diff --git a/arkindex/dataimport/api.py b/arkindex/dataimport/api.py index 825e480e1298664425aac9e92df312a4a0e79c1b..495f1a8541baad7fce4fff3a9555bf1bb27a6324 100644 --- a/arkindex/dataimport/api.py +++ b/arkindex/dataimport/api.py @@ -649,3 +649,19 @@ class WorkerVersionList(ListCreateAPIView): reponse_status = status.HTTP_201_CREATED if created else status.HTTP_200_OK return Response(WorkerVersionSerializer(version).data, status=reponse_status) + + +class WorkerVersionRetrieve(CorpusACLMixin, RetrieveAPIView): + """ + Retrieve a specific worker version + """ + permission_classes = (IsVerified, ) + serializer_class = WorkerVersionSerializer + openapi_overrides = { + 'tags': ['repos'], + } + + def get_queryset(self): + return WorkerVersion.objects.filter( + revision__repo__corpus__in=Corpus.objects.readable(self.request.user), + ) diff --git a/arkindex/dataimport/tests/test_workers_api.py b/arkindex/dataimport/tests/test_workers_api.py index 7a70e597615d79a2076a504932fbe1af3b6236db..7694a94c5097f6f95cdec0f74b8971ec8f8a711e 100644 --- a/arkindex/dataimport/tests/test_workers_api.py +++ b/arkindex/dataimport/tests/test_workers_api.py @@ -220,3 +220,23 @@ class TestWorkersWorkerVersions(FixtureAPITestCase): 'revision': ['This field is required.'], 'configuration': ['This field is required.'] }) + + def test_retrieve_version_requires_login(self): + response = self.client.get(reverse('api:version-retrieve', kwargs={'pk': str(self.version_1.id)})) + self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) + + def test_retrieve_version_invalid_id(self): + self.client.force_login(self.user) + response = self.client.get( + reverse('api:version-retrieve', kwargs={'pk': '12341234-1234-1234-1234-123412341234'}) + ) + self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND) + + def test_retrieve_version(self): + self.client.force_login(self.user) + response = self.client.get(reverse('api:version-retrieve', kwargs={'pk': str(self.version_1.id)})) + self.assertEqual(response.status_code, status.HTTP_200_OK) + data = response.json() + self.assertEqual(data['id'], str(self.version_1.id)) + self.assertEqual(data['configuration'], {"test": "test1"}) + self.assertEqual(data['revision']['id'], str(self.rev.id)) diff --git a/arkindex/project/api_v1.py b/arkindex/project/api_v1.py index 5022e2b682b2bad10cda7063acc0b0e3bb81df63..3ba7200c5810922516afa8b92fdeefa2bbb3825e 100644 --- a/arkindex/project/api_v1.py +++ b/arkindex/project/api_v1.py @@ -27,7 +27,7 @@ from arkindex.dataimport.api import ( DataFileList, DataFileRetrieve, DataFileUpload, DataImportFromFiles, RepositoryList, RepositoryRetrieve, RepositoryStartImport, DataFileCreate, GitRepositoryImportHook, AvailableRepositoriesList, RevisionRetrieve, - MLToolList, CorpusWorkflow, WorkerList, WorkerVersionList + MLToolList, CorpusWorkflow, WorkerList, WorkerVersionList, WorkerVersionRetrieve ) from arkindex.images.api import ImageCreate, IIIFURLCreate, IIIFInformationCreate, ImageRetrieve, ImageElements from arkindex.users.api import ( @@ -129,6 +129,7 @@ api = [ # Workers path('imports/repos/<uuid:pk>/workers/', WorkerList.as_view(), name='repository-workers'), path('workers/<uuid:pk>/versions/', WorkerVersionList.as_view(), name='worker-versions'), + path('workers/versions/<uuid:pk>/', WorkerVersionRetrieve.as_view(), name='version-retrieve'), # Import workflows path('imports/', DataImportsList.as_view(), name='import-list'),