Beispiel #1
0
def get_user_setting(user_id: int, resource: str):
    """
    HTTP `GET`/`HEAD` route for a single user setting resource.

    Args:
        user_id (int): Public ID of the user.
        resource (str): Identifier/Name of the user setting.

    Raises:
        ManagerGetError: When the selected user setting does not exists.

    Notes:
        Calling the route over HTTP HEAD method will result in an empty body.

    Returns:
        GetSingleResponse: Which includes the json data of a UserSettingModel.
    """
    settings_manager = UserSettingsManager(
        database_manager=current_app.database_manager)
    try:
        setting: UserSettingModel = settings_manager.get_user_setting(
            user_id, resource)
        api_response = GetSingleResponse(UserSettingModel.to_dict(setting),
                                         url=request.url,
                                         model=UserSettingModel.MODEL,
                                         body=request.method == 'HEAD')
    except ManagerGetError as err:
        return abort(404, err.message)
    return api_response.make_response()
def get_category(public_id: int):
    """
    HTTP `GET`/`HEAD` route for a single category resource.

    Args:
        public_id (int): Public ID of the category.

    Raises:
        ManagerGetError: When the selected category does not exists.

    Returns:
        GetSingleResponse: Which includes the json data of a CategoryModel.
    """
    category_manager: CategoryManager = CategoryManager(
        database_manager=current_app.database_manager)
    body = True if not request.method != 'HEAD' else False

    try:
        category_instance = category_manager.get(public_id)
    except ManagerGetError as err:
        return abort(404, err.message)
    api_response = GetSingleResponse(CategoryModel.to_json(category_instance),
                                     url=request.url,
                                     model=CategoryModel.MODEL,
                                     body=body)
    return api_response.make_response()
Beispiel #3
0
def get_group(public_id: int):
    """
    HTTP `GET`/`HEAD` route for a single group resource.

    Args:
        public_id (int): Public ID of the group.

    Raises:
        ManagerGetError: When the selected group does not exists.

    Notes:
        Calling the route over HTTP HEAD method will result in an empty body.

    Returns:
        GetSingleResponse: Which includes the json data of a UserGroupModel.
    """
    group_manager: GroupManager = GroupManager(database_manager=current_app.database_manager,
                                               right_manager=RightManager(rights))
    try:
        group = group_manager.get(public_id)
    except ManagerGetError as err:
        return abort(404, err.message)
    api_response = GetSingleResponse(UserGroupModel.to_dict(group), url=request.url,
                                     model=UserGroupModel.MODEL, body=request.method == 'HEAD')
    return api_response.make_response()
Beispiel #4
0
def get_right(name: str):
    """
    HTTP `GET`/`HEAD` route for a single right resource.

    Args:
        name (str): Name of the right.

    Raises:
        ManagerGetError: When the selected right does not exists.

    Notes:
        Calling the route over HTTP HEAD method will result in an empty body.

    Returns:
        GetSingleResponse: Which includes the json data of a BaseRight.
    """
    right_manager: RightManager = RightManager(right_tree)

    try:
        right = right_manager.get(name)
    except ManagerGetError as err:
        return abort(404, err.message)
    api_response = GetSingleResponse(BaseRight.to_dict(right), url=request.url, model=Model('Right'),
                                     body=request.method == 'HEAD')
    return api_response.make_response()
def get_type(public_id: int):
    """
    HTTP `GET`/`HEAD` route for a single type resource.

    Args:
        public_id (int): Public ID of the type.

    Raises:
        ManagerGetError: When the selected type does not exists.

    Returns:
        GetSingleResponse: Which includes the json data of a TypeModel.
    """
    type_manager = TypeManager(database_manager=current_app.database_manager)
    body = request.method == 'HEAD'

    try:
        type_ = type_manager.get(public_id)
    except ManagerGetError as err:
        return abort(404, err.message)
    api_response = GetSingleResponse(TypeModel.to_json(type_),
                                     url=request.url,
                                     model=TypeModel.MODEL,
                                     body=body)
    return api_response.make_response()
Beispiel #6
0
def get_user(public_id: int):
    """
    HTTP `GET`/`HEAD` route for a single user resource.

    Args:
        public_id (int): Public ID user.

    Raises:
        ManagerGetError: When the selected user does not exists.

    Notes:
        Calling the route over HTTP HEAD method will result in an empty body.

    Returns:
        GetSingleResponse: Which includes the json data of a UserModel.
    """
    user_manager: UserManager = UserManager(
        database_manager=current_app.database_manager)

    try:
        user: UserModel = user_manager.get(public_id)
    except ManagerGetError as err:
        return abort(404, err.message)
    api_response = GetSingleResponse(UserModel.to_dict(user),
                                     url=request.url,
                                     model=UserModel.MODEL,
                                     body=request.method == 'HEAD')
    return api_response.make_response()
Beispiel #7
0
def get_levels():
    """
    HTTP `GET`/`HEAD` route for a static collection of levels.

    Returns:
        GetSingleResponse: Which includes a levels as enum.

    Notes:
        Calling the route over HTTP HEAD method will result in an empty body.
    """

    api_response = GetSingleResponse(_nameToLevel, url=request.url, model=Model('Security-Level'),
                                     body=request.method == 'HEAD')
    return api_response.make_response()
Beispiel #8
0
def get_link(public_id: int, request_user: UserModel):
    link_manager = ObjectLinkManager(
        database_manager=current_app.database_manager)
    body = request.method == 'HEAD'
    try:
        link = link_manager.get(public_id=public_id,
                                user=request_user,
                                permission=AccessControlPermission.READ)
    except ManagerGetError as err:
        return abort(404, err.message)
    except AccessDeniedError as err:
        return abort(403, err.message)
    api_response = GetSingleResponse(ObjectLinkModel.to_json(link),
                                     url=request.url,
                                     model=ObjectLinkModel.MODEL,
                                     body=body)
    return api_response.make_response()