Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "Revert slack org does not exist changes breaking escalate command (#2057)" #2096

Merged
merged 6 commits into from
Jun 6, 2023

Conversation

joeyorlando
Copy link
Contributor

@joeyorlando joeyorlando commented Jun 5, 2023

What this PR does

Closes https://github.com/grafana/oncall-private/issues/1836

Checklist

  • Unit, integration, and e2e (if applicable) tests updated
  • Documentation added (or pr:no public docs PR label added if not required)
  • CHANGELOG.md updated (or pr:no changelog PR label added if not required)

@joeyorlando joeyorlando marked this pull request as ready for review June 6, 2023 09:45
@joeyorlando joeyorlando requested a review from a team June 6, 2023 09:45
@joeyorlando joeyorlando added the pr:no public docs Added to a PR that does not require public documentation updates label Jun 6, 2023
…afana/oncall into jorlando/revert-orgnotfound-slack-fix
@@ -285,55 +301,73 @@ def post(self, request):
# Open pop-up to inform user why OnCall bot doesn't work if any action was triggered
self._open_warning_window_if_needed(payload, slack_team_identity, warning_text)
return Response(status=200)
elif organization is None and payload_type_is_block_actions:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and payload_type_is_block_actions is the main change of this PR.

From what I can see from the logs,Organization matching query does not exist. exceptions originating from this endpoint only seem to be happening when payload_type == 'block_actions'

Comment on lines +165 to +185
payload_type = payload.get("type")
payload_type_is_block_actions = payload_type == PAYLOAD_TYPE_BLOCK_ACTIONS
payload_command = payload.get("command")
payload_callback_id = payload.get("callback_id")
payload_actions = payload.get("actions", [])
payload_user = payload.get("user")
payload_user_id = payload.get("user_id")

payload_event = payload.get("event", {})
payload_event_type = payload_event.get("type")
payload_event_subtype = payload_event.get("subtype")
payload_event_user = payload_event.get("user")
payload_event_bot_id = payload_event.get("bot_id")
payload_event_channel_type = payload_event.get("channel_type")

payload_event_message = payload_event.get("message", {})
payload_event_message_user = payload_event_message.get("user")

payload_event_previous_message = payload_event.get("previous_message", {})
payload_event_previous_message_user = payload_event_previous_message.get("user")

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

decided to clean this up a bit, much less repetitive imo

Comment on lines +101 to +134
@patch("apps.slack.views.SlackEventApiEndpointView.verify_signature", return_value=True)
@patch("apps.slack.views.SlackEventApiEndpointView._open_warning_window_if_needed")
@pytest.mark.django_db
def test_organization_not_found_scenario_doesnt_break_slash_commands(
mock_open_warning_window_if_needed,
_mock_verify_signature,
make_organization,
make_slack_user_identity,
slack_team_identity,
):

make_organization(slack_team_identity=slack_team_identity)
make_slack_user_identity(slack_team_identity=slack_team_identity, slack_id=SLACK_USER_ID)

response = _make_request(
{
"token": "axvnc,mvc,mv,mcvmnxcmnxc",
"team_id": SLACK_TEAM_ID,
"team_domain": "testingtest-nim4013",
"channel_id": "C043HQ70QMB",
"channel_name": "testy-testing",
"user_id": "U043HQ3VABF",
"user_name": "bob.smith",
"command": settings.SLACK_DIRECT_PAGING_SLASH_COMMAND,
"text": "potato",
"api_app_id": "A0909234092340293402934234234234234234",
"is_enterprise_install": "false",
"response_url": "https://hooks.slack.com/commands/cvcv/cvcv/cvcv",
"trigger_id": "asdfasdf.4122782784722.cvcv",
}
)

assert response.status_code == status.HTTP_200_OK
mock_open_warning_window_if_needed.assert_not_called()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

previously this PR broke the /escalate command, added a test to ensure this is no longer the case. The request payload structure being sent here is identical to that when the /escalate command is used.

Comment on lines +462 to +469
payload_view = payload.get("view", {})
payload_view_state = payload_view.get("state", {})
payload_view_state_values = payload_view_state.get("values", {})

payload_event = payload.get("event", {})
payload_event_channel = payload_event.get("channel")
payload_event_message = payload_event.get("message", {})
payload_event_thread_ts = payload_event.get("thread_ts")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here. wanted to clean this up

Copy link
Contributor

@matiasb matiasb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@joeyorlando joeyorlando added this pull request to the merge queue Jun 6, 2023
Merged via the queue into dev with commit cf949ac Jun 6, 2023
@joeyorlando joeyorlando deleted the jorlando/revert-orgnotfound-slack-fix branch June 6, 2023 12:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr:no public docs Added to a PR that does not require public documentation updates
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants