Skip to content

App platform/update permissions token auth #14046

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

Merged
merged 3 commits into from
Jul 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions src/sentry/api/bases/sentryapps.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,16 @@ def wrapped(self, *args, **kwargs):

class SentryAppsPermission(SentryPermission):
scope_map = {
'GET': (), # Public endpoint.
# GET is ideally a public endpoint but for now we are allowing for
# anyone who has member permissions or above.
'GET': ('event:read',
'event:write',
'event:admin',
'project:releases',
'project:read',
'org:read',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MeredithAnya What about the org:write permission? Do all users who have org:write also have org:read?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'member:read',
'team:read',),
'POST': ('org:read', 'org:integrations', 'org:write', 'org:admin'),
}

Expand Down Expand Up @@ -118,12 +127,25 @@ class SentryAppPermission(SentryPermission):
}

published_scope_map = {
'GET': (), # Public endpoint.
# GET is ideally a public endpoint but for now we are allowing for
# anyone who has member permissions or above.
'GET': ('event:read',
'event:write',
'event:admin',
'project:releases',
'project:read',
'org:read',
'member:read',
'team:read',),
'PUT': ('org:write', 'org:admin'),
'POST': ('org:write', 'org:admin'),
'DELETE': ('org:admin'),
}

@property
def scope_map(self):
return self.published_scope_map

def has_object_permission(self, request, view, sentry_app):
if not hasattr(request, 'user') or not request.user:
return False
Expand Down
6 changes: 6 additions & 0 deletions tests/sentry/api/bases/test_sentryapps.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ def test_request_user_is_not_app_owner_fails(self):
with self.assertRaises(Http404):
self.permission.has_object_permission(self.request, None, self.sentry_app)

def test_has_permission(self):
from sentry.models import ApiToken
token = ApiToken.objects.create(user=self.user, scope_list=['event:read', 'org:read'])
self.request = self.make_request(user=None, auth=token, method='GET')
assert self.permission.has_permission(self.request, None)


class SentryAppBaseEndpointTest(TestCase):
def setUp(self):
Expand Down