From 987abb16637919896735b8021e74004428f1094f Mon Sep 17 00:00:00 2001 From: Michael DeHaan Date: Sun, 31 Mar 2013 22:04:52 -0400 Subject: [PATCH] Super users can list what projects an organization is assigned to. --- lib/main/views.py | 15 +++++++++++++++ lib/urls.py | 2 ++ 2 files changed, 17 insertions(+) diff --git a/lib/main/views.py b/lib/main/views.py index 040d5ece4c..be899409ae 100644 --- a/lib/main/views.py +++ b/lib/main/views.py @@ -176,6 +176,21 @@ class ProjectsDetail(BaseDetail): serializer_class = ProjectSerializer permission_classes = (CustomRbac,) +class ProjectsOrganizationsList(BaseSubList): + + model = Organization + serializer_class = OrganizationSerializer + permission_classes = (CustomRbac,) + parent_model = Project + relationship = 'organizations' + postable = False + + def _get_queryset(self): + project = Project.objects.get(pk=self.kwargs['pk']) + if not self.request.user.is_superuser: + raise PermissionDenied() + return Organization.objects.filter(projects__in = [ project ]) + class TagsDetail(BaseDetail): model = Tag diff --git a/lib/urls.py b/lib/urls.py index 0b3423073f..ce77ec4f4e 100644 --- a/lib/urls.py +++ b/lib/urls.py @@ -39,6 +39,7 @@ views_UsersAdminOrganizationsList = views.UsersAdminOrganizationsList.as_view() # projects service views_ProjectsList = views.ProjectsList.as_view() views_ProjectsDetail = views.ProjectsDetail.as_view() +views_ProjectsOrganizationsList = views.ProjectsOrganizationsList.as_view() # audit trail service @@ -96,6 +97,7 @@ urlpatterns = patterns('', # projects service url(r'^api/v1/projects/$', views_ProjectsList), url(r'^api/v1/projects/(?P[0-9]+)/$', views_ProjectsDetail), + url(r'^api/v1/projects/(?P[0-9]+)/organizations/$', views_ProjectsOrganizationsList), # audit trail service # api/v1/audit_trails/