diff --git a/src/sentry/api/endpoints/group_notes.py b/src/sentry/api/endpoints/group_notes.py index 90edcf1d35500f..3d2ce30cffe5b2 100644 --- a/src/sentry/api/endpoints/group_notes.py +++ b/src/sentry/api/endpoints/group_notes.py @@ -66,7 +66,7 @@ def post(self, request: Request, group) -> Response: ) GroupSubscription.objects.subscribe( - group=group, subscriber=request.user, reason=GroupSubscriptionReason.comment + group=group, user=request.user, reason=GroupSubscriptionReason.comment ) mentioned_users = extract_user_ids_from_mentions(group.organization.id, mentions) diff --git a/src/sentry/api/helpers/group_index/update.py b/src/sentry/api/helpers/group_index/update.py index 8bcc03508f3f06..0ebd570785e073 100644 --- a/src/sentry/api/helpers/group_index/update.py +++ b/src/sentry/api/helpers/group_index/update.py @@ -121,7 +121,7 @@ def self_subscribe_and_assign_issue( # representation of current user if acting_user: GroupSubscription.objects.subscribe( - subscriber=acting_user, group=group, reason=GroupSubscriptionReason.status_change + user=acting_user, group=group, reason=GroupSubscriptionReason.status_change ) if self_assign_issue == "1" and not group.assignee_set.exists(): @@ -736,7 +736,7 @@ def handle_is_bookmarked( user_id=acting_user.id if acting_user else None, ) GroupSubscription.objects.subscribe( - subscriber=acting_user, group=group, reason=GroupSubscriptionReason.bookmark + user=acting_user, group=group, reason=GroupSubscriptionReason.bookmark ) elif is_bookmarked is False: GroupBookmark.objects.filter( diff --git a/src/sentry/issues/status_change.py b/src/sentry/issues/status_change.py index 84ce428fc5d1c3..7c869582cc6ca5 100644 --- a/src/sentry/issues/status_change.py +++ b/src/sentry/issues/status_change.py @@ -109,7 +109,7 @@ def handle_status_update( if not is_bulk: if acting_user: GroupSubscription.objects.subscribe( - subscriber=acting_user, + user=acting_user, group=group, reason=GroupSubscriptionReason.status_change, ) diff --git a/src/sentry/models/groupsubscription.py b/src/sentry/models/groupsubscription.py index de92ac5b0fe9f3..08f355707e7dce 100644 --- a/src/sentry/models/groupsubscription.py +++ b/src/sentry/models/groupsubscription.py @@ -34,33 +34,22 @@ class GroupSubscriptionManager(BaseManager): def subscribe( self, group: Group, - subscriber: User | RpcUser | Team, + user: User | RpcUser, reason: int = GroupSubscriptionReason.unknown, ) -> bool: """ - Subscribe a user or team to an issue, but only if that user or team has not explicitly + Subscribe a user to an issue, but only if the user has not explicitly unsubscribed. """ - from sentry.models import Team, User - try: with transaction.atomic(router.db_for_write(GroupSubscription)): - if isinstance(subscriber, User) or isinstance(subscriber, RpcUser): - self.create( - user_id=subscriber.id, - group=group, - project=group.project, - is_active=True, - reason=reason, - ) - elif isinstance(subscriber, Team): - self.create( - team=subscriber, - group=group, - project=group.project, - is_active=True, - reason=reason, - ) + self.create( + user_id=user.id, + group=group, + project=group.project, + is_active=True, + reason=reason, + ) except IntegrityError: pass return True @@ -71,18 +60,14 @@ def subscribe_actor( actor: Union[Team, User, RpcUser], reason: int = GroupSubscriptionReason.unknown, ) -> Optional[bool]: - from sentry import features from sentry.models import Team, User if isinstance(actor, RpcUser) or isinstance(actor, User): return self.subscribe(group, actor, reason) if isinstance(actor, Team): - if features.has("organizations:team-workflow-notifications", group.organization, actor): - return self.subscribe(group, actor, reason) - else: - # subscribe the members of the team - team_users_ids = list(actor.member_set.values_list("user_id", flat=True)) - return self.bulk_subscribe(group, team_users_ids, reason) + # subscribe the members of the team + team_users_ids = list(actor.member_set.values_list("user_id", flat=True)) + return self.bulk_subscribe(group, team_users_ids, reason) raise NotImplementedError("Unknown actor type: %r" % type(actor)) diff --git a/src/sentry/receivers/releases.py b/src/sentry/receivers/releases.py index 59bac71f0bac6c..3f4c7d7acf5264 100644 --- a/src/sentry/receivers/releases.py +++ b/src/sentry/receivers/releases.py @@ -141,7 +141,7 @@ def resolved_in_commit(instance, created, **kwargs): # subscribe every user for user in user_list: GroupSubscription.objects.subscribe( - subscriber=user, + user=user, group=group, reason=GroupSubscriptionReason.status_change, ) diff --git a/tests/sentry/models/test_groupsubscription.py b/tests/sentry/models/test_groupsubscription.py index 9f5e5b5ddd36b8..ff63f91ec744f5 100644 --- a/tests/sentry/models/test_groupsubscription.py +++ b/tests/sentry/models/test_groupsubscription.py @@ -12,7 +12,6 @@ from sentry.services.hybrid_cloud.user.service import user_service from sentry.silo import SiloMode from sentry.testutils.cases import TestCase -from sentry.testutils.helpers.features import with_feature from sentry.testutils.silo import assume_test_silo_mode, region_silo_test from sentry.types.integrations import ExternalProviders @@ -22,21 +21,13 @@ class SubscribeTest(TestCase): def test_simple(self): group = self.create_group() user = self.create_user() - team = self.create_team() - GroupSubscription.objects.subscribe(group=group, subscriber=user) + GroupSubscription.objects.subscribe(group=group, user=user) assert GroupSubscription.objects.filter(group=group, user_id=user.id).exists() # should not error - GroupSubscription.objects.subscribe(group=group, subscriber=user) - - GroupSubscription.objects.subscribe(group=group, subscriber=team) - - assert GroupSubscription.objects.filter(group=group, team=team).exists() - - # should not error - GroupSubscription.objects.subscribe(group=group, subscriber=team) + GroupSubscription.objects.subscribe(group=group, user=user) def test_bulk(self): group = self.create_group() @@ -97,23 +88,6 @@ def test_actor_team(self): # should not error GroupSubscription.objects.subscribe_actor(group=group, actor=team) - @with_feature("organizations:team-workflow-notifications") - def test_subscribe_team(self): - org = self.create_organization() - group = self.create_group() - user = self.create_user(email="foo@example.com") - team = self.create_team(organization=org) - self.create_member(user=user, organization=org, role="owner", teams=[team]) - - GroupSubscription.objects.subscribe_actor(group=group, actor=team) - - assert not GroupSubscription.objects.filter(group=group, user_id=user.id).exists() - - assert GroupSubscription.objects.filter(group=group, team=team).exists() - - # should not error - GroupSubscription.objects.subscribe_actor(group=group, actor=team) - @region_silo_test(stable=True) class GetParticipantsTest(TestCase):