-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
feat(demo-mode): read-only user #79665
Open
obostjancic
wants to merge
14
commits into
master
Choose a base branch
from
ogi/feat/readonly-user
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
6ad51f1
feat: readonly user
obostjancic b8381b0
fix access
obostjancic 1bbf0dd
extract to options
obostjancic d855c31
fix
obostjancic e6c752a
Merge branch 'master' into ogi/feat/readonly-user
obostjancic 34339b5
Merge branch 'master' into ogi/feat/readonly-user
obostjancic b0a2797
Merge branch 'master' into ogi/feat/readonly-user
obostjancic 8ffccaf
Merge branch 'master' into ogi/feat/readonly-user
obostjancic 130318a
Merge branch 'master' into ogi/feat/readonly-user
obostjancic 398f783
Merge branch 'master' into ogi/feat/readonly-user
obostjancic ce2dbf1
added tests
obostjancic 63e6a85
Merge branch 'master' into ogi/feat/readonly-user
obostjancic e7935ee
add test
obostjancic 355ad98
Merge branch 'master' into ogi/feat/readonly-user
obostjancic File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
from sentry.api.permissions import ( | ||
SentryPermission, | ||
StaffPermission, | ||
SuperuserOrStaffFeatureFlaggedPermission, | ||
SuperuserPermission, | ||
|
@@ -34,3 +35,60 @@ def test_superuser_or_staff_feature_flagged_permission_inactive_option(self): | |
|
||
# With active superuser | ||
assert self.superuser_staff_flagged_permission.has_permission(self.superuser_request, None) | ||
|
||
|
||
class ReadonlyPermissionsTest(DRFPermissionTestCase): | ||
user_permission = SentryPermission() | ||
|
||
def setUp(self): | ||
super().setUp() | ||
self.normal_user = self.create_user() | ||
self.readonly_user = self.create_user("[email protected]") | ||
|
||
@override_options({"demo-mode.enabled": True, "demo-mode.users": ["[email protected]"]}) | ||
def test_readonly_user_has_permission(self): | ||
assert self.user_permission.has_permission(self.make_request(self.readonly_user), None) | ||
|
||
def test_readonly_user_has_object_permission(self): | ||
assert not self.user_permission.has_object_permission( | ||
self.make_request(self.readonly_user), None, None | ||
) | ||
|
||
@override_options({"demo-mode.enabled": True, "demo-mode.users": ["[email protected]"]}) | ||
def test_get_method(self): | ||
assert self.user_permission.has_permission( | ||
self.make_request(self.readonly_user, method="GET"), None | ||
) | ||
assert self.user_permission.has_permission( | ||
self.make_request(self.normal_user, method="GET"), None | ||
) | ||
|
||
@override_options({"demo-mode.enabled": True, "demo-mode.users": ["[email protected]"]}) | ||
def test_post_method(self): | ||
assert not self.user_permission.has_permission( | ||
self.make_request(self.readonly_user, method="POST"), None | ||
) | ||
|
||
assert self.user_permission.has_permission( | ||
self.make_request(self.normal_user, method="GET"), None | ||
) | ||
|
||
@override_options({"demo-mode.enabled": True, "demo-mode.users": ["[email protected]"]}) | ||
def test_put_method(self): | ||
assert not self.user_permission.has_permission( | ||
self.make_request(self.readonly_user, method="PUT"), None | ||
) | ||
|
||
assert self.user_permission.has_permission( | ||
self.make_request(self.normal_user, method="GET"), None | ||
) | ||
|
||
@override_options({"demo-mode.enabled": True, "demo-mode.users": ["[email protected]"]}) | ||
def test_delete_method(self): | ||
assert not self.user_permission.has_permission( | ||
self.make_request(self.readonly_user, method="DELETE"), None | ||
) | ||
|
||
assert self.user_permission.has_permission( | ||
self.make_request(self.normal_user, method="GET"), None | ||
) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't usually use
SentryPermission
directly, it's usually a base class we inherit from and apply scopes to.It seems like if you use this directly, then no users will have permissions on this api:
sentry/src/sentry/api/permissions.py
Lines 167 to 169 in 219f2e6
Since this just defined empty scopes, this
any
can't return True. Not sure if there's some other piece I'm missing that circumvents this.