Skip to content

Commit

Permalink
Merge pull request #316 from OpenImaging/allow-imports
Browse files Browse the repository at this point in the history
Allow anyone with project access to import/export
  • Loading branch information
dchiquito authored Feb 9, 2022
2 parents bf25f08 + 92de005 commit 3ef32a6
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 7 deletions.
3 changes: 2 additions & 1 deletion client/src/components/ProjectSettings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ export default defineComponent({
<v-layout>
<v-switch
v-model="globalImportExport"
:disabled="!user.is_superuser"
@click="changed = true"
color="primary"
label="Global import/export"
Expand Down Expand Up @@ -186,7 +187,7 @@ export default defineComponent({
</v-btn>
</v-col>
<v-col cols="9">
<DataImportExport v-if="user.is_superuser" />
<DataImportExport />
</v-col>
<v-col
cols="2"
Expand Down
1 change: 0 additions & 1 deletion client/src/views/Projects.vue
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,6 @@ export default defineComponent({
<v-card-title>Project: {{ currentProject.name }}</v-card-title>
<div class="flex-container">
<v-card
v-if="user.is_superuser"
class="flex-card"
style="flex-grow: 4;"
>
Expand Down
2 changes: 1 addition & 1 deletion miqa/core/rest/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ def settings_(self, request, **kwargs):
request_body=no_body,
responses={204: 'Import succeeded.'},
)
@project_permission_required(superuser_access=True)
@project_permission_required()
@action(detail=True, url_path='import', url_name='import', methods=['POST'])
def import_(self, request, **kwargs):
project: Project = self.get_object()
Expand Down
9 changes: 5 additions & 4 deletions miqa/core/tests/test_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from pathlib import Path
import re

from guardian.shortcuts import get_perms
import pytest
from rest_framework.exceptions import APIException

Expand Down Expand Up @@ -86,7 +87,7 @@ def test_import_csv(tmp_path, user, project_factory, sample_scans, user_api_clie
user_api_client = user_api_client(project=project)

resp = user_api_client.post(f'/api/v1/projects/{project.id}/import')
if user.is_superuser:
if get_perms(user, project):
assert resp.status_code == 204
# The import should update the project, even though the names do not match
project.refresh_from_db()
Expand Down Expand Up @@ -115,7 +116,7 @@ def test_import_global_csv(tmp_path, user, project_factory, sample_scans, user_a
user_api_client = user_api_client(project=project)

resp = user_api_client.post(f'/api/v1/projects/{project.id}/import')
if user.is_superuser:
if get_perms(user, project):
assert resp.status_code == 204
# The import should update the correctly named projects, but not the original import project
project.refresh_from_db()
Expand Down Expand Up @@ -147,7 +148,7 @@ def test_import_json(
project = project_factory(import_path=json_file)

resp = user_api_client(project=project).post(f'/api/v1/projects/{project.id}/import')
if user.is_superuser:
if get_perms(user, project):
assert resp.status_code == 204
# The import should update the project, even though the names do not match
project.refresh_from_db()
Expand Down Expand Up @@ -181,7 +182,7 @@ def test_import_global_json(
user_api_client = user_api_client(project=project)

resp = user_api_client.post(f'/api/v1/projects/{project.id}/import')
if user.is_superuser:
if get_perms(user, project):
assert resp.status_code == 204
# The import should update the correctly named projects, but not the original import project
project.refresh_from_db()
Expand Down

0 comments on commit 3ef32a6

Please sign in to comment.