def get_serializer_class(self): use_admin_serializer = False if self.action == "create": use_admin_serializer = True if self.action == "retrieve": use_admin_serializer = permissions_service.is_project_owner(self.request.user, self.object.project) project_id = self.request.QUERY_PARAMS.get("project", None) if self.action == "list" and project_id is not None: project = get_object_or_404(models.Project, pk=project_id) use_admin_serializer = permissions_service.is_project_owner(self.request.user, project) if use_admin_serializer: return self.admin_serializer_class else: return self.serializer_class
def get_serializer_class(self): project_id = self.request.QUERY_PARAMS.get("project", None) if project_id is None: # Creation if self.request.method == 'POST': return self.admin_serializer_class return self.serializer_class project = get_object_or_404(models.Project, pk=project_id) if permissions_service.is_project_owner(self.request.user, project): return self.admin_serializer_class return self.serializer_class
def get_serializer_class(self): if self.action == "list": return self.list_serializer_class elif self.action == "create": return self.serializer_class if self.action == "by_slug": slug = self.request.QUERY_PARAMS.get("slug", None) project = get_object_or_404(models.Project, slug=slug) else: project = self.get_object() if permissions_service.is_project_owner(self.request.user, project): return self.admin_serializer_class return self.serializer_class
def get_i_am_owner(self, obj): if "request" in self.context: return is_project_owner(self.context["request"].user, obj) return False
def check_permissions(self, request, view, obj=None): return is_project_owner(request.user, obj)
def check_permissions(self, request, view, obj=None): model = get_model_from_key(obj.key) pk = get_pk_from_key(obj.key) project = model.objects.get(pk=pk) return is_project_owner(request.user, project)
def check_permissions(self, request, view, obj=None): return is_project_owner(request.user, obj.webhook.project)