magpie.api.management.user.user_utils

Module Contents

magpie.api.management.user.user_utils.create_user(user_name, password, email, group_name, db_session) → HTTPException[source]

Creates a user if it is permitted and not conflicting. Password must be set to None if using external identity.

Created user will be part of group matching group_name (can be MAGPIE_ANONYMOUS_GROUP for minimal access). Furthermore, the user will also always be associated with MAGPIE_ANONYMOUS_GROUP (if not already explicitly requested with group_name) to allow access to resources with public permission. The group_name must be an existing group.

Returns:valid HTTP response on successful operation.
magpie.api.management.user.user_utils.create_user_resource_permission_response(user, resource, permission, db_session) → HTTPException[source]

Creates a permission on a user/resource combination if it is permitted and not conflicting.

Returns:valid HTTP response on successful operation.
magpie.api.management.user.user_utils.delete_user_resource_permission_response(user, resource, permission, db_session) → HTTPException[source]

Get validated response on deleted user resource permission.

Returns:valid HTTP response on successful operations.
Raises:HTTPException – error HTTP response of corresponding situation.
magpie.api.management.user.user_utils.get_resource_root_service(resource, request) → ServiceInterface[source]

Retrieves the service class corresponding to the specified resource’s root service-resource.

magpie.api.management.user.user_utils.filter_user_permission(resource_permission_list, user) → Iterable[ResourcePermissionType][source]

Retrieves only direct user permissions on resources amongst a list of user/group resource/service permissions.

magpie.api.management.user.user_utils.get_user_resource_permissions_response(user, resource, request, inherit_groups_permissions=True, effective_permissions=False) → HTTPException[source]

Retrieves user resource permissions with or without inherited group permissions. Alternatively retrieves the effective user resource permissions, where group permissions are implied as True.

Returns:valid HTTP response on successful operations.
Raises:HTTPException – error HTTP response of corresponding situation.
magpie.api.management.user.user_utils.get_user_services(user, request, cascade_resources=False, inherit_groups_permissions=False, format_as_list=False) → UserServicesType[source]

Returns services by type with corresponding services by name containing sub-dict information.

Parameters:
  • user – user for which to find services
  • request – request with database session connection
  • cascade_resources – If False, return only services with Direct user permissions on their corresponding service-resource. Otherwise, return every service that has at least one sub-resource with user permissions.
  • inherit_groups_permissions – If False, return only user-specific service/sub-resources permissions. Otherwise, resolve inherited permissions using all groups the user is member of.
  • format_as_list – returns as list of service dict information (not grouped by type and by name)
Returns:

only services which the user as Direct or Inherited permissions, according to inherit_from_resources

Return type:

dict of services by type with corresponding services by name containing sub-dict information, unless format_as_list is True

magpie.api.management.user.user_utils.get_user_service_permissions(user, service, request, inherit_groups_permissions=True) → List[Permission][source]
magpie.api.management.user.user_utils.get_user_resources_permissions_dict(user, request, resource_types=None, resource_ids=None, inherit_groups_permissions=True) → Dict[Str, Any][source]

Creates a dictionary of resources by id with corresponding permissions of the user.

Parameters:
  • user – user for which to find services
  • request – request with database session connection
  • resource_types – filter the search query with specified resource types
  • resource_ids – filter the search query with specified resource ids
  • inherit_groups_permissions – If False, return only user-specific resource permissions. Otherwise, resolve inherited permissions using all groups the user is member of.
Returns:

only services which the user as Direct or Inherited permissions, according to inherit_from_resources

magpie.api.management.user.user_utils.get_user_service_resources_permissions_dict(user, service, request, inherit_groups_permissions=True) → Dict[Str, Any][source]
magpie.api.management.user.user_utils.check_user_info(user_name, email, password, group_name) → None[source]
magpie.api.management.user.user_utils.get_user_groups_checked(request, user) → List[Str][source]