Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions core/collections/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1575,6 +1575,7 @@ def persist(cls, index, **kwargs):
temp_version = not bool(expansion.mnemonic)
if temp_version:
expansion.mnemonic = generate_temp_version()
expansion.is_processing = True
expansion.clean()
expansion.full_clean()
expansion.save()
Expand Down Expand Up @@ -1635,6 +1636,14 @@ def update_diffs(rel):

return diff

def clear_processing(self, full_save=False):
if self.is_processing:
self.is_processing = False
if full_save:
self.save()
else:
self.save(update_fields=['is_processing'])


class ExpansionParameters:
ACTIVE = 'activeOnly'
Expand Down
5 changes: 5 additions & 0 deletions core/collections/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,11 @@
views.CollectionVersionExpansionView.as_view(),
name='collection-version-expansion-detail'
),
path(
'<str:collection>/<str:version>/expansions/<str:expansion>/processing/',
views.CollectionVersionExpansionProcessingView.as_view(),
name='collection-version-expansion-processing'
),
path(
'<str:collection>/<str:version>/expansions/<str:expansion>/resolved-repo-updates/',
views.CollectionVersionExpansionResolvedRepoUpdatesView.as_view(),
Expand Down
22 changes: 21 additions & 1 deletion core/collections/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
ConceptContainerProcessingMixin)
from core.common.permissions import (
CanViewConceptDictionary, CanEditConceptDictionary, HasAccessToVersionedObject,
CanViewConceptDictionaryVersion
CanViewConceptDictionaryVersion, HasOwnership
)
from core.common.serializers import TaskSerializer
from core.common.swagger_parameters import q_param, compress_header, page_param, verbose_param, \
Expand Down Expand Up @@ -1308,3 +1308,23 @@ def get_results(self):
)
def post(self, _):
return Response(self.get_results(), status=status.HTTP_200_OK)


class CollectionVersionExpansionProcessingView(CollectionVersionExpansionBaseView):
def get_permissions(self):
if self.request.method == 'POST':
return [HasOwnership(), IsAuthenticated()]

return [CanViewConceptDictionary(), ]

def get(self, request, *args, **kwargs): # pylint: disable=unused-argument
expansion = self.get_object()
response = Response(status=200)
response.content = expansion.is_processing
return response

def post(self, request, *args, **kwargs): # pylint: disable=unused-argument
expansion = self.get_object()
expansion.clear_processing()

return Response(status=status.HTTP_200_OK)
4 changes: 1 addition & 3 deletions core/common/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -431,9 +431,7 @@ def seed_children_to_expansion(expansion_id, index=True, force_reevaluate=False)
expansion = Expansion.objects.filter(id=expansion_id).first()
if expansion:
expansion.seed_children(index=index, force_reevaluate=force_reevaluate)
if expansion.is_processing:
expansion.is_processing = False
expansion.save()
expansion.clear_processing(True)


@app.task
Expand Down
50 changes: 50 additions & 0 deletions core/integration_tests/tests_collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -4094,6 +4094,56 @@ def test_get(self):
self.assertEqual([expansion['mnemonic'] for expansion in response.data], ['e2-head', 'e1-v1', 'e1-head'])


class CollectionVersionExpansionProcessingViewTest(OCLAPITestCase):
def setUp(self):
super().setUp()
self.collection = OrganizationCollectionFactory()
self.expansion = ExpansionFactory(collection_version=self.collection)
self.token = self.collection.created_by.get_token()

def test_get_200(self):
response = self.client.get(
self.expansion.url + 'processing/',
HTTP_AUTHORIZATION=f'Token {self.token}'
)

self.assertEqual(response.status_code, 200)
self.assertEqual(response.content, b'False')

self.expansion.is_processing = True
self.expansion.save(update_fields=['is_processing'])

response = self.client.get(
self.expansion.url + 'processing/',
HTTP_AUTHORIZATION=f'Token {self.token}'
)

self.assertEqual(response.status_code, 200)
self.assertEqual(response.content, b'True')

def test_post_200(self):
self.expansion.is_processing = True
self.expansion.save(update_fields=['is_processing'])

response = self.client.post(
self.expansion.url + 'processing/',
HTTP_AUTHORIZATION=f'Token {self.token}'
)

self.assertEqual(response.status_code, 200)
self.expansion.refresh_from_db()
self.assertFalse(self.expansion.is_processing)

response = self.client.post(
self.expansion.url + 'processing/',
HTTP_AUTHORIZATION=f'Token {self.token}'
)

self.assertEqual(response.status_code, 200)
self.expansion.refresh_from_db()
self.assertFalse(self.expansion.is_processing)


class CollectionVersionExpansionResolvedRepoUpdatesViewTest(OCLAPITestCase):
def setUp(self):
super().setUp()
Expand Down