Browse Source

ref(models): `ActivityType` (#34978)

## Objective:
We want to separate enum logic from Model logic. This breaks a lot of circular dependencies.
Marcos Gaeta 2 years ago
parent
commit
b9f5a910dc

+ 4 - 3
bin/load-mocks

@@ -3,6 +3,7 @@
 import time
 
 from sentry.runner import configure
+from sentry.types.activity import ActivityType
 
 configure()
 
@@ -510,7 +511,7 @@ def main(num_events=1, extra_events=False, load_trends=False, slow=False):
             )[0]
 
             Activity.objects.create(
-                type=Activity.RELEASE,
+                type=ActivityType.RELEASE.value,
                 project=project,
                 ident=release.version,
                 user=user,
@@ -541,7 +542,7 @@ def main(num_events=1, extra_events=False, load_trends=False, slow=False):
             )
 
             Activity.objects.create(
-                type=Activity.DEPLOY,
+                type=ActivityType.DEPLOY.value,
                 project=project,
                 ident=release.version,
                 data={
@@ -710,7 +711,7 @@ def main(num_events=1, extra_events=False, load_trends=False, slow=False):
     create_mock_transactions(project_map, load_trends, slow)
 
     Activity.objects.create(
-        type=Activity.RELEASE,
+        type=ActivityType.RELEASE.value,
         project=project,
         ident="4f38b65c62c4565aa94bba391ff8946922a8eed4",
         user=user,

+ 2 - 1
src/sentry/api/endpoints/group_integration_details.py

@@ -10,6 +10,7 @@ from sentry.integrations import IntegrationFeatures
 from sentry.models import Activity, ExternalIssue, GroupLink, Integration
 from sentry.shared_integrations.exceptions import IntegrationError, IntegrationFormError
 from sentry.signals import integration_issue_created, integration_issue_linked
+from sentry.types.activity import ActivityType
 
 MISSING_FEATURE_MESSAGE = "Your organization does not have access to this feature."
 
@@ -36,7 +37,7 @@ class GroupIntegrationDetailsEndpoint(GroupEndpoint):
         Activity.objects.create(
             project=group.project,
             group=group,
-            type=Activity.CREATE_ISSUE,
+            type=ActivityType.CREATE_ISSUE.value,
             user=request.user,
             data=issue_information,
         )

+ 4 - 2
src/sentry/api/endpoints/group_notes.py

@@ -18,7 +18,9 @@ from sentry.utils.functional import extract_lazy_object
 
 class GroupNotesEndpoint(GroupEndpoint):
     def get(self, request: Request, group) -> Response:
-        notes = Activity.objects.filter(group=group, type=Activity.NOTE).select_related("user")
+        notes = Activity.objects.filter(group=group, type=ActivityType.NOTE.value).select_related(
+            "user"
+        )
 
         return self.paginate(
             request=request,
@@ -47,7 +49,7 @@ class GroupNotesEndpoint(GroupEndpoint):
 
         if Activity.objects.filter(
             group=group,
-            type=Activity.NOTE,
+            type=ActivityType.NOTE.value,
             user=request.user,
             data=data,
             datetime__gte=timezone.now() - timedelta(hours=1),

+ 3 - 2
src/sentry/api/endpoints/group_notes_details.py

@@ -9,6 +9,7 @@ from sentry.api.serializers import serialize
 from sentry.api.serializers.rest_framework.group_notes import NoteSerializer
 from sentry.models import Activity
 from sentry.signals import comment_deleted, comment_updated
+from sentry.types.activity import ActivityType
 
 
 class GroupNotesDetailsEndpoint(GroupEndpoint):
@@ -22,7 +23,7 @@ class GroupNotesDetailsEndpoint(GroupEndpoint):
 
         try:
             note = Activity.objects.get(
-                group=group, type=Activity.NOTE, user=request.user, id=note_id
+                group=group, type=ActivityType.NOTE.value, user=request.user, id=note_id
             )
         except Activity.DoesNotExist:
             raise ResourceDoesNotExist
@@ -52,7 +53,7 @@ class GroupNotesDetailsEndpoint(GroupEndpoint):
 
         try:
             note = Activity.objects.get(
-                group=group, type=Activity.NOTE, user=request.user, id=note_id
+                group=group, type=ActivityType.NOTE.value, user=request.user, id=note_id
             )
         except Activity.DoesNotExist:
             raise ResourceDoesNotExist

+ 2 - 1
src/sentry/api/endpoints/organization_activity.py

@@ -8,6 +8,7 @@ from sentry.api.bases import OrganizationMemberEndpoint
 from sentry.api.paginator import DateTimePaginator
 from sentry.api.serializers import OrganizationActivitySerializer, serialize
 from sentry.models import Activity, OrganizationMemberTeam, Project
+from sentry.types.activity import ActivityType
 
 
 class OrganizationActivityEndpoint(OrganizationMemberEndpoint, EnvironmentMixin):
@@ -15,7 +16,7 @@ class OrganizationActivityEndpoint(OrganizationMemberEndpoint, EnvironmentMixin)
         # There is an activity record created for both sides of the unmerge
         # operation, so we only need to include one of them here to avoid
         # showing the same entry twice.
-        base_qs = Activity.objects.exclude(type=Activity.UNMERGE_SOURCE).values_list(
+        base_qs = Activity.objects.exclude(type=ActivityType.UNMERGE_SOURCE.value).values_list(
             "id", flat=True
         )
 

+ 2 - 1
src/sentry/api/endpoints/organization_release_details.py

@@ -22,6 +22,7 @@ from sentry.api.serializers.rest_framework import (
 from sentry.models import Activity, Project, Release, ReleaseCommitError, ReleaseStatus
 from sentry.models.release import UnsafeReleaseDeletion
 from sentry.snuba.sessions import STATS_PERIODS
+from sentry.types.activity import ActivityType
 from sentry.utils.sdk import bind_organization_context, configure_scope
 
 
@@ -483,7 +484,7 @@ class OrganizationReleaseDetailsEndpoint(
             if not was_released and release.date_released:
                 for project in projects:
                     Activity.objects.create(
-                        type=Activity.RELEASE,
+                        type=ActivityType.RELEASE.value,
                         project=project,
                         ident=Activity.get_version_ident(release.version),
                         data={"version": release.version},

+ 2 - 1
src/sentry/api/endpoints/organization_releases.py

@@ -42,6 +42,7 @@ from sentry.search.events.constants import (
 from sentry.search.events.filter import handle_operator_negation, parse_semver
 from sentry.signals import release_created
 from sentry.snuba.sessions import STATS_PERIODS
+from sentry.types.activity import ActivityType
 from sentry.utils.cache import cache
 from sentry.utils.sdk import bind_organization_context, configure_scope
 
@@ -483,7 +484,7 @@ class OrganizationReleasesEndpoint(
                 if release.date_released:
                     for project in new_projects:
                         Activity.objects.create(
-                            type=Activity.RELEASE,
+                            type=ActivityType.RELEASE.value,
                             project=project,
                             ident=Activity.get_version_ident(result["version"]),
                             data={"version": result["version"]},

+ 2 - 1
src/sentry/api/endpoints/project_release_details.py

@@ -12,6 +12,7 @@ from sentry.models import Activity, Release
 from sentry.models.release import UnsafeReleaseDeletion
 from sentry.plugins.interfaces.releasehook import ReleaseHook
 from sentry.snuba.sessions import STATS_PERIODS
+from sentry.types.activity import ActivityType
 from sentry.utils.sdk import bind_organization_context, configure_scope
 
 
@@ -129,7 +130,7 @@ class ProjectReleaseDetailsEndpoint(ProjectEndpoint, ReleaseAnalyticsMixin):
 
             if not was_released and release.date_released:
                 Activity.objects.create(
-                    type=Activity.RELEASE,
+                    type=ActivityType.RELEASE.value,
                     project=project,
                     ident=Activity.get_version_ident(release.version),
                     data={"version": release.version},

+ 2 - 1
src/sentry/api/endpoints/project_releases.py

@@ -13,6 +13,7 @@ from sentry.models import Activity, Environment, Release, ReleaseStatus
 from sentry.plugins.interfaces.releasehook import ReleaseHook
 from sentry.ratelimits.config import SENTRY_RATELIMITER_GROUP_DEFAULTS, RateLimitConfig
 from sentry.signals import release_created
+from sentry.types.activity import ActivityType
 from sentry.utils.sdk import bind_organization_context, configure_scope
 
 
@@ -158,7 +159,7 @@ class ProjectReleasesEndpoint(ProjectEndpoint, EnvironmentMixin):
 
                 if not was_released and release.date_released:
                     Activity.objects.create(
-                        type=Activity.RELEASE,
+                        type=ActivityType.RELEASE.value,
                         project=project,
                         ident=Activity.get_version_ident(result["version"]),
                         data={"version": result["version"]},

+ 10 - 9
src/sentry/api/helpers/group_index/update.py

@@ -53,6 +53,7 @@ from sentry.signals import (
 )
 from sentry.tasks.integrations import kick_off_status_syncs
 from sentry.tasks.merge import merge_groups
+from sentry.types.activity import ActivityType
 from sentry.utils import metrics
 from sentry.utils.functional import extract_lazy_object
 
@@ -262,7 +263,7 @@ def update_groups(
                 .extra(select={"sort": "COALESCE(date_released, date_added)"})
                 .order_by("-sort")[0]
             )
-            activity_type = Activity.SET_RESOLVED_IN_RELEASE
+            activity_type = ActivityType.SET_RESOLVED_IN_RELEASE.value
             activity_data = {
                 # no version yet
                 "version": ""
@@ -283,7 +284,7 @@ def update_groups(
                     {"detail": "Cannot set resolved in release for multiple projects."}, status=400
                 )
             release = statusDetails["inRelease"]
-            activity_type = Activity.SET_RESOLVED_IN_RELEASE
+            activity_type = ActivityType.SET_RESOLVED_IN_RELEASE.value
             activity_data = {
                 # no version yet
                 "version": release.version
@@ -303,7 +304,7 @@ def update_groups(
                     {"detail": "Cannot set resolved in commit for multiple projects."}, status=400
                 )
             commit = statusDetails["inCommit"]
-            activity_type = Activity.SET_RESOLVED_IN_COMMIT
+            activity_type = ActivityType.SET_RESOLVED_IN_COMMIT.value
             activity_data = {"commit": commit.id}
             status_details = {
                 "inCommit": serialize(commit, user),
@@ -312,7 +313,7 @@ def update_groups(
             res_type_str = "in_commit"
         else:
             res_type_str = "now"
-            activity_type = Activity.SET_RESOLVED
+            activity_type = ActivityType.SET_RESOLVED.value
             activity_data = {}
             status_details = {}
 
@@ -575,7 +576,7 @@ def update_groups(
                 result["statusDetails"] = {}
         if group_list and happened:
             if new_status == GroupStatus.UNRESOLVED:
-                activity_type = Activity.SET_UNRESOLVED
+                activity_type = ActivityType.SET_UNRESOLVED.value
                 activity_data = {}
 
                 for group in group_list:
@@ -596,7 +597,7 @@ def update_groups(
                             sender=update_groups,
                         )
             elif new_status == GroupStatus.IGNORED:
-                activity_type = Activity.SET_IGNORED
+                activity_type = ActivityType.SET_IGNORED.value
                 activity_data = {
                     "ignoreCount": ignore_count,
                     "ignoreDuration": ignore_duration,
@@ -762,7 +763,7 @@ def update_groups(
                 Activity.objects.create(
                     project=project_lookup[group.project_id],
                     group=group,
-                    type=Activity.SET_PRIVATE,
+                    type=ActivityType.SET_PRIVATE.value,
                     user=acting_user,
                 )
 
@@ -776,7 +777,7 @@ def update_groups(
                 Activity.objects.create(
                     project=project_lookup[group.project_id],
                     group=group,
-                    type=Activity.SET_PUBLIC,
+                    type=ActivityType.SET_PUBLIC.value,
                     user=acting_user,
                 )
 
@@ -808,7 +809,7 @@ def update_groups(
         Activity.objects.create(
             project=project_lookup[primary_group.project_id],
             group=primary_group,
-            type=Activity.MERGE,
+            type=ActivityType.MERGE.value,
             user=acting_user,
             data={"issues": [{"id": c.id} for c in groups_to_merge]},
         )

Some files were not shown because too many files changed in this diff