Пример #1
0
    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
Пример #2
0
    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
Пример #3
0
    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