|
@@ -2,14 +2,13 @@ from __future__ import absolute_import
|
|
|
|
|
|
from sentry.api.base import Endpoint
|
|
|
from sentry.api.exceptions import ResourceDoesNotExist
|
|
|
-from sentry.api.permissions import ScopedPermission
|
|
|
from sentry.app import raven
|
|
|
-from sentry.auth import access
|
|
|
from sentry.models import Project, ProjectStatus
|
|
|
-from sentry.models.apikey import ROOT_KEY
|
|
|
|
|
|
+from .team import TeamPermission
|
|
|
|
|
|
-class ProjectPermission(ScopedPermission):
|
|
|
+
|
|
|
+class ProjectPermission(TeamPermission):
|
|
|
scope_map = {
|
|
|
'GET': ['project:read', 'project:write', 'project:delete'],
|
|
|
'POST': ['project:write', 'project:delete'],
|
|
@@ -18,24 +17,8 @@ class ProjectPermission(ScopedPermission):
|
|
|
}
|
|
|
|
|
|
def has_object_permission(self, request, view, project):
|
|
|
- if request.user and request.user.is_authenticated() and request.auth:
|
|
|
- request.access = access.from_request(
|
|
|
- request, project.organization, scopes=request.auth.get_scopes(),
|
|
|
- )
|
|
|
-
|
|
|
- elif request.auth:
|
|
|
- if request.auth is ROOT_KEY:
|
|
|
- return True
|
|
|
- return request.auth.organization_id == project.organization_id
|
|
|
-
|
|
|
- else:
|
|
|
- request.access = access.from_request(request, project.organization)
|
|
|
-
|
|
|
- allowed_scopes = set(self.scope_map.get(request.method, []))
|
|
|
- return any(
|
|
|
- request.access.has_team_scope(project.team, s)
|
|
|
- for s in allowed_scopes
|
|
|
- )
|
|
|
+ return super(ProjectPermission, self).has_object_permission(
|
|
|
+ request, view, project.team)
|
|
|
|
|
|
|
|
|
class ProjectReleasePermission(ProjectPermission):
|
|
@@ -71,16 +54,18 @@ class ProjectEndpoint(Endpoint):
|
|
|
|
|
|
def convert_args(self, request, organization_slug, project_slug, *args, **kwargs):
|
|
|
try:
|
|
|
- project = Project.objects.get_from_cache(
|
|
|
+ project = Project.objects.filter(
|
|
|
organization__slug=organization_slug,
|
|
|
slug=project_slug,
|
|
|
- )
|
|
|
+ ).select_related('organization', 'team').get()
|
|
|
except Project.DoesNotExist:
|
|
|
raise ResourceDoesNotExist
|
|
|
|
|
|
if project.status != ProjectStatus.VISIBLE:
|
|
|
raise ResourceDoesNotExist
|
|
|
|
|
|
+ project.team.organization = project.organization
|
|
|
+
|
|
|
self.check_object_permissions(request, project)
|
|
|
|
|
|
raven.tags_context({
|