Skip to content

Commit f8575a5

Browse files
committed
update function description & default with empty list
1 parent 287377e commit f8575a5

File tree

2 files changed

+14
-16
lines changed

2 files changed

+14
-16
lines changed

src/sentry/replays/permissions.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,15 @@
1616

1717
def has_replay_permission(organization: Organization, user: User | AnonymousUser | None) -> bool:
1818
"""
19-
Check if a user has permission to access replay data for an organization. This
20-
change is backwards compatible with the existing behavior and introduces the
21-
ability to granularly control replay access for organization members, irrespective
22-
of their role.
23-
24-
Logic:
25-
- If feature flag is disabled, return True (existing behavior, everyone has access)
26-
- User must be authenticated and a member of the org
27-
- If no allowlist records exist for org, return True for all members
28-
- If allowlist records exist, check if user's org membership is in the allowlist
29-
- Return True if user is in allowlist, False otherwise
19+
Determine whether a user has permission to access replay data for a given organization.
20+
21+
Rules:
22+
- User must be authenticated and an active org member.
23+
- If the 'organizations:granular-replay-permissions' feature flag is OFF, all users have access.
24+
- If the 'sentry:granular-replay-permissions' org option is not set or falsy, all org members have access.
25+
- If no allowlist records exist for the organization but the feature flag is on, no one has access.
26+
- If allowlist records exist, only users explicitly present in the OrganizationMemberReplayAccess allowlist have access.
27+
- Returns True if allowed, False otherwise.
3028
"""
3129
if not features.has("organizations:granular-replay-permissions", organization):
3230
return True
@@ -51,7 +49,7 @@ def has_replay_permission(organization: Organization, user: User | AnonymousUser
5149
).exists()
5250

5351
if not allowlist_exists:
54-
return True
52+
return False
5553

5654
has_access = OrganizationMemberReplayAccess.objects.filter(
5755
organization=organization, organizationmember=member

tests/sentry/replays/test_permissions.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@ def test_org_option_disabled_returns_true(self) -> None:
3838
)
3939
assert has_replay_permission(self.organization, self.user2) is True
4040

41-
def test_empty_allowlist_returns_true(self) -> None:
42-
"""When allowlist is empty, all members should have access"""
41+
def test_empty_allowlist_returns_false(self) -> None:
42+
"""When allowlist is empty access control is active, no one should have access"""
4343
with self.feature("organizations:granular-replay-permissions"):
4444
self._enable_granular_permissions()
45-
assert has_replay_permission(self.organization, self.user1) is True
46-
assert has_replay_permission(self.organization, self.user2) is True
45+
assert has_replay_permission(self.organization, self.user1) is False
46+
assert has_replay_permission(self.organization, self.user2) is False
4747

4848
def test_member_in_allowlist_returns_true(self) -> None:
4949
"""When member is in allowlist, they should have access"""

0 commit comments

Comments
 (0)