Skip to content

Commit 4e21dcb

Browse files
author
Stephen Cefali
authored
ref(notifications): remove some unused hybrid cloud service methods (#60488)
This removes `get_settings_for_recipient_by_parent`, `get_settings_for_users`, and `get_settings_for_user_by_projects` which are not used anymore
1 parent f29a346 commit 4e21dcb

File tree

3 files changed

+3
-141
lines changed

3 files changed

+3
-141
lines changed

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

Lines changed: 2 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,19 @@
11
from __future__ import annotations
22

3-
from typing import Callable, List, Mapping, MutableMapping, Optional, Sequence, Tuple
3+
from typing import Callable, List, Mapping, MutableMapping, Optional, Tuple
44

55
from django.db import router, transaction
6-
from django.db.models import Q, QuerySet
6+
from django.db.models import QuerySet
77

88
from sentry.api.serializers.base import Serializer
99
from sentry.api.serializers.models.notification_setting import NotificationSettingsSerializer
1010
from sentry.models.notificationsetting import NotificationSetting
1111
from sentry.models.notificationsettingoption import NotificationSettingOption
1212
from sentry.models.notificationsettingprovider import NotificationSettingProvider
1313
from sentry.models.user import User
14-
from sentry.notifications.helpers import get_scope_type
1514
from sentry.notifications.notificationcontroller import NotificationController
1615
from sentry.notifications.types import (
1716
NotificationScopeEnum,
18-
NotificationScopeType,
1917
NotificationSettingEnum,
2018
NotificationSettingOptionValues,
2119
NotificationSettingsOptionEnum,
@@ -112,73 +110,6 @@ def update_notification_options(
112110
**kwargs,
113111
)
114112

115-
# TODO(snigdha): This can be removed in V2.
116-
def get_settings_for_users(
117-
self,
118-
*,
119-
types: List[NotificationSettingTypes],
120-
users: List[RpcUser],
121-
value: NotificationSettingOptionValues,
122-
) -> List[RpcNotificationSetting]:
123-
settings = NotificationSetting.objects.filter(
124-
user_id__in=[u.id for u in users],
125-
type__in=types,
126-
value=value.value,
127-
scope_type=NotificationScopeType.USER.value,
128-
)
129-
return [serialize_notification_setting(u) for u in settings]
130-
131-
def get_settings_for_recipient_by_parent(
132-
self, *, type: NotificationSettingTypes, parent_id: int, recipients: Sequence[RpcActor]
133-
) -> List[RpcNotificationSetting]:
134-
team_ids = [r.id for r in recipients if r.actor_type == ActorType.TEAM]
135-
user_ids = [r.id for r in recipients if r.actor_type == ActorType.USER]
136-
137-
parent_specific_scope_type = get_scope_type(type)
138-
notification_settings = NotificationSetting.objects.filter(
139-
Q(
140-
scope_type=parent_specific_scope_type.value,
141-
scope_identifier=parent_id,
142-
)
143-
| Q(
144-
scope_type=NotificationScopeType.USER.value,
145-
scope_identifier__in=user_ids,
146-
)
147-
| Q(
148-
scope_type=NotificationScopeType.TEAM.value,
149-
scope_identifier__in=team_ids,
150-
),
151-
(Q(team_id__in=team_ids) | Q(user_id__in=user_ids)),
152-
type=type.value,
153-
)
154-
155-
return [serialize_notification_setting(s) for s in notification_settings]
156-
157-
def get_settings_for_user_by_projects(
158-
self, *, type: NotificationSettingTypes, user_id: int, parent_ids: List[int]
159-
) -> List[RpcNotificationSetting]:
160-
try:
161-
User.objects.get(id=user_id)
162-
except User.DoesNotExist:
163-
return []
164-
165-
scope_type = get_scope_type(type)
166-
return [
167-
serialize_notification_setting(s)
168-
for s in NotificationSetting.objects.filter(
169-
Q(
170-
scope_type=scope_type.value,
171-
scope_identifier__in=parent_ids,
172-
)
173-
| Q(
174-
scope_type=NotificationScopeType.USER.value,
175-
scope_identifier=user_id,
176-
),
177-
type=type.value,
178-
user_id=user_id,
179-
)
180-
]
181-
182113
def remove_notification_settings(
183114
self, *, team_id: Optional[int], user_id: Optional[int], provider: ExternalProviders
184115
) -> None:

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

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# in modules such as this one where hybrid cloud data models or service classes are
44
# defined, because we want to reflect on type annotations and avoid forward references.
55
from abc import abstractmethod
6-
from typing import List, Mapping, MutableMapping, Optional, Sequence, Set, Tuple
6+
from typing import List, Mapping, MutableMapping, Optional, Set, Tuple
77

88
from sentry.notifications.types import (
99
NotificationScopeEnum,
@@ -35,35 +35,6 @@ def get_local_implementation(cls) -> RpcService:
3535

3636
return DatabaseBackedNotificationsService()
3737

38-
@rpc_method
39-
@abstractmethod
40-
def get_settings_for_recipient_by_parent(
41-
self,
42-
*,
43-
type: NotificationSettingTypes,
44-
parent_id: int,
45-
recipients: Sequence[RpcActor],
46-
) -> List[RpcNotificationSetting]:
47-
pass
48-
49-
@rpc_method
50-
@abstractmethod
51-
def get_settings_for_users(
52-
self,
53-
*,
54-
types: List[NotificationSettingTypes],
55-
users: List[RpcUser],
56-
value: NotificationSettingOptionValues,
57-
) -> List[RpcNotificationSetting]:
58-
pass
59-
60-
@rpc_method
61-
@abstractmethod
62-
def get_settings_for_user_by_projects(
63-
self, *, type: NotificationSettingTypes, user_id: int, parent_ids: List[int]
64-
) -> List[RpcNotificationSetting]:
65-
pass
66-
6738
@rpc_method
6839
@abstractmethod
6940
def update_settings(

tests/sentry/api/endpoints/test_rpc.py

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,9 @@
66
from django.urls import reverse
77
from rest_framework.exceptions import ErrorDetail
88

9-
from sentry.models.notificationsetting import NotificationSetting
10-
from sentry.notifications.types import (
11-
NotificationScopeType,
12-
NotificationSettingOptionValues,
13-
NotificationSettingTypes,
14-
)
159
from sentry.services.hybrid_cloud.organization import RpcUserOrganizationContext
1610
from sentry.services.hybrid_cloud.rpc import generate_request_signature
1711
from sentry.testutils.cases import APITestCase
18-
from sentry.types.integrations import ExternalProviders
1912
from sentry.utils import json
2013

2114

@@ -137,36 +130,3 @@ def test_with_invalid_arguments(self):
137130
assert response.data == {
138131
"detail": ErrorDetail(string="Malformed request.", code="parse_error")
139132
}
140-
141-
def test_with_enum_serialization(self):
142-
path = self._get_path("notifications", "get_settings_for_user_by_projects")
143-
NotificationSetting.objects.update_settings(
144-
ExternalProviders.EMAIL,
145-
NotificationSettingTypes.ISSUE_ALERTS,
146-
NotificationSettingOptionValues.ALWAYS,
147-
user_id=self.user.id,
148-
)
149-
data = {
150-
"args": {
151-
"type": 20,
152-
"user_id": self.user.id,
153-
"parent_ids": [self.project.id],
154-
}
155-
}
156-
response = self._send_post_request(path, data)
157-
assert response.status_code == 200
158-
response_body = response.json()
159-
setting = NotificationSetting.objects.filter(user_id=self.user.id).get()
160-
assert response_body["value"] == [
161-
{
162-
"id": setting.id,
163-
"scope_type": NotificationScopeType.USER.value,
164-
"scope_identifier": self.user.id,
165-
"target_id": response_body["value"][0]["target_id"],
166-
"team_id": None,
167-
"user_id": self.user.id,
168-
"provider": ExternalProviders.EMAIL.value,
169-
"type": NotificationSettingTypes.ISSUE_ALERTS.value,
170-
"value": 20,
171-
}
172-
]

0 commit comments

Comments
 (0)