def send_staff_review_account_reminder( relationship_id, task_relationship_type=TaskRelationshipType.ORG.value): """Send staff review account reminder notification.""" current_app.logger.debug('<send_staff_review_account_reminder') user: UserModel = UserModel.find_by_jwt_token() recipient = current_app.config.get('STAFF_ADMIN_EMAIL') # Get task id that is related with the task. Task Relationship Type can be ORG, PRODUCT etc. task = TaskModel.find_by_task_relationship_id( task_relationship_type=task_relationship_type, relationship_id=relationship_id) context_path = f'review-account/{task.id}' app_url = f"{g.get('origin_url', '')}/{current_app.config.get('AUTH_WEB_TOKEN_CONFIRM_PATH')}" review_url = f'{app_url}/{context_path}' first_name = user.firstname last_name = user.lastname data = { 'emailAddresses': recipient, 'contextUrl': review_url, 'userFirstName': first_name, 'userLastName': last_name } try: publish_to_mailer('staffReviewAccount', org_id=relationship_id, data=data) current_app.logger.debug('<send_staff_review_account_reminder') except Exception as e: # noqa=B901 current_app.logger.error( '<send_staff_review_account_reminder failed') raise BusinessException(Error.FAILED_NOTIFICATION, None) from e
def test_finding_task_by_relationship_id(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.ORG.value, relationship_id=10, type=TaskTypePrefix.NEW_ACCOUNT_STAFF_REVIEW.value, status=TaskStatus.OPEN.value, related_to=user.id, relationship_status=TaskRelationshipStatus.PENDING_STAFF_REVIEW.value) task.save() found_task = TaskModel.find_by_task_relationship_id( task_relationship_type=TaskRelationshipType.ORG.value, relationship_id=10) assert found_task assert found_task.name == 'TEST 1' assert found_task.relationship_id == 10 assert found_task.status == TaskStatus.OPEN.value