Skip to content

Commit 7db689a

Browse files
committed
fix(teams): Keep a team's issue subscriptions when removing a pending invite
Removing a member from a team unsubscribes them from the team's issues with GroupSubscription.filter(user_id=member.user_id). A pending invite has no user, so user_id=None matched the team's own subscriptions (user_id is NULL on those rows) and deleted them.
1 parent cbc4755 commit 7db689a

2 files changed

Lines changed: 23 additions & 0 deletions

File tree

‎src/sentry/core/endpoints/organization_member_team_details.py‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -586,6 +586,9 @@ def _unsubscribe_issues(team: Team, member: OrganizationMember) -> None:
586586
"""
587587
Unsubscribe user from issues the team is subscribed to
588588
"""
589+
# A pending invite has no subscriptions, and user_id=None would match the team's own.
590+
if member.user_id is None:
591+
return
589592
team_assigned_groups = GroupAssignee.objects.filter(team_id=team.id).values_list(
590593
"group_id", flat=True
591594
)

‎tests/sentry/core/endpoints/test_organization_member_team_details.py‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -800,6 +800,26 @@ def test_cannot_leave_idp_provisioned_team(self) -> None:
800800
team=idp_team, organizationmember=member
801801
).exists()
802802

803+
def test_removing_pending_invite_keeps_team_subscriptions(self) -> None:
804+
invite = self.create_member(
805+
organization=self.org, email="invited@example.com", role="member", teams=[self.team]
806+
)
807+
group = self.create_group()
808+
GroupAssignee.objects.create(group=group, team=self.team, project=group.project)
809+
GroupSubscription.objects.create(
810+
group=group,
811+
project=group.project,
812+
team=self.team,
813+
reason=GroupSubscriptionReason.assigned,
814+
)
815+
816+
self.login_as(self.user)
817+
self.get_success_response(
818+
self.org.slug, invite.id, self.team.slug, status_code=status.HTTP_200_OK
819+
)
820+
821+
assert GroupSubscription.objects.filter(group=group, team=self.team).exists()
822+
803823
def test_unsubscribe_user_from_team_issues_legacy(self) -> None:
804824
"""
805825
We have some legacy DB rows from before the GroupSubscription table had a team_id

0 commit comments

Comments
 (0)