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

chore(notifications): move over notificationsettingoption #80836

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from sentry.api.exceptions import ParameterValidationError
from sentry.api.serializers import serialize
from sentry.api.validators.notifications import validate_type
from sentry.models.notificationsettingoption import NotificationSettingOption
from sentry.notifications.models.notificationsettingoption import NotificationSettingOption
from sentry.notifications.serializers import NotificationSettingsOptionSerializer
from sentry.notifications.validators import UserNotificationSettingOptionWithValueSerializer
from sentry.users.api.bases.user import UserEndpoint
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from sentry.api.api_owners import ApiOwner
from sentry.api.api_publish_status import ApiPublishStatus
from sentry.api.base import control_silo_endpoint
from sentry.models.notificationsettingoption import NotificationSettingOption
from sentry.notifications.models.notificationsettingoption import NotificationSettingOption
from sentry.users.api.bases.user import UserEndpoint
from sentry.users.models.user import User

Expand Down
1 change: 1 addition & 0 deletions src/sentry/conf/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,7 @@ def env(
"sentry.users",
"sentry.sentry_apps",
"sentry.integrations",
"sentry.notifications",
"sentry.flags",
"sentry.monitors",
"sentry.uptime",
Expand Down
1 change: 0 additions & 1 deletion src/sentry/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@
from .importchunk import * # NOQA
from .latestreporeleaseenvironment import * # NOQA
from .notificationmessage import * # NOQA
from .notificationsettingoption import * # NOQA
from .notificationsettingprovider import * # NOQA
from .options import * # NOQA
from .organization import * # NOQA
Expand Down
41 changes: 2 additions & 39 deletions src/sentry/models/notificationsettingoption.py
Original file line number Diff line number Diff line change
@@ -1,40 +1,3 @@
from django.db import models
from sentry.notifications.models.notificationsettingoption import NotificationSettingOption

from sentry.backup.scopes import RelocationScope
from sentry.db.models import control_silo_model, sane_repr

from .notificationsettingbase import NotificationSettingBase


@control_silo_model
class NotificationSettingOption(NotificationSettingBase):
__relocation_scope__ = RelocationScope.Excluded

class Meta:
app_label = "sentry"
db_table = "sentry_notificationsettingoption"
unique_together = (
(
"scope_type",
"scope_identifier",
"user_id",
"team_id",
"type",
),
)
constraints = [
models.CheckConstraint(
condition=models.Q(team_id__isnull=False, user_id__isnull=True)
| models.Q(team_id__isnull=True, user_id__isnull=False),
name="notification_setting_option_team_or_user_check",
)
]

__repr__ = sane_repr(
"scope_type",
"scope_identifier",
"type",
"user_id",
"team_id",
"value",
)
__all__ = ("NotificationSettingOption",)
3 changes: 3 additions & 0 deletions src/sentry/notifications/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from sentry.notifications.models.notificationsettingoption import NotificationSettingOption

__all__ = ("NotificationSettingOption",)
39 changes: 39 additions & 0 deletions src/sentry/notifications/models/notificationsettingoption.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
from django.db import models
Copy link
Member

Choose a reason for hiding this comment

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

Should we also have a sentry/models/notifications/models/__init__.py that imports all the models from notifications app? We may need the barrel file to appease django's app startup.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oof I forgot. I'm rusty 🫠 I also need to add to INSTALLED_APPS


from sentry.backup.scopes import RelocationScope
from sentry.db.models import control_silo_model, sane_repr
from sentry.models.notificationsettingbase import NotificationSettingBase


@control_silo_model
class NotificationSettingOption(NotificationSettingBase):
__relocation_scope__ = RelocationScope.Excluded

class Meta:
app_label = "sentry"
db_table = "sentry_notificationsettingoption"
unique_together = (
(
"scope_type",
"scope_identifier",
"user_id",
"team_id",
"type",
),
)
constraints = [
models.CheckConstraint(
condition=models.Q(team_id__isnull=False, user_id__isnull=True)
| models.Q(team_id__isnull=True, user_id__isnull=False),
name="notification_setting_option_team_or_user_check",
)
]

__repr__ = sane_repr(
"scope_type",
"scope_identifier",
"type",
"user_id",
"team_id",
"value",
)
2 changes: 1 addition & 1 deletion src/sentry/notifications/notificationcontroller.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
ExternalProviderEnum,
ExternalProviders,
)
from sentry.models.notificationsettingoption import NotificationSettingOption
from sentry.models.notificationsettingprovider import NotificationSettingProvider
from sentry.models.organizationmapping import OrganizationMapping
from sentry.models.team import Team
Expand All @@ -26,6 +25,7 @@
recipient_is_user,
team_is_valid_recipient,
)
from sentry.notifications.models.notificationsettingoption import NotificationSettingOption
from sentry.notifications.types import (
GroupSubscriptionStatus,
NotificationScopeEnum,
Expand Down
2 changes: 1 addition & 1 deletion src/sentry/notifications/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
from typing import Any

from sentry.api.serializers import Serializer
from sentry.models.notificationsettingoption import NotificationSettingOption
from sentry.models.notificationsettingprovider import NotificationSettingProvider
from sentry.notifications.models.notificationsettingoption import NotificationSettingOption


class NotificationSettingsBaseSerializer(Serializer):
Expand Down
2 changes: 1 addition & 1 deletion src/sentry/notifications/services/impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
from django.db import router, transaction

from sentry.integrations.types import EXTERNAL_PROVIDERS, ExternalProviderEnum, ExternalProviders
from sentry.models.notificationsettingoption import NotificationSettingOption
from sentry.models.notificationsettingprovider import NotificationSettingProvider
from sentry.notifications.models.notificationsettingoption import NotificationSettingOption
from sentry.notifications.notificationcontroller import NotificationController
from sentry.notifications.services import NotificationsService
from sentry.notifications.services.model import RpcSubscriptionStatus
Expand Down
2 changes: 1 addition & 1 deletion src/sentry/testutils/cases.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@
from sentry.models.environment import Environment
from sentry.models.files.file import File
from sentry.models.groupmeta import GroupMeta
from sentry.models.notificationsettingoption import NotificationSettingOption
from sentry.models.notificationsettingprovider import NotificationSettingProvider
from sentry.models.options.project_option import ProjectOption
from sentry.models.organization import Organization
Expand All @@ -110,6 +109,7 @@
from sentry.models.repository import Repository
from sentry.models.rule import RuleSource
from sentry.monitors.models import Monitor, MonitorEnvironment, MonitorType, ScheduleType
from sentry.notifications.models.notificationsettingoption import NotificationSettingOption
from sentry.notifications.notifications.base import alert_page_needs_org_id
from sentry.notifications.types import FineTuningAPIKey
from sentry.organizations.services.organization.serial import serialize_rpc_organization
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from django.urls import reverse

from sentry.models.groupsubscription import GroupSubscription
from sentry.models.notificationsettingoption import NotificationSettingOption
from sentry.notifications.models.notificationsettingoption import NotificationSettingOption
from sentry.silo.base import SiloMode
from sentry.testutils.cases import APITestCase
from sentry.testutils.silo import assume_test_silo_mode
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from rest_framework import status

from sentry.models.notificationsettingoption import NotificationSettingOption
from sentry.notifications.models.notificationsettingoption import NotificationSettingOption
from sentry.notifications.types import (
NotificationScopeEnum,
NotificationSettingEnum,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from rest_framework import status

from sentry.models.notificationsettingoption import NotificationSettingOption
from sentry.notifications.models.notificationsettingoption import NotificationSettingOption
from sentry.notifications.types import (
NotificationScopeEnum,
NotificationSettingEnum,
Expand Down
2 changes: 1 addition & 1 deletion tests/sentry/api/serializers/test_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
from sentry.models.groupresolution import GroupResolution
from sentry.models.groupsnooze import GroupSnooze
from sentry.models.groupsubscription import GroupSubscription
from sentry.models.notificationsettingoption import NotificationSettingOption
from sentry.models.notificationsettingprovider import NotificationSettingProvider
from sentry.notifications.models.notificationsettingoption import NotificationSettingOption
from sentry.notifications.types import (
NotificationScopeEnum,
NotificationSettingEnum,
Expand Down
2 changes: 1 addition & 1 deletion tests/sentry/db/models/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
RegionImportChunk,
)
from sentry.models.notificationsettingbase import NotificationSettingBase
from sentry.models.notificationsettingoption import NotificationSettingOption
from sentry.models.notificationsettingprovider import NotificationSettingProvider
from sentry.models.projecttemplate import ProjectTemplate
from sentry.models.relocation import (
Expand All @@ -24,6 +23,7 @@
ProjectTransactionThreshold,
ProjectTransactionThresholdOverride,
)
from sentry.notifications.models.notificationsettingoption import NotificationSettingOption
from sentry.sentry_apps.models import SentryAppInstallationForProvider
from sentry.uptime.models import ProjectUptimeSubscription, UptimeSubscription

Expand Down
2 changes: 1 addition & 1 deletion tests/sentry/incidents/action_handlers/test_email.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
)
from sentry.incidents.models.incident import INCIDENT_STATUS, IncidentStatus, TriggerStatus
from sentry.incidents.utils.types import AlertRuleActivationConditionType
from sentry.models.notificationsettingoption import NotificationSettingOption
from sentry.notifications.models.notificationsettingoption import NotificationSettingOption
from sentry.seer.anomaly_detection.types import StoreDataResponse
from sentry.sentry_metrics import indexer
from sentry.sentry_metrics.use_case_id_registry import UseCaseID
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
from sentry.integrations.types import ExternalProviders
from sentry.issues.grouptype import MonitorIncidentType
from sentry.issues.issue_occurrence import IssueEvidence, IssueOccurrence
from sentry.models.notificationsettingoption import NotificationSettingOption
from sentry.models.notificationsettingprovider import NotificationSettingProvider
from sentry.models.projectownership import ProjectOwnership
from sentry.models.rule import Rule
from sentry.notifications.models.notificationsettingoption import NotificationSettingOption
from sentry.notifications.notifications.rules import AlertRuleNotification
from sentry.notifications.types import ActionTargetType, FallthroughChoiceType, FineTuningAPIKey
from sentry.ownership.grammar import Matcher, Owner
Expand Down
2 changes: 1 addition & 1 deletion tests/sentry/mail/activity/test_note.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from sentry.integrations.types import ExternalProviders
from sentry.models.activity import Activity
from sentry.models.notificationsettingoption import NotificationSettingOption
from sentry.notifications.models.notificationsettingoption import NotificationSettingOption
from sentry.notifications.notifications.activity.note import NoteActivityNotification
from sentry.notifications.types import GroupSubscriptionReason
from sentry.silo.base import SiloMode
Expand Down
2 changes: 1 addition & 1 deletion tests/sentry/mail/activity/test_release.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
from sentry.integrations.types import ExternalProviderEnum, ExternalProviders
from sentry.models.activity import Activity
from sentry.models.environment import Environment
from sentry.models.notificationsettingoption import NotificationSettingOption
from sentry.models.notificationsettingprovider import NotificationSettingProvider
from sentry.models.release import Release
from sentry.models.repository import Repository
from sentry.notifications.models.notificationsettingoption import NotificationSettingOption
from sentry.notifications.notifications.activity.release import ReleaseActivityNotification
from sentry.notifications.types import (
GroupSubscriptionReason,
Expand Down
2 changes: 1 addition & 1 deletion tests/sentry/mail/test_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
from sentry.mail import build_subject_prefix, mail_adapter
from sentry.models.activity import Activity
from sentry.models.grouprelease import GroupRelease
from sentry.models.notificationsettingoption import NotificationSettingOption
from sentry.models.notificationsettingprovider import NotificationSettingProvider
from sentry.models.options.project_option import ProjectOption
from sentry.models.organization import Organization
Expand All @@ -33,6 +32,7 @@
from sentry.models.repository import Repository
from sentry.models.rule import Rule
from sentry.models.userreport import UserReport
from sentry.notifications.models.notificationsettingoption import NotificationSettingOption
from sentry.notifications.notifications.rules import AlertRuleNotification
from sentry.notifications.types import ActionTargetType, FallthroughChoiceType
from sentry.notifications.utils.digest import get_digest_subject
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import pytest

from sentry.models.notificationsettingoption import NotificationSettingOption
from sentry.notifications.models.notificationsettingoption import NotificationSettingOption
from sentry.testutils.cases import TestMigrations


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import pytest

from sentry.models.notificationsettingoption import NotificationSettingOption
from sentry.notifications.models.notificationsettingoption import NotificationSettingOption
from sentry.testutils.cases import TestMigrations
from sentry.testutils.silo import control_silo_test

Expand Down
2 changes: 1 addition & 1 deletion tests/sentry/models/test_groupsubscription.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
from sentry.integrations.types import ExternalProviderEnum, ExternalProviders
from sentry.models.group import Group
from sentry.models.groupsubscription import GroupSubscription
from sentry.models.notificationsettingoption import NotificationSettingOption
from sentry.models.notificationsettingprovider import NotificationSettingProvider
from sentry.models.team import Team
from sentry.notifications.models.notificationsettingoption import NotificationSettingOption
from sentry.notifications.types import (
GroupSubscriptionReason,
NotificationScopeEnum,
Expand Down
2 changes: 1 addition & 1 deletion tests/sentry/models/test_organization.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@
)
from sentry.models.apikey import ApiKey
from sentry.models.auditlogentry import AuditLogEntry
from sentry.models.notificationsettingoption import NotificationSettingOption
from sentry.models.notificationsettingprovider import NotificationSettingProvider
from sentry.models.options.organization_option import OrganizationOption
from sentry.models.organization import Organization
from sentry.models.organizationmember import OrganizationMember
from sentry.notifications.models.notificationsettingoption import NotificationSettingOption
from sentry.silo.base import SiloMode
from sentry.testutils.cases import TestCase
from sentry.testutils.helpers.features import with_feature
Expand Down
2 changes: 1 addition & 1 deletion tests/sentry/models/test_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from sentry.integrations.types import ExternalProviders
from sentry.models.environment import Environment, EnvironmentProject
from sentry.models.grouplink import GroupLink
from sentry.models.notificationsettingoption import NotificationSettingOption
from sentry.models.options.project_option import ProjectOption
from sentry.models.options.project_template_option import ProjectTemplateOption
from sentry.models.organizationmember import OrganizationMember
Expand All @@ -20,6 +19,7 @@
from sentry.models.releases.release_project import ReleaseProject
from sentry.models.rule import Rule
from sentry.monitors.models import Monitor, MonitorEnvironment, MonitorType, ScheduleType
from sentry.notifications.models.notificationsettingoption import NotificationSettingOption
from sentry.notifications.types import NotificationSettingEnum
from sentry.notifications.utils.participants import get_notification_recipients
from sentry.silo.base import SiloMode
Expand Down
2 changes: 1 addition & 1 deletion tests/sentry/models/test_team.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from django.test import override_settings

from sentry.deletions.tasks.hybrid_cloud import schedule_hybrid_cloud_foreign_key_jobs_control
from sentry.models.notificationsettingoption import NotificationSettingOption
from sentry.models.notificationsettingprovider import NotificationSettingProvider
from sentry.models.organizationmember import OrganizationMember
from sentry.models.organizationmemberteam import OrganizationMemberTeam
from sentry.models.team import Team
from sentry.notifications.models.notificationsettingoption import NotificationSettingOption
from sentry.silo.base import SiloMode
from sentry.testutils.cases import TestCase
from sentry.testutils.outbox import outbox_runner
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

from sentry.constants import ObjectStatus
from sentry.grouping.utils import hash_from_values
from sentry.models.notificationsettingoption import NotificationSettingOption
from sentry.monitors.models import (
CheckInStatus,
Monitor,
Expand All @@ -19,6 +18,7 @@
ScheduleType,
)
from sentry.monitors.tasks.detect_broken_monitor_envs import detect_broken_monitor_envs
from sentry.notifications.models.notificationsettingoption import NotificationSettingOption
from sentry.silo.base import SiloMode
from sentry.testutils.cases import TestCase
from sentry.testutils.helpers.datetime import before_now
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from sentry.deletions.tasks.hybrid_cloud import schedule_hybrid_cloud_foreign_key_jobs_control
from sentry.models.notificationsettingoption import NotificationSettingOption
from sentry.notifications.models.notificationsettingoption import NotificationSettingOption
from sentry.silo.base import SiloMode
from sentry.testutils.cases import TestCase
from sentry.testutils.outbox import outbox_runner
Expand Down
2 changes: 1 addition & 1 deletion tests/sentry/notifications/test_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from urllib.parse import parse_qs, urlparse

from sentry.integrations.models.external_actor import ExternalActor
from sentry.models.notificationsettingoption import NotificationSettingOption
from sentry.models.organizationmemberteamreplica import OrganizationMemberTeamReplica
from sentry.models.rule import Rule
from sentry.notifications.helpers import (
Expand All @@ -12,6 +11,7 @@
team_is_valid_recipient,
validate,
)
from sentry.notifications.models.notificationsettingoption import NotificationSettingOption
from sentry.notifications.types import NotificationSettingEnum, NotificationSettingsOptionEnum
from sentry.notifications.utils import (
get_email_link_extra_params,
Expand Down
Loading
Loading