def _update_org(is_approved: bool, org_id: int, origin_url: str = None, task_action: str = None): """Approve/Reject Affidavit and Org.""" from auth_api.services import Org as OrgService # pylint:disable=cyclic-import, import-outside-toplevel current_app.logger.debug('<update_task_org ') OrgService.approve_or_reject(org_id=org_id, is_approved=is_approved, origin_url=origin_url, task_action=task_action) current_app.logger.debug('>update_task_org ')
def patch(org_id): """Patch an account.""" request_json = request.get_json() # For now allowed is to put the status code, which will be done by bcol_staff_admin. # If this patch is going to be used by other other roles, then add proper security check try: status_code = request_json.get('statusCode', None) suspension_reason_code = request_json.get('suspensionReasonCode', None) if status_code in (OrgStatusEnum.SUSPENDED.value, OrgStatusEnum.ACTIVE.value): if not _jwt.validate_roles([Role.STAFF_SUSPEND_ACCOUNTS.value]): return {'message': 'Not authorized to perform this action'}, \ http_status.HTTP_401_UNAUTHORIZED response, status = OrgService.change_org_status(org_id=org_id, status_code=status_code, suspension_reason_code=suspension_reason_code ).as_dict(), http_status.HTTP_200_OK else: is_approved: bool = request_json.get('statusCode', None) == AffidavitStatus.APPROVED.value origin = request.environ.get('HTTP_ORIGIN', 'localhost') response, status = OrgService.approve_or_reject(org_id=org_id, is_approved=is_approved, origin_url=origin).as_dict(), http_status.HTTP_200_OK except BusinessException as exception: response, status = {'code': exception.code, 'message': exception.message}, exception.status_code return response, status
def test_create_org_by_rejected_bceid_user(session, keycloak_mock, monkeypatch): # pylint:disable=unused-argument """Assert that an Org can be created.""" # Steps # 1. Create a pending affidavit # 2. Create org # 3. Reject Org, which will mark the affidavit as rejected # 4. Same user create new org, which should be PENDING_STAFF_REVIEW. user = factory_user_model_with_contact() token_info = TestJwtClaims.get_test_user(sub=user.keycloak_guid, source=LoginSource.BCEID.value) monkeypatch.setattr('auth_api.utils.user_context._get_token_info', lambda: token_info) affidavit_info = TestAffidavit.get_test_affidavit_with_contact() AffidavitService.create_affidavit(token_info=token_info, affidavit_info=affidavit_info) with patch.object(OrgService, 'send_staff_review_account_reminder', return_value=None) as mock_notify: org = OrgService.create_org(TestOrgInfo.org_with_mailing_address(), user_id=user.id) org_dict = org.as_dict() assert org_dict['org_status'] == OrgStatus.PENDING_STAFF_REVIEW.value org = OrgService.approve_or_reject(org_dict['id'], is_approved=False, token_info=token_info) org_dict = org.as_dict() assert org_dict['org_status'] == OrgStatus.REJECTED.value org = OrgService.create_org(TestOrgInfo.org_with_mailing_address(name='Test 123'), user_id=user.id) org_dict = org.as_dict() assert org_dict['org_status'] == OrgStatus.PENDING_STAFF_REVIEW.value mock_notify.assert_called()
def test_reject_org(session, keycloak_mock): # pylint:disable=unused-argument """Assert that an Affidavit can be rejected.""" user = factory_user_model_with_contact() token_info = TestJwtClaims.get_test_user(sub=user.keycloak_guid, source=LoginSource.BCEID.value) affidavit_info = TestAffidavit.get_test_affidavit_with_contact() AffidavitService.create_affidavit(token_info=token_info, affidavit_info=affidavit_info) org = OrgService.create_org(TestOrgInfo.org_with_mailing_address(), user_id=user.id, token_info=token_info) org_dict = org.as_dict() assert org_dict['org_status'] == OrgStatus.PENDING_STAFF_REVIEW.value org = OrgService.approve_or_reject(org_dict['id'], is_approved=False, token_info=token_info) org_dict = org.as_dict() assert org_dict['org_status'] == OrgStatus.REJECTED.value affidavit = AffidavitService.find_affidavit_by_org_id(org_dict['id']) assert affidavit['status'] == AffidavitStatus.REJECTED.value
def test_approve_org(session, keycloak_mock, monkeypatch): # pylint:disable=unused-argument """Assert that an Affidavit can be approved.""" user = factory_user_model_with_contact() token_info = TestJwtClaims.get_test_user(sub=user.keycloak_guid, source=LoginSource.BCEID.value) affidavit_info = TestAffidavit.get_test_affidavit_with_contact() AffidavitService.create_affidavit(token_info=token_info, affidavit_info=affidavit_info) monkeypatch.setattr('auth_api.utils.user_context._get_token_info', lambda: token_info) org = OrgService.create_org(TestOrgInfo.org_with_mailing_address(), user_id=user.id) org_dict = org.as_dict() assert org_dict['org_status'] == OrgStatus.PENDING_STAFF_REVIEW.value org = OrgService.approve_or_reject(org_dict['id'], is_approved=True, token_info=token_info) org_dict = org.as_dict() assert org_dict['org_status'] == OrgStatus.ACTIVE.value affidavit = AffidavitService.find_affidavit_by_org_id(org_dict['id']) assert affidavit['status'] == AffidavitStatus.APPROVED.value
def patch(org_id): """Patch an account.""" request_json = request.get_json() token = g.jwt_oidc_token_info # For now allowed is to put the status code, which will be done by bcol_staff_admin. # If this patch is going to be used by other other roles, then add proper security check try: is_approved: bool = request_json.get( 'statusCode', None) == AffidavitStatus.APPROVED.value origin = request.environ.get('HTTP_ORIGIN', 'localhost') response, status = OrgService.approve_or_reject( org_id=org_id, is_approved=is_approved, token_info=token, origin_url=origin).as_dict(), http_status.HTTP_200_OK except BusinessException as exception: response, status = { 'code': exception.code, 'message': exception.message }, exception.status_code return response, status