def post(): """Post a new user using the request body (which will contain a JWT). If the user already exists, update the name. """ token = g.jwt_oidc_token_info try: request_json = request.get_json(silent=True) # For BCeID users validate schema. if token.get('loginSource', None) == LoginSource.BCEID.value and request_json is not None: valid_format, errors = schema_utils.validate(request_json, 'user') if not valid_format: return {'message': schema_utils.serialize(errors)}, http_status.HTTP_400_BAD_REQUEST user = UserService.save_from_jwt_token(token, request_json) response, status = user.as_dict(), http_status.HTTP_201_CREATED # Add the user to public_users group if the user doesn't have public_user group if token.get('loginSource', '') != LoginSource.STAFF.value: KeycloakService.join_users_group(token) # For anonymous users, there are no invitation process for members, # so whenever they login perform this check and add them to corresponding groups if token.get('loginSource', '') == LoginSource.BCROS.value: if len(OrgService.get_orgs(user.identifier, [Status.ACTIVE.value])) > 0: KeycloakService.join_account_holders_group() except BusinessException as exception: response, status = {'code': exception.code, 'message': exception.message}, exception.status_code return response, status
def fetch_user_settings(user_id): """Create a new organization.""" current_app.logger.debug('<fetch_user_settings ') all_settings = [] url_origin = current_app.config.get('WEB_APP_URL') if user_id: all_orgs = OrgService.get_orgs(user_id) for org in all_orgs: all_settings.append( UserSettingsModel( org.id, org.name, url_origin, '/account/' + str(org.id) + '/settings', 'ACCOUNT', org.type_code, org.status_code, '/account/' + str(org.id) + '/restricted-product', org.branch_name # added as additonal label )) all_settings.append( UserSettingsModel(user_id, 'USER PROFILE', url_origin, '/userprofile', 'USER_PROFILE')) all_settings.append( UserSettingsModel(user_id, 'CREATE ACCOUNT', url_origin, '/setup-account', 'CREATE_ACCOUNT')) return all_settings
def post(): """Post a new user using the request body (which will contain a JWT). If the user already exists, update the name. """ token = g.jwt_oidc_token_info try: request_json = request.get_json(silent=True) # For BCeID users validate schema. if token.get('loginSource', None) == LoginSource.BCEID.value and request_json is not None: valid_format, errors = schema_utils.validate(request_json, 'user') if not valid_format: return {'message': schema_utils.serialize(errors)}, http_status.HTTP_400_BAD_REQUEST user = UserService.save_from_jwt_token(token, request_json) response, status = user.as_dict(), http_status.HTTP_201_CREATED # Add the user to public_users group if the user doesn't have public_user group KeycloakService.join_users_group(token) # If the user doesn't have account_holder role check if user is part of any orgs and add to the group if token.get('loginSource', '') in \ (LoginSource.BCSC.value, LoginSource.BCROS.value, LoginSource.BCEID.value) \ and Role.ACCOUNT_HOLDER.value not in token.get('roles', []) \ and len(OrgService.get_orgs(user.identifier, [Status.ACTIVE.value])) > 0: KeycloakService.join_account_holders_group() except BusinessException as exception: response, status = {'code': exception.code, 'message': exception.message}, exception.status_code return response, status
def get(): """Get a list of orgs that the current user is associated with.""" token = g.jwt_oidc_token_info try: user = UserService.find_by_jwt_token(token) if not user: response, status = {'message': 'User not found.'}, http_status.HTTP_404_NOT_FOUND else: all_orgs = OrgService.get_orgs(user.identifier) orgs = OrgSchema().dump( all_orgs, many=True) response, status = jsonify({'orgs': orgs}), http_status.HTTP_200_OK except BusinessException as exception: response, status = {'code': exception.code, 'message': exception.message}, exception.status_code return response, status
def fetch_user_settings(user_id): """Create a new organization.""" current_app.logger.debug('<fetch_user_settings ') all_orgs = OrgService.get_orgs(user_id) all_settings = [] url_origin = current_app.config.get('WEB_APP_URL') for org in all_orgs: all_settings.append( UserSettingsModel(org.id, org.name, url_origin, '/account/' + str(org.id) + '/settings', 'ACCOUNT')) all_settings.append( UserSettingsModel(user_id, 'USER PROFILE', url_origin, '/userprofile', 'USER_PROFILE')) all_settings.append( UserSettingsModel(user_id, 'CREATE ACCOUNT', url_origin, '/createaccount', 'CREATE_ACCOUNT')) return all_settings
def post(): """Post a new user using the request body (which will contain a JWT). If the user already exists, update the name. """ token = g.jwt_oidc_token_info try: user = UserService.save_from_jwt_token(token) response, status = user.as_dict(), http_status.HTTP_201_CREATED # Add the user to public_users group if the user doesn't have public_user group KeycloakService.join_users_group(g.jwt_oidc_token_info) # If the user doesn't have account_holder role check if user is part of any orgs and add to the group if token.get('loginSource', '') in (BCSC, BCROS) \ and Role.ACCOUNT_HOLDER.value not in token.get('roles', []) \ and len(OrgService.get_orgs(user.identifier, [Status.ACTIVE.value])) > 0: KeycloakService.join_account_holders_group() except BusinessException as exception: response, status = {'code': exception.code, 'message': exception.message}, exception.status_code return response, status
def get(): """Get a list of orgs that the current user is associated with.""" token = g.jwt_oidc_token_info try: user = UserService.find_by_jwt_token(token) if not user: response, status = {'message': 'User not found.'}, http_status.HTTP_404_NOT_FOUND else: # response, status = jsonify(user.get_orgs()), http_status.HTTP_200_OK all_orgs = OrgService.get_orgs(user.identifier) exclude_fields = [] # only approved users should see entities.. # TODO when endpoints are separated into afilliations endpoint, this logic can be removed if all_orgs: if all_orgs[0].members and all_orgs[0].members[0].status != Status.ACTIVE.value: exclude_fields.append('affiliated_entities') orgs = OrgSchema(exclude=exclude_fields).dump( all_orgs, many=True) response, status = jsonify({'orgs': orgs}), http_status.HTTP_200_OK except BusinessException as exception: response, status = {'code': exception.code, 'message': exception.message}, exception.status_code return response, status