Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix export job #5282

Merged
merged 11 commits into from
Nov 16, 2022
1 change: 1 addition & 0 deletions cvat/apps/iam/permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -892,6 +892,7 @@ def get_scopes(request, view, obj):
('update', 'PUT'): 'update', # TODO: do we need the method?
('destroy', 'DELETE'): 'delete',
('annotations', 'GET'): 'view:annotations',
('dataset_export', 'GET'): 'export:dataset',
('annotations', 'PATCH'): 'update:annotations',
('annotations', 'DELETE'): 'delete:annotations',
('annotations', 'PUT'): 'update:annotations',
Expand Down
8 changes: 4 additions & 4 deletions cvat/apps/iam/rules/jobs.rego
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import data.organizations

# input: {
# "scope": <"view"|"list"|"update:state"|"update:stage"|"update:assignee""delete"|
# "view:annotations"|"update:annotations"|"delete:annotations"|"view:data"> or null,
# "view:annotations"|"update:annotations"|"delete:annotations"|"view:data"|"export:dataset"> or null,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kirill-sizov , do we need to update CSV file as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nmanovic Yes, we need, I have updated

# "auth": {
# "user": {
# "id": <num>,
Expand Down Expand Up @@ -139,20 +139,20 @@ filter = [] { # Django Q object to filter list of entries
}

allow {
{ utils.VIEW, utils.VIEW_ANNOTATIONS, utils.VIEW_DATA, utils.VIEW_METADATA, utils.VIEW_COMMITS }[input.scope]
{ utils.VIEW, utils.EXPORT_DATASET, utils.EXPORT_ANNOTATIONS, utils.VIEW_ANNOTATIONS, utils.VIEW_DATA, utils.VIEW_METADATA, utils.VIEW_COMMITS }[input.scope]
utils.is_sandbox
is_job_staff
}

allow {
{ utils.VIEW, utils.VIEW_ANNOTATIONS, utils.VIEW_DATA, utils.VIEW_METADATA, utils.VIEW_COMMITS }[input.scope]
{ utils.VIEW, utils.EXPORT_DATASET, utils.EXPORT_ANNOTATIONS, utils.VIEW_ANNOTATIONS, utils.VIEW_DATA, utils.VIEW_METADATA, utils.VIEW_COMMITS }[input.scope]
input.auth.organization.id == input.resource.organization.id
utils.has_perm(utils.USER)
organizations.has_perm(organizations.MAINTAINER)
}

allow {
{ utils.VIEW, utils.VIEW_ANNOTATIONS, utils.VIEW_DATA, utils.VIEW_METADATA, utils.VIEW_COMMITS }[input.scope]
{ utils.VIEW, utils.EXPORT_DATASET, utils.EXPORT_ANNOTATIONS, utils.VIEW_ANNOTATIONS, utils.VIEW_DATA, utils.VIEW_METADATA, utils.VIEW_COMMITS }[input.scope]
input.auth.organization.id == input.resource.organization.id
organizations.has_perm(organizations.WORKER)
is_job_staff
Expand Down
27 changes: 24 additions & 3 deletions tests/python/rest_api/test_jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -539,9 +539,30 @@ def test_can_export_dataset(self, admin_user: str, jobs_with_shapes: List):
response = self._export_dataset(admin_user, job["id"], format="CVAT for images 1.1")
assert response.data

def test_can_export_annotations(self, admin_user: str, jobs_with_shapes: List):
job = jobs_with_shapes[0]
response = self._export_annotations(admin_user, job["id"], format="CVAT for images 1.1")
def test_non_admin_can_export_dataset(self, users, tasks, jobs_with_shapes):
job_id, username = next(
(
(job["id"], tasks[job["task_id"]]["owner"]["username"])
for job in jobs_with_shapes
if "admin" not in users[tasks[job["task_id"]]["owner"]["id"]]["groups"]
and tasks[job["task_id"]]["target_storage"] is None
and tasks[job["task_id"]]["organization"] is None
)
)
response = self._export_dataset(username, job_id, format="CVAT for images 1.1")
assert response.data

def test_non_admin_can_export_annotations(self, users, tasks, jobs_with_shapes):
job_id, username = next(
(
(job["id"], tasks[job["task_id"]]["owner"]["username"])
for job in jobs_with_shapes
if "admin" not in users[tasks[job["task_id"]]["owner"]["id"]]["groups"]
and tasks[job["task_id"]]["target_storage"] is None
and tasks[job["task_id"]]["organization"] is None
)
)
response = self._export_annotations(username, job_id, format="CVAT for images 1.1")
assert response.data

@pytest.mark.parametrize("username, jid", [("admin1", 14)])
Expand Down