magpie.api.management.resource.resource_formats

Module Contents

Functions

format_resource(→ magpie.typedefs.JSON)

Formats a Resource information into JSON.

format_resource_tree(→ magpie.typedefs.JSON)

Generates the formatted resource tree under the provided nested resources.

format_resources_listed(→ List[magpie.typedefs.JSON])

Obtains the formatted Resource list with their applicable permissions.

format_resources_nested(→ magpie.typedefs.JSON)

Obtains the formatted Resource tree with all its formatted children hierarchy.

magpie.api.management.resource.resource_formats.format_resource(resource: magpie.models.Resource, permissions: Collection[magpie.typedefs.AnyPermissionType] | None = None, permission_type: magpie.permissions.PermissionType | None = None, basic_info: bool = False, dotted: bool = False) magpie.typedefs.JSON[source]

Formats a Resource information into JSON.

Parameters:
  • resourceResource to be formatted.

  • permissions – Permissions to list along with the resource. By default, these are the applicable permissions for that corresponding resource type.

  • permission_type – Override indication of provenance to apply to permissions. Only applicable when they are provided.

  • basic_info – If True, return only sufficient details to identify the resource, without any additional permissions detail, nor hierarchical resource information is returned.

  • dotted – Employ a dot (.) instead of underscore (_) to separate Resource from its basic information.

magpie.api.management.resource.resource_formats.format_resource_tree(nested_resources: magpie.typedefs.NestedResourceNodes, db_session: sqlalchemy.orm.session.Session, resources_perms_dict: magpie.typedefs.ResourcePermissionMap | None = None, permission_type: magpie.permissions.PermissionType | None = None, nesting_key: magpie.typedefs.NestingKeyType = 'children') magpie.typedefs.JSON[source]

Generates the formatted resource tree under the provided nested resources.

For all of the nested resources, formatting is applied by calling format_resource() recursively on them. Apply specific resource permissions as defined by resources_perms_dict if provided.

Parameters:
  • nested_resources – Service or resource for which to generate the formatted resource tree.

  • db_session – Connection to database.

  • resources_perms_dict – Any pre-established Applied Permission to set to corresponding resources by ID. When provided, these will define the User, Group or both (i.e.: Inherited Permissions) actual permissions, or even the Effective Permissions, according to parent caller function’s context. Otherwise (None), defaults to extracting Allowed Permissions for the given Resource scoped under the corresponding root Service.

  • permission_type – Override Permission type to indicate its provenance. Type is applied recursively for all resources in the generated nested resource tree.

  • nesting_key – Key to employ for nesting the formatted sub-tree resources according to the provided nested resources.

Returns:

Formatted nested resource tree with their details and permissions.

magpie.api.management.resource.resource_formats.format_resources_listed(resources: List[magpie.typedefs.ServiceOrResourceType], db_session: sqlalchemy.orm.session.Session) List[magpie.typedefs.JSON][source]

Obtains the formatted Resource list with their applicable permissions.

magpie.api.management.resource.resource_formats.format_resources_nested(resource: magpie.typedefs.ServiceOrResourceType, nested_resources: magpie.typedefs.NestedResourceNodes, nesting_key: magpie.typedefs.NestingKeyType, db_session: sqlalchemy.orm.session.Session) magpie.typedefs.JSON[source]

Obtains the formatted Resource tree with all its formatted children hierarchy.