Skip to content

Commit 68a1f39

Browse files
author
Stephen Cefali
authored
feat(notifications): remove logic to remove notificationsetting rows when the user uninstalls slack (#60535)
This PR removes logic to change notification settings when a user uninstalls Slack. This is unnecessary, if the user doesn't have Slack installed we don't need to worry about clearing out settings as we won't show Slack as a possible option in the notification settings UI and it won't notify them.
1 parent 1cf401a commit 68a1f39

File tree

5 files changed

+2
-211
lines changed

5 files changed

+2
-211
lines changed

src/sentry/integrations/slack/integration.py

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,7 @@
1616
)
1717
from sentry.models.integrations.integration import Integration
1818
from sentry.pipeline import NestedPipelineView
19-
from sentry.services.hybrid_cloud.notifications import notifications_service
20-
from sentry.services.hybrid_cloud.organization import (
21-
RpcOrganizationSummary,
22-
RpcUserOrganizationContext,
23-
organization_service,
24-
)
19+
from sentry.services.hybrid_cloud.organization import RpcOrganizationSummary
2520
from sentry.shared_integrations.exceptions import ApiError, IntegrationError
2621
from sentry.tasks.integrations.slack import link_slack_user_identities
2722
from sentry.utils.http import absolute_uri
@@ -87,21 +82,6 @@ def get_config_data(self) -> Mapping[str, str]:
8782
)
8883
return {"installationType": metadata_.get("installation_type", default_installation)}
8984

90-
def uninstall(self) -> None:
91-
"""
92-
Delete all parent-specific notification settings. For each user and team,
93-
if this is their ONLY Slack integration, set their parent-independent
94-
Slack notification setting to NEVER.
95-
"""
96-
org_context: RpcUserOrganizationContext | None = (
97-
organization_service.get_organization_by_id(id=self.organization_id, user_id=None)
98-
)
99-
if org_context:
100-
notifications_service.uninstall_slack_settings(
101-
organization_id=self.organization_id,
102-
project_ids=[p.id for p in org_context.organization.projects],
103-
)
104-
10585

10686
class SlackIntegrationProvider(IntegrationProvider):
10787
key = "slack"

src/sentry/notifications/manager.py

Lines changed: 1 addition & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import logging
44
from collections import defaultdict
5-
from typing import TYPE_CHECKING, Iterable, List, Mapping, MutableSet, Optional, Set, Union
5+
from typing import TYPE_CHECKING, Iterable, Mapping, MutableSet, Optional, Set, Union
66

77
from django.db import router, transaction
88
from django.db.models import Q, QuerySet
@@ -20,7 +20,6 @@
2020
NOTIFICATION_SCOPE_TYPE,
2121
NOTIFICATION_SETTING_OPTION_VALUES,
2222
NOTIFICATION_SETTING_TYPES,
23-
VALID_VALUES_FOR_KEY,
2423
VALID_VALUES_FOR_KEY_V2,
2524
NotificationScopeEnum,
2625
NotificationScopeType,
@@ -485,39 +484,3 @@ def update_provider_settings(self, user_id: int | None, team_id: int | None):
485484
**base_query,
486485
type__in=[NOTIFICATION_SETTING_TYPES[type] for type in types_to_delete],
487486
).delete()
488-
489-
def remove_parent_settings_for_organization(
490-
self, organization_id: int, project_ids: List[int], provider: ExternalProviders
491-
) -> None:
492-
"""Delete all parent-specific notification settings referencing this organization."""
493-
kwargs = {}
494-
kwargs["provider"] = provider.value
495-
496-
self.filter(
497-
Q(scope_type=NotificationScopeType.PROJECT.value, scope_identifier__in=project_ids)
498-
| Q(
499-
scope_type=NotificationScopeType.ORGANIZATION.value,
500-
scope_identifier=organization_id,
501-
),
502-
**kwargs,
503-
).delete()
504-
505-
def disable_settings_for_users(
506-
self, provider: ExternalProviders, users: Iterable[User]
507-
) -> None:
508-
"""
509-
Given a list of users, overwrite all of their parent-independent
510-
notification settings to NEVER.
511-
TODO(mgaeta): Django 3 has self.bulk_create() which would allow us to do
512-
this in a single query.
513-
"""
514-
for user in users:
515-
for type in VALID_VALUES_FOR_KEY.keys():
516-
self.update_or_create(
517-
provider=provider.value,
518-
type=type.value,
519-
scope_type=NotificationScopeType.USER.value,
520-
scope_identifier=user.id,
521-
user_id=user.id,
522-
defaults={"value": NotificationSettingOptionValues.NEVER.value},
523-
)

src/sentry/services/hybrid_cloud/notifications/impl.py

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,6 @@
3535

3636

3737
class DatabaseBackedNotificationsService(NotificationsService):
38-
def uninstall_slack_settings(self, organization_id: int, project_ids: List[int]) -> None:
39-
provider = ExternalProviders.SLACK
40-
users = User.objects.get_users_with_only_one_integration_for_provider(
41-
provider, organization_id
42-
)
43-
44-
NotificationSetting.objects.remove_parent_settings_for_organization(
45-
organization_id, project_ids, provider
46-
)
47-
NotificationSetting.objects.disable_settings_for_users(provider, users)
48-
4938
def update_settings(
5039
self,
5140
*,

src/sentry/services/hybrid_cloud/notifications/service.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,6 @@ def update_notification_options(
7474
) -> None:
7575
pass
7676

77-
@rpc_method
78-
@abstractmethod
79-
def uninstall_slack_settings(
80-
self,
81-
organization_id: int,
82-
project_ids: List[int],
83-
) -> None:
84-
pass
85-
8677
@rpc_method
8778
@abstractmethod
8879
def remove_notification_settings_for_team(

tests/sentry/integrations/slack/test_uninstall.py

Lines changed: 0 additions & 132 deletions
This file was deleted.

0 commit comments

Comments
 (0)