-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dev' into davrods-link-and-irods-batch-accept
- Loading branch information
Showing
32 changed files
with
2,608 additions
and
480 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
.. _api_irodsinfo: | ||
|
||
Irods Info API | ||
^^^^^^^^^^^^^^^^^ | ||
|
||
The REST API for irods info operations is described in this document. | ||
|
||
|
||
API Views | ||
========= | ||
|
||
.. currentmodule:: irodsinfo.views_api | ||
|
||
.. autoclass:: IrodsConfigRetrieveAPIView | ||
|
||
|
||
Versioning | ||
========== | ||
|
||
For accept header versioning, the following header is expected in the current | ||
SODAR version: | ||
|
||
.. code-block:: console | ||
Accept: application/vnd.bihealth.sodar+json; version=0.13.4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
"""Tests for API view permissions in the irodsinfo app""" | ||
|
||
from django.urls import reverse | ||
|
||
# Projectroles dependency | ||
from projectroles.tests.test_permissions import TestPermissionBase | ||
|
||
|
||
class TestIrodsConfigRetrieveAPIView(TestPermissionBase): | ||
"""Tests for irodsinfo API""" | ||
|
||
def setUp(self): | ||
# Create users | ||
self.superuser = self.make_user('superuser') | ||
self.superuser.is_superuser = True | ||
self.superuser.save() | ||
self.regular_user = self.make_user('regular_user') | ||
# No user | ||
self.anonymous = None | ||
|
||
def test_irods_config(self): | ||
"""Test permissions for IrodsConfigRetrieveAPIView""" | ||
url = reverse('irodsinfo:api_env') | ||
good_users = [self.superuser, self.regular_user] | ||
bad_users = [self.anonymous] | ||
self.assert_response(url, good_users, 200) | ||
self.assert_response(url, bad_users, 401) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
"""Tests for API views in the irodsinfo app""" | ||
|
||
from django.test import override_settings | ||
from django.urls import reverse | ||
from rest_framework import status | ||
|
||
from test_plus.test import TestCase | ||
|
||
from irodsinfo.tests.test_views import PLUGINS_DISABLE_IRODS | ||
|
||
|
||
class TestIrodsConfigRetrieveAPIView(TestCase): | ||
"""Tests for IrodsConfigRetrieveAPIView""" | ||
|
||
def setUp(self): | ||
# Create users | ||
self.superuser = self.make_user('superuser') | ||
self.superuser.is_superuser = True | ||
self.superuser.save() | ||
self.regular_user = self.make_user('regular_user') | ||
|
||
def test_get_irods_config(self): | ||
"""Test GET request to retrieve iRODS config""" | ||
url = reverse('irodsinfo:api_env') | ||
with self.login(self.regular_user): | ||
response = self.client.get(url) | ||
self.assertEqual(response.status_code, status.HTTP_200_OK) | ||
self.assertIn('irods_environment', response.data) | ||
|
||
@override_settings(ENABLED_BACKEND_PLUGINS=PLUGINS_DISABLE_IRODS) | ||
def test_get_irods_config_with_disabled_backend(self): | ||
"""Test GET request to retrieve iRODS config with disabled backend""" | ||
url = reverse('irodsinfo:api_env') | ||
with self.login(self.regular_user): | ||
response = self.client.get(url) | ||
self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND) | ||
self.assertIn('iRODS backend not enabled', response.data['detail']) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
"""REST API views for the irodsinfo app""" | ||
|
||
import logging | ||
|
||
from rest_framework.permissions import IsAuthenticated | ||
from rest_framework.response import Response | ||
from rest_framework.views import APIView | ||
|
||
# Projectroles dependency | ||
from projectroles.plugins import get_backend_api | ||
|
||
from irodsinfo.views import IrodsConfigMixin | ||
|
||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class IrodsEnvRetrieveAPIView(IrodsConfigMixin, APIView): | ||
""" | ||
Retrieve iRODS environment file for the current user. | ||
**URL:** ``/irods/api/environment`` | ||
**Methods:** ``GET`` | ||
**Returns:** | ||
- ``irods_environment``: iRODS client environment | ||
""" | ||
|
||
permission_classes = [IsAuthenticated] | ||
|
||
def get(self, request, *args, **kwargs): | ||
"""Get iRODS environment file""" | ||
try: | ||
irods_backend = get_backend_api('omics_irods') | ||
if not irods_backend: | ||
return Response( | ||
{'detail': 'iRODS backend not enabled'}, status=404 | ||
) | ||
env = self.get_irods_client_env(request.user, irods_backend) | ||
return Response({'irods_environment': env}) | ||
|
||
except Exception as ex: | ||
logger.error('iRODS config retrieval failed: {}'.format(ex)) | ||
return Response( | ||
{'detail': 'iRODS config retrieval failed'}, status=400 | ||
) |
Oops, something went wrong.