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_send_staff_review_account_reminder_exception(session, notify_org_mock, keycloak_mock): # pylint:disable=unused-argument """Send a reminder with exception.""" user = factory_user_model_with_contact(TestUserInfo.user_test) org = OrgService.create_org(TestOrgInfo.org1, user_id=user.id) org_dictionary = org.as_dict() with patch.object(notification, 'send_email', return_value=False): with pytest.raises(BusinessException) as exception: OrgService.send_staff_review_account_reminder( user, org_dictionary['id'], 'localhost') assert exception.value.code == Error.FAILED_NOTIFICATION.name
def _modify_task(user): # 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 task_model: TaskModel = TaskModel.find_by_task_for_account( org.id, TaskStatus.HOLD.value) if task_model: task_type = TaskTypePrefix.NEW_ACCOUNT_STAFF_REVIEW.value task_info = { 'name': org.name, 'relationshipId': org.id, 'relatedTo': user.identifier, 'dateSubmitted': task_model.date_submitted, 'relationshipType': TaskRelationshipType.ORG.value, 'type': task_type, 'status': TaskStatus.OPEN.value, 'relationship_status': TaskRelationshipStatus.PENDING_STAFF_REVIEW.value } 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 OrgService.send_staff_review_account_reminder( relationship_id=org.id) remark = f'User Uploaded New affidavit .Created New task id: {new_task.identifier}' TaskService.close_task(task_model.id, remark)