Skip to content

Commit

Permalink
Fix draft project transfers
Browse files Browse the repository at this point in the history
  • Loading branch information
noliveleger committed Mar 19, 2024
1 parent 9e239d7 commit 834ec51
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
17 changes: 12 additions & 5 deletions kobo/apps/project_ownership/models/transfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand All @@ -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
Expand Down Expand Up @@ -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')
Expand Down
11 changes: 11 additions & 0 deletions kobo/apps/project_ownership/tests/test_transfer_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 834ec51

Please sign in to comment.