def _modify_task(user): """Clone on-hold task to a new active task; handle user-based and org-based tasks.""" # find users org. ideally only one org org_list = MembershipModel.find_orgs_for_user(user.identifier) org: OrgModel = next(iter(org_list or []), None) if org: # check if there is any holding tasks # Find if the corresponding task is NEW_ACCOUNT_STAFF_REVIEW / GOVN type, clone and close it task_model: TaskModel = TaskModel.find_by_task_for_account( org.id, TaskStatus.HOLD.value) if task_model is None: # Else, find if there are any associated task of BCEID_ADMIN type, clone and close it task_model: TaskModel = TaskModel.find_by_user_and_status( org.id, TaskStatus.HOLD.value) if task_model: task_info = { 'name': org.name, 'relationshipId': task_model.relationship_id, 'relatedTo': user.identifier, 'dateSubmitted': task_model.date_submitted, 'relationshipType': task_model.relationship_type, 'type': task_model.type, 'action': task_model.action, 'status': TaskStatus.OPEN.value, 'relationship_status': TaskRelationshipStatus.PENDING_STAFF_REVIEW.value, 'account_id': task_model.account_id } new_task = TaskService.create_task(task_info=task_info, do_commit=False) # Send notification mail to staff review task from auth_api.services import Org as OrgService # pylint:disable=cyclic-import, import-outside-toplevel if task_model.relationship_type == TaskRelationshipType.USER.value: OrgService.send_staff_review_account_reminder( relationship_id=user.identifier, task_relationship_type=TaskRelationshipType.USER.value) else: OrgService.send_staff_review_account_reminder( relationship_id=org.id) remarks = [ f'User Uploaded New affidavit .Created New task id: {new_task.identifier}' ] TaskService.close_task(task_model.id, remarks)
def test_find_by_task_for_user(session): # pylint:disable=unused-argument """Assert that we can fetch all tasks.""" user = factory_user_model() task = TaskModel( name='TEST 1', date_submitted=datetime.now(), relationship_type=TaskRelationshipType.USER.value, relationship_id=user.id, type=TaskTypePrefix.BCEID_ADMIN.value, status=TaskStatus.OPEN.value, related_to=user.id, account_id=10, relationship_status=TaskRelationshipStatus.PENDING_STAFF_REVIEW.value) task.save() found_task = TaskModel.find_by_user_and_status( org_id=10, status=TaskStatus.OPEN.value) assert found_task assert found_task.name == 'TEST 1' assert found_task.relationship_id == user.id assert found_task.status == TaskStatus.OPEN.value