From 7bf14056836389ff90f73d7c81ccbf5eecc25cc1 Mon Sep 17 00:00:00 2001 From: Hironsan Date: Thu, 3 Aug 2023 16:29:51 +0900 Subject: [PATCH] Return all examples to project admin --- backend/examples/views/example.py | 8 +++++--- backend/projects/models.py | 3 +++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/backend/examples/views/example.py b/backend/examples/views/example.py index 43b0963a..38fdfa04 100644 --- a/backend/examples/views/example.py +++ b/backend/examples/views/example.py @@ -7,7 +7,7 @@ from rest_framework.response import Response from examples.filters import ExampleFilter from examples.models import Example from examples.serializers import ExampleSerializer -from projects.models import Project +from projects.models import Member, Project from projects.permissions import IsProjectAdmin, IsProjectStaffAndReadOnly @@ -25,8 +25,10 @@ class ExampleList(generics.ListCreateAPIView): return get_object_or_404(Project, pk=self.kwargs["project_id"]) def get_queryset(self): - queryset = self.model.objects.filter(project=self.project, assignments__assignee=self.request.user) - return queryset + member = get_object_or_404(Member, project=self.project, user=self.request.user) + if member.is_admin: + return self.model.objects.filter(project=self.project) + return self.model.objects.filter(project=self.project, assignments__assignee=self.request.user) def perform_create(self, serializer): serializer.save(project=self.project) diff --git a/backend/projects/models.py b/backend/projects/models.py index 08022190..bd5a2f26 100644 --- a/backend/projects/models.py +++ b/backend/projects/models.py @@ -210,6 +210,9 @@ class Member(models.Model): message = "This user is already assigned to a role in this project." raise ValidationError(message) + def is_admin(self): + return self.role.name == settings.ROLE_PROJECT_ADMIN + @property def username(self): return self.user.username