|
45 | 45 | IntegrationProviderSlug, |
46 | 46 | IntegrationResponse, |
47 | 47 | ) |
| 48 | +from sentry.integrations.utils.webhook_viewer_context import webhook_viewer_context |
48 | 49 | from sentry.models.activity import ActivityIntegration |
49 | 50 | from sentry.models.apikey import ApiKey |
50 | 51 | from sentry.models.group import Group |
@@ -434,18 +435,19 @@ def _handle_team_member_removed(self, request: Request) -> Response: |
434 | 435 | ) |
435 | 436 | if len(org_integrations) > 0: |
436 | 437 | for org_integration in org_integrations: |
437 | | - create_audit_entry( |
438 | | - request=request, |
439 | | - organization_id=org_integration.organization_id, |
440 | | - target_object=integration.id, |
441 | | - event=audit_log.get_event_id("INTEGRATION_REMOVE"), |
442 | | - actor_label="Teams User", |
443 | | - data={ |
444 | | - "provider": integration.provider, |
445 | | - "name": integration.name, |
446 | | - "team_id": team_id, |
447 | | - }, |
448 | | - ) |
| 438 | + with webhook_viewer_context(org_integration.organization_id): |
| 439 | + create_audit_entry( |
| 440 | + request=request, |
| 441 | + organization_id=org_integration.organization_id, |
| 442 | + target_object=integration.id, |
| 443 | + event=audit_log.get_event_id("INTEGRATION_REMOVE"), |
| 444 | + actor_label="Teams User", |
| 445 | + data={ |
| 446 | + "provider": integration.provider, |
| 447 | + "name": integration.name, |
| 448 | + "team_id": team_id, |
| 449 | + }, |
| 450 | + ) |
449 | 451 |
|
450 | 452 | integration_service.delete_integration(integration_id=integration.id) |
451 | 453 | return self.respond(status=204) |
@@ -584,60 +586,61 @@ def _handle_action_submitted(self, request: Request) -> Response: |
584 | 586 | ) |
585 | 587 | return self.respond(status=404) |
586 | 588 |
|
587 | | - idp = identity_service.get_provider( |
588 | | - provider_type=IntegrationProviderSlug.MSTEAMS.value, provider_ext_id=team_id |
589 | | - ) |
590 | | - if idp is None: |
591 | | - logger.info( |
592 | | - "msteams.action.invalid-team-id", |
593 | | - extra={ |
594 | | - "team_id": team_id, |
595 | | - "integration_id": integration.id, |
596 | | - "organization_id": group.organization.id, |
597 | | - }, |
| 589 | + with webhook_viewer_context(group.organization.id): |
| 590 | + idp = identity_service.get_provider( |
| 591 | + provider_type=IntegrationProviderSlug.MSTEAMS.value, provider_ext_id=team_id |
598 | 592 | ) |
599 | | - return self.respond(status=404) |
| 593 | + if idp is None: |
| 594 | + logger.info( |
| 595 | + "msteams.action.invalid-team-id", |
| 596 | + extra={ |
| 597 | + "team_id": team_id, |
| 598 | + "integration_id": integration.id, |
| 599 | + "organization_id": group.organization.id, |
| 600 | + }, |
| 601 | + ) |
| 602 | + return self.respond(status=404) |
600 | 603 |
|
601 | | - identity = identity_service.get_identity( |
602 | | - filter={"provider_id": idp.id, "identity_ext_id": user_id} |
603 | | - ) |
604 | | - if identity is None: |
605 | | - associate_url = build_linking_url( |
606 | | - integration, group.organization, user_id, team_id, tenant_id |
| 604 | + identity = identity_service.get_identity( |
| 605 | + filter={"provider_id": idp.id, "identity_ext_id": user_id} |
607 | 606 | ) |
| 607 | + if identity is None: |
| 608 | + associate_url = build_linking_url( |
| 609 | + integration, group.organization, user_id, team_id, tenant_id |
| 610 | + ) |
608 | 611 |
|
609 | | - card = build_linking_card(associate_url) |
610 | | - user_conversation_id = client.get_user_conversation_id(user_id, tenant_id) |
611 | | - client.send_card(user_conversation_id, card) |
612 | | - return self.respond(status=201) |
| 612 | + card = build_linking_card(associate_url) |
| 613 | + user_conversation_id = client.get_user_conversation_id(user_id, tenant_id) |
| 614 | + client.send_card(user_conversation_id, card) |
| 615 | + return self.respond(status=201) |
613 | 616 |
|
614 | | - # update the state of the issue |
615 | | - issue_change_response = self._issue_state_change(group, identity, data["value"]) |
| 617 | + # update the state of the issue |
| 618 | + issue_change_response = self._issue_state_change(group, identity, data["value"]) |
616 | 619 |
|
617 | | - # get the rules from the payload |
618 | | - rules = tuple(Rule.objects.filter(id__in=payload["rules"])) |
| 620 | + # get the rules from the payload |
| 621 | + rules = tuple(Rule.objects.filter(id__in=payload["rules"])) |
619 | 622 |
|
620 | | - # pull the event based off our payload |
621 | | - event = eventstore.backend.get_event_by_id(group.project_id, payload["eventId"]) |
622 | | - if event is None: |
623 | | - logger.info( |
624 | | - "msteams.action.event-missing", |
625 | | - extra={ |
626 | | - "team_id": team_id, |
627 | | - "integration_id": integration.id, |
628 | | - "organization_id": group.organization.id, |
629 | | - "event_id": payload["eventId"], |
630 | | - "project_id": group.project_id, |
631 | | - }, |
632 | | - ) |
633 | | - return self.respond(status=404) |
| 623 | + # pull the event based off our payload |
| 624 | + event = eventstore.backend.get_event_by_id(group.project_id, payload["eventId"]) |
| 625 | + if event is None: |
| 626 | + logger.info( |
| 627 | + "msteams.action.event-missing", |
| 628 | + extra={ |
| 629 | + "team_id": team_id, |
| 630 | + "integration_id": integration.id, |
| 631 | + "organization_id": group.organization.id, |
| 632 | + "event_id": payload["eventId"], |
| 633 | + "project_id": group.project_id, |
| 634 | + }, |
| 635 | + ) |
| 636 | + return self.respond(status=404) |
634 | 637 |
|
635 | | - # refresh issue and update card |
636 | | - group.refresh_from_db() |
637 | | - card = MSTeamsIssueMessageBuilder(group, event, rules, integration).build_group_card() |
638 | | - client.update_card(conversation_id, activity_id, card) |
| 638 | + # refresh issue and update card |
| 639 | + group.refresh_from_db() |
| 640 | + card = MSTeamsIssueMessageBuilder(group, event, rules, integration).build_group_card() |
| 641 | + client.update_card(conversation_id, activity_id, card) |
639 | 642 |
|
640 | | - return issue_change_response |
| 643 | + return issue_change_response |
641 | 644 |
|
642 | 645 | def _handle_channel_message(self, request: Request) -> Response: |
643 | 646 | data = request.data |
|
0 commit comments