|
@@ -1,12 +1,9 @@
|
|
|
from __future__ import annotations
|
|
|
|
|
|
-from typing import Callable, List, Mapping, MutableMapping, Optional, Tuple
|
|
|
+from typing import List, Mapping, MutableMapping, Optional, Tuple
|
|
|
|
|
|
from django.db import router, transaction
|
|
|
-from django.db.models import QuerySet
|
|
|
|
|
|
-from sentry.api.serializers.base import Serializer
|
|
|
-from sentry.api.serializers.models.notification_setting import NotificationSettingsSerializer
|
|
|
from sentry.models.notificationsetting import NotificationSetting
|
|
|
from sentry.models.notificationsettingoption import NotificationSettingOption
|
|
|
from sentry.models.notificationsettingprovider import NotificationSettingProvider
|
|
@@ -19,15 +16,7 @@ from sentry.notifications.types import (
|
|
|
NotificationSettingsOptionEnum,
|
|
|
)
|
|
|
from sentry.services.hybrid_cloud.actor import ActorType, RpcActor
|
|
|
-from sentry.services.hybrid_cloud.auth.model import AuthenticationContext
|
|
|
-from sentry.services.hybrid_cloud.filter_query import (
|
|
|
- FilterQueryDatabaseImpl,
|
|
|
- OpaqueSerializedResponse,
|
|
|
-)
|
|
|
-from sentry.services.hybrid_cloud.notifications import NotificationsService, RpcNotificationSetting
|
|
|
-from sentry.services.hybrid_cloud.notifications.model import NotificationSettingFilterArgs
|
|
|
-from sentry.services.hybrid_cloud.notifications.serial import serialize_notification_setting
|
|
|
-from sentry.services.hybrid_cloud.user import RpcUser
|
|
|
+from sentry.services.hybrid_cloud.notifications import NotificationsService
|
|
|
from sentry.services.hybrid_cloud.user.service import user_service
|
|
|
from sentry.types.integrations import ExternalProviderEnum, ExternalProviders
|
|
|
|
|
@@ -117,9 +106,6 @@ class DatabaseBackedNotificationsService(NotificationsService):
|
|
|
) -> None:
|
|
|
self.remove_notification_settings(team_id=team_id, user_id=None, provider=provider)
|
|
|
|
|
|
- def get_many(self, *, filter: NotificationSettingFilterArgs) -> List[RpcNotificationSetting]:
|
|
|
- return self._FQ.get_many(filter)
|
|
|
-
|
|
|
def remove_notification_settings_for_organization(self, *, organization_id: int) -> None:
|
|
|
assert organization_id, "organization_id must be a positive integer"
|
|
|
NotificationSetting.objects.remove_for_organization(organization_id=organization_id)
|
|
@@ -143,15 +129,6 @@ class DatabaseBackedNotificationsService(NotificationsService):
|
|
|
scope_identifier=project_id,
|
|
|
).delete()
|
|
|
|
|
|
- def serialize_many(
|
|
|
- self,
|
|
|
- *,
|
|
|
- filter: NotificationSettingFilterArgs,
|
|
|
- as_user: Optional[RpcUser] = None,
|
|
|
- auth_context: Optional[AuthenticationContext] = None,
|
|
|
- ) -> List[OpaqueSerializedResponse]:
|
|
|
- return self._FQ.serialize_many(filter, as_user, auth_context)
|
|
|
-
|
|
|
def get_subscriptions_for_projects(
|
|
|
self,
|
|
|
*,
|
|
@@ -173,6 +150,7 @@ class DatabaseBackedNotificationsService(NotificationsService):
|
|
|
)
|
|
|
return {
|
|
|
project: (s.is_disabled, s.is_active, s.has_only_inactive_subscriptions)
|
|
|
+ # TODO(Steve): Simplify API to pass in one project at a time
|
|
|
for project, s in controller.get_subscriptions_status_for_projects(
|
|
|
user=user, project_ids=project_ids, type=type
|
|
|
).items()
|
|
@@ -228,41 +206,3 @@ class DatabaseBackedNotificationsService(NotificationsService):
|
|
|
)
|
|
|
raw_output = controller.get_notification_recipients(type=type, actor_type=actor_type)
|
|
|
return {str(provider.name): actors for provider, actors in raw_output.items()}
|
|
|
-
|
|
|
- class _NotificationSettingsQuery(
|
|
|
- FilterQueryDatabaseImpl[
|
|
|
- NotificationSetting, NotificationSettingFilterArgs, RpcNotificationSetting, None
|
|
|
- ],
|
|
|
- ):
|
|
|
- def apply_filters(
|
|
|
- self, query: QuerySet[NotificationSetting], filters: NotificationSettingFilterArgs
|
|
|
- ) -> QuerySet[NotificationSetting]:
|
|
|
- if "provider" in filters and filters["provider"] is not None:
|
|
|
- query = query.filter(provider=filters["provider"])
|
|
|
- if "type" in filters and filters["type"] is not None:
|
|
|
- query = query.filter(type=filters["type"].value)
|
|
|
- if "scope_type" in filters and filters["scope_type"] is not None:
|
|
|
- query = query.filter(scope_type=filters["scope_type"])
|
|
|
- if "scope_identifier" in filters and filters["scope_identifier"] is not None:
|
|
|
- query = query.filter(scope_identifier=filters["scope_identifier"])
|
|
|
- if "user_ids" in filters and len(filters["user_ids"]) > 0:
|
|
|
- query = query.filter(user_id__in=filters["user_ids"])
|
|
|
- if "team_ids" in filters and len(filters["team_ids"]) > 0:
|
|
|
- query = query.filter(team_id__in=filters["team_ids"])
|
|
|
- return query.all()
|
|
|
-
|
|
|
- def base_query(self, ids_only: bool = False) -> QuerySet[NotificationSetting]:
|
|
|
- return NotificationSetting.objects
|
|
|
-
|
|
|
- def filter_arg_validator(self) -> Callable[[NotificationSettingFilterArgs], Optional[str]]:
|
|
|
- return self._filter_has_any_key_validator("user_ids", "team_ids")
|
|
|
-
|
|
|
- def serialize_api(self, serializer_type: Optional[None]) -> Serializer:
|
|
|
- return NotificationSettingsSerializer()
|
|
|
-
|
|
|
- def serialize_rpc(
|
|
|
- self, notification_setting: NotificationSetting
|
|
|
- ) -> RpcNotificationSetting:
|
|
|
- return serialize_notification_setting(notification_setting)
|
|
|
-
|
|
|
- _FQ = _NotificationSettingsQuery()
|