From 834ec518a9487dcfacd51e2476f1ad6fafda041c Mon Sep 17 00:00:00 2001 From: Olivier Leger Date: Tue, 19 Mar 2024 09:52:33 -0400 Subject: [PATCH] Fix draft project transfers --- kobo/apps/project_ownership/models/transfer.py | 17 ++++++++++++----- .../tests/test_transfer_status.py | 11 +++++++++++ 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/kobo/apps/project_ownership/models/transfer.py b/kobo/apps/project_ownership/models/transfer.py index 7dd391edcb..3e45cebb8e 100644 --- a/kobo/apps/project_ownership/models/transfer.py +++ b/kobo/apps/project_ownership/models/transfer.py @@ -102,9 +102,16 @@ def transfer_project(self): if not self.asset.has_deployment: with transaction.atomic(): self._reassign_project_permissions(update_deployment=False) - self._sent_app_in_messages() - # FIXME - Draft stay in queue forever - # Set async tasks to done for submissions and attachments. + self._sent_in_app_messages() + # Draft projects do not have submissions or attachments to + # sync, set them to success right away + status_types = [ + TransferStatusTypeChoices.SUBMISSIONS, + TransferStatusTypeChoices.ATTACHMENTS, + ] + self.statuses.filter(status_type__in=status_types).update( + status=TransferStatusChoices.SUCCESS + ) else: with transaction.atomic(): with kc_transaction_atomic(): @@ -120,7 +127,7 @@ def transfer_project(self): ) deployment.rename_enketo_id_key(previous_owner_username) - self._sent_app_in_messages() + self._sent_in_app_messages() # Move submissions, media files and attachments in background # tasks because it can take a while to complete on big projects @@ -204,7 +211,7 @@ def _reassign_project_permissions(self, update_deployment: bool = False): self.invite.sender, PERM_MANAGE_ASSET ) - def _sent_app_in_messages(self): + def _sent_in_app_messages(self): # Use translatable strings here to let Transifex detect them but … title = t('Project ownership transferred') diff --git a/kobo/apps/project_ownership/tests/test_transfer_status.py b/kobo/apps/project_ownership/tests/test_transfer_status.py index d173e983dd..11985bdc2c 100644 --- a/kobo/apps/project_ownership/tests/test_transfer_status.py +++ b/kobo/apps/project_ownership/tests/test_transfer_status.py @@ -103,3 +103,14 @@ def test_calculated_failed_transfer_status(self): # Same as the invite self.invite.refresh_from_db() assert self.invite.status == InviteStatusChoices.FAILED + + def test_draft_project_transfer(self): + # when project is a draft, there are no celery tasks called to move + # submissions (and related attachments). + self.transfer.transfer_project() + assert self.transfer.status == TransferStatusChoices.SUCCESS + + # However, the status of each async task should still be updated to + # 'success'. + for transfer_status in self.transfer.statuses.all(): + assert transfer_status.status == TransferStatusChoices.SUCCESS