From b612f65479bb29bcf82551983173509fe64686ed Mon Sep 17 00:00:00 2001 From: Matthew Jones Date: Fri, 10 Jun 2016 15:04:35 -0400 Subject: [PATCH] Fix up the project teams list This was still referencing the old mechanism for pulling associative information. This updates it to query against the new role system --- awx/api/views.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/awx/api/views.py b/awx/api/views.py index 9617e63b93..0643c03582 100644 --- a/awx/api/views.py +++ b/awx/api/views.py @@ -979,12 +979,19 @@ class ProjectPlaybooks(RetrieveAPIView): model = Project serializer_class = ProjectPlaybooksSerializer -class ProjectTeamsList(SubListCreateAttachDetachAPIView): +class ProjectTeamsList(ListAPIView): model = Team serializer_class = TeamSerializer - parent_model = Project - relationship = 'teams' + + def get_queryset(self): + p = get_object_or_404(Project, pk=self.kwargs['pk']) + if not self.request.user.can_access(Project, 'read', p): + raise PermissionDenied() + project_ct = ContentType.objects.get_for_model(Project) + team_ct = ContentType.objects.get_for_model(self.model) + all_roles = Role.objects.filter(Q(descendents__content_type=project_ct) & Q(descendents__object_id=p.pk), content_type=team_ct) + return self.model.objects.filter(pk__in=[t.content_object.pk for t in all_roles]) class ProjectSchedulesList(SubListCreateAttachDetachAPIView):