Esempio n. 1
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()
Esempio n. 2
0
 def to_dict(cls, instance: "UserGroupModel") -> dict:
     return {
         'public_id': instance.public_id,
         'name': instance.name,
         'label': instance.label,
         'rights': [BaseRight.to_dict(right) for right in instance.rights]
     }
Esempio n. 3
0
def get_rights(params: CollectionParameters):
    """
    HTTP `GET`/`HEAD` route for getting a iterable collection of resources.

    Args:
        params (CollectionParameters): Passed parameters over the http query string

    Returns:
        GetMultiResponse: Which includes a IterationResult of the BaseRight.

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

    Raises:
        ManagerIterationError: If the collection could not be iterated.
        ManagerGetError: If the collection/resources could not be found.
    """
    right_manager = RightManager(right_tree)
    body = request.method == 'HEAD'

    try:
        if params.optional['view'] == 'tree':
            api_response = GetMultiResponse(
                right_manager.tree_to_json(right_tree),
                total=len(right_tree),
                params=params,
                url=request.url,
                model='Right-Tree',
                body=body)
            return api_response.make_response(pagination=False)
        else:
            iteration_result: IterationResult[
                BaseRight] = right_manager.iterate(filter=params.filter,
                                                   limit=params.limit,
                                                   skip=params.skip,
                                                   sort=params.sort,
                                                   order=params.order)
            rights = [
                BaseRight.to_dict(type) for type in iteration_result.results
            ]
            api_response = GetMultiResponse(rights,
                                            total=iteration_result.total,
                                            params=params,
                                            url=request.url,
                                            model=Model('Right'),
                                            body=request.method == 'HEAD')
            return api_response.make_response()
    except ManagerIterationError as err:
        return abort(400, err.message)
    except ManagerGetError as err:
        return abort(404, err.message)
Esempio n. 4
0
                                      description='Manage exportd logs'),
                      (ExportdLogRight('view',
                                       description='View exportd logs'),
                       ExportdLogRight('reload',
                                       Levels.SECURE,
                                       description='Reload exportd logs'),
                       ExportdLogRight('delete',
                                       Levels.DANGER,
                                       description='Delete exportd logs'))))

DOCAPI_RIGHTS = (DocapiRight(
    GLOBAL_RIGHT_IDENTIFIER, description='Manage DocAPI'), (
        DocapiTemplateRight(GLOBAL_RIGHT_IDENTIFIER,
                            description='Manage DocAPI templates'),
        (
            DocapiTemplateRight('view', description='View template'),
            DocapiTemplateRight('add', description='Add template'),
            DocapiTemplateRight('edit',
                                Levels.SECURE,
                                description='Edit template'),
            DocapiTemplateRight('delete',
                                Levels.SECURE,
                                description='Delete template'),
        ),
    ))
__all__ = (BaseRight(Levels.NOTSET,
                     GLOBAL_RIGHT_IDENTIFIER,
                     description='Base application right'), SYSTEM_RIGHTS,
           FRAMEWORK_RIGHTS, EXPORT_RIGHTS, IMPORT_RIGHTS,
           USER_MANAGEMENT_RIGHTS, EXPORTD_RIGHTS, DOCAPI_RIGHTS)