Skip to content

Commit

Permalink
Return PermissionDenied when neither task_id nor rq_id were passed on…
Browse files Browse the repository at this point in the history
… POST /api/quality/reports
  • Loading branch information
Marishka17 committed Oct 9, 2024
1 parent e1eda0e commit bfe1488
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions cvat/apps/quality_control/permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from typing import Optional, Union, cast

from django.conf import settings
from rest_framework.exceptions import ValidationError
from rest_framework.exceptions import ValidationError, PermissionDenied

from cvat.apps.engine.models import Project, Task
from cvat.apps.engine.permissions import TaskPermission
Expand Down Expand Up @@ -60,11 +60,17 @@ def create(cls, request, view, obj, iam_context):
elif scope == Scopes.LIST and isinstance(obj, Task):
permissions.append(TaskPermission.create_scope_view(request, task=obj))
elif scope == Scopes.CREATE:
if request.query_params.get("rq_id"):
# Note: POST /api/quality/reports is used to initiate report creation and to check the process status
rq_id = request.query_params.get("rq_id")
task_id = request.data.get("task_id")

if not(task_id or rq_id):
raise PermissionDenied("Either task_id or rq_id must be specified")

if rq_id:
# There will be another check for this case during request processing
continue

task_id = request.data.get("task_id")
if task_id is not None:
# The request may have a different org or org unset
# Here we need to retrieve iam_context for this user, based on the task_id
Expand Down Expand Up @@ -125,12 +131,11 @@ def get_resource(self):
if self.obj:
obj_id = self.obj.id
task = self.obj.get_task()
elif self.scope == self.Scopes.CREATE:
if self.task_id:
try:
task = Task.objects.get(id=self.task_id)
except Task.DoesNotExist:
raise ValidationError("The specified task does not exist")
elif self.scope == self.Scopes.CREATE and self.task_id:
try:
task = Task.objects.get(id=self.task_id)
except Task.DoesNotExist:
raise ValidationError("The specified task does not exist")

if task and task.project:
project = task.project
Expand Down

0 comments on commit bfe1488

Please sign in to comment.