|
@@ -5,10 +5,11 @@ from sentry.api.exceptions import ResourceDoesNotExist
|
|
|
from sentry.app import raven
|
|
|
from sentry.models import Project, ProjectStatus
|
|
|
|
|
|
-from .team import TeamPermission
|
|
|
+from .organization import OrganizationPermission
|
|
|
+from .team import has_team_permission
|
|
|
|
|
|
|
|
|
-class ProjectPermission(TeamPermission):
|
|
|
+class ProjectPermission(OrganizationPermission):
|
|
|
scope_map = {
|
|
|
'GET': ['project:read', 'project:write', 'project:admin'],
|
|
|
'POST': ['project:write', 'project:admin'],
|
|
@@ -17,7 +18,15 @@ class ProjectPermission(TeamPermission):
|
|
|
}
|
|
|
|
|
|
def has_object_permission(self, request, view, project):
|
|
|
- return super(ProjectPermission, self).has_object_permission(request, view, project.team)
|
|
|
+ result = super(ProjectPermission,
|
|
|
+ self).has_object_permission(request, view, project.organization)
|
|
|
+
|
|
|
+ if not result:
|
|
|
+ return result
|
|
|
+
|
|
|
+ return any(
|
|
|
+ has_team_permission(request, team, self.scope_map) for team in project.teams.all()
|
|
|
+ )
|
|
|
|
|
|
|
|
|
class StrictProjectPermission(ProjectPermission):
|
|
@@ -74,15 +83,13 @@ class ProjectEndpoint(Endpoint):
|
|
|
project = Project.objects.filter(
|
|
|
organization__slug=organization_slug,
|
|
|
slug=project_slug,
|
|
|
- ).select_related('organization', 'team').get()
|
|
|
+ ).select_related('organization').prefetch_related('teams').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({
|