magpie.api.management.user.user_views¶
User Views, both for specific user-name provided as request path variable and special keyword for logged session user.
Attributes¶
Classes¶
Supported Webhook actions. |
|
Supported statuses of user-group relationships. |
|
Applicable types of Permission according to context. |
Functions¶
|
Checks the config for any webhooks that correspond to the input action, and prepares corresponding requests. |
|
Search in order for matched value of |
|
Obtains the formatted permission representations after validation that each of their name is a known member of |
|
Immediately sets the logger level to avoid duplicate log outputs from the root logger and this logger when |
|
List all registered user names or details. |
|
Create a new user. |
|
Update user information by user name. |
|
Get user information by name. |
|
Delete a user by name. |
|
List all groups a user belongs to. |
|
Assign a user to a group. |
|
Removes a user from a group. |
|
List all resources a user has permissions on. |
|
List all permissions a user has on a specific resource. |
Create a permission on specific resource for a user. |
|
Create or modify an existing permission on a resource for a user. |
|
Delete a permission from a specific resource for a user (not including his groups permissions). |
|
Delete a permission by name from a resource for a user (not including his groups permissions). |
|
|
List all services a user has permissions on. |
|
List all permissions a user has on a service. |
|
Create a permission on a service for a user. |
Create or modify an existing permission on a service for a user. |
|
|
Delete a permission from a service for a user (not including his groups permissions). |
Delete a permission by name from a service for a user (not including his groups permissions). |
|
|
List all resources under a service a user has permission on. |
Module Contents¶
- class magpie.api.management.user.user_views.WebhookAction[source]¶
Bases:
magpie.utils.ExtendedEnumSupported Webhook actions.
- UPDATE_USER_STATUS = 'update_user_status'¶
Triggered when an existing User status gets successfully updated.
See also
- CREATE_USER_PERMISSION = 'create_user_permission'¶
Triggered when a Permission onto a Service or Resource gets created for a User.
See also
- DELETE_USER_PERMISSION = 'delete_user_permission'¶
Triggered when a Permission onto a Service or Resource gets deleted for a User.
See also
- CREATE_GROUP_PERMISSION = 'create_group_permission'¶
Triggered when a Permission onto a Service or Resource gets created for a Group.
See also
- DELETE_GROUP_PERMISSION = 'delete_group_permission'¶
Triggered when a Permission onto a Service or Resource gets deleted for a Group.
See also
- magpie.api.management.user.user_views.process_webhook_requests(action: WebhookAction, params: magpie.typedefs.WebhookTemplateParameters, update_user_status_on_error: bool = False, settings: magpie.typedefs.AnySettingsContainer | None = None) None[source]¶
Checks the config for any webhooks that correspond to the input action, and prepares corresponding requests.
- Parameters:
action – tag identifying which webhooks to use in the config
params – Dictionary containing the required parameters and associated values for the request following the event action. Parameters will replace templates found in the
payloaddefinition of the webhook.update_user_status_on_error – update the user status or not in case of a webhook error.
settings – application settings where webhooks configuration can be retrieved.
- magpie.api.management.user.user_views.get_constant(constant_name: magpie.typedefs.Str, settings_container: magpie.typedefs.AnySettingsContainer | None = None, settings_name: magpie.typedefs.Str | None = None, default_value: magpie.typedefs.SettingValue | None = None, raise_not_set: bool = True, raise_missing: bool = True, print_missing: bool = False, empty_missing: bool = False) magpie.typedefs.SettingValue[source]¶
- Search in order for matched value of
constant_name: search in
MAGPIE_CONSTANTSsearch in settings if specified
search alternative setting names (see below)
search in
magpie.constantsdefinitionssearch in environment variables
Parameter
constant_nameis expected to have the formatMAGPIE_[VARIABLE_NAME]although any value can be passed to retrieve generic settings from all above-mentioned search locations.If
settings_nameis provided as alternative name, it is used as is to search for results ifconstant_namewas not found. Otherwise,magpie.[variable_name]is used for additional search when the formatMAGPIE_[VARIABLE_NAME]was used forconstant_name(i.e.:MAGPIE_ADMIN_USERwill also search formagpie.admin_userand so on for corresponding constants).- Parameters:
constant_name – key to search for a value
settings_container – WSGI application settings container (if not provided, uses found one in current thread)
settings_name – alternative name for settings if specified
default_value – default value to be returned if not found anywhere, and exception raises are disabled.
raise_not_set – raise an exception if the found key is
None, search until last case if others areNoneraise_missing – raise exception if key is not found anywhere
print_missing – print message if key is not found anywhere, return
Noneempty_missing – consider an empty value for an existing key as if it was missing (i.e.: as if not set).
- Returns:
found value or default_value
- Raises:
ValueError – if resulting value is invalid based on options (by default raise missing/empty/
Nonevalue)LookupError – if no appropriate value could be found from all search locations (according to options)
- Search in order for matched value of
- class magpie.api.management.user.user_views.UserGroupStatus[source]¶
Bases:
magpie.utils.FlexibleNameEnumSupported statuses of user-group relationships.
- ALL = 'all'¶
- ACTIVE = 'active'¶
- PENDING = 'pending'¶
- class magpie.api.management.user.user_views.PermissionType[source]¶
Bases:
magpie.utils.ExtendedEnumApplicable types of Permission according to context.
- ACCESS = 'access'¶
- ALLOWED = 'allowed'¶
- APPLIED = 'applied'¶
- DIRECT = 'direct'¶
- INHERITED = 'inherited'¶
- EFFECTIVE = 'effective'¶
- OWNED = 'owned'¶
- magpie.api.management.user.user_views.format_permissions(permissions: Collection[magpie.typedefs.AnyPermissionType] | None, permission_type: PermissionType | None = None, force_unique: bool = True) Dict[magpie.typedefs.Str, List[magpie.typedefs.Str] | magpie.typedefs.PermissionDict | magpie.typedefs.Str][source]¶
Obtains the formatted permission representations after validation that each of their name is a known member of
Permissionenum, and optionally with modifiers as defined byPermissionSet.The returned lists are sorted alphabetically by permission name, and then in order of resolution priority (from highest to lowest) for each subset or corresponding name.
The permissions are cleaned from any duplicate entries, unless
force_uniqueis specified to allow it. If no or emptypermissionsis provided, empty lists are returned.Note
Field
permission_namesprovides both the older implicit permission names and the newer explicit name representation. For this reason, there will be semantically “duplicate” permissions in that list, but there will not be any literal string duplicates. Implicit names are immediately followed by their explicit name, unless implicit names do not apply for the given permission (e.g.: whenAccess.DENYdid not exist). Only detailed and explicit JSON representations are provided in thepermissionslist.When
permission_typeis equal toPermissionType.ALLOWED, the collection of every applicablePermissionSetis automatically generated by expanding all combinations ofAccessandScopewith every providedPermissionname inpermissions. This allows more concise definition of allowed permissions undermagpie.services.Servicesand their children Resource by only definingPermissionnames without manually listing all variations ofPermissionSet.For other
permission_typevalues, which represent Applied Permission only explicitly providedpermissionsare returned, to effectively return the collection of active permissions.- Parameters:
permissions – multiple permissions of any implementation and type, to be rendered both as names and JSON.
permission_type – indication of the represented permissions to be formatted, for informative indication.
force_unique – whether to remove duplicate entries by association of name, access and scope or not.
- Returns:
JSON with the permissions listed as implicit+explicit names, as permission set objects, and their type.
- magpie.api.management.user.user_views.get_logger(name: magpie.typedefs.Str, level: int | None = None, force_stdout: bool = None, message_format: magpie.typedefs.Str | None = None, datetime_format: magpie.typedefs.Str | None = None) logging.Logger[source]¶
Immediately sets the logger level to avoid duplicate log outputs from the root logger and this logger when level is
logging.NOTSET.
- magpie.api.management.user.user_views.get_users_view(request)[source]¶
List all registered user names or details.
- magpie.api.management.user.user_views.update_user_view(request)[source]¶
Update user information by user name.
- magpie.api.management.user.user_views.get_user_groups_view(request)[source]¶
List all groups a user belongs to.
Groups can be filtered by status depending of input arguments.
- magpie.api.management.user.user_views.assign_user_group_view(request)[source]¶
Assign a user to a group.
- magpie.api.management.user.user_views.delete_user_group_view(request)[source]¶
Removes a user from a group.
- magpie.api.management.user.user_views.get_user_resources_view(request)[source]¶
List all resources a user has permissions on.
- magpie.api.management.user.user_views.get_user_resource_permissions_view(request)[source]¶
List all permissions a user has on a specific resource.
- magpie.api.management.user.user_views.create_user_resource_permissions_view(request)[source]¶
Create a permission on specific resource for a user.
- magpie.api.management.user.user_views.replace_user_resource_permissions_view(request)[source]¶
Create or modify an existing permission on a resource for a user.
Can be used to adjust permission modifiers.
- magpie.api.management.user.user_views.delete_user_resource_permissions_view(request)[source]¶
Delete a permission from a specific resource for a user (not including his groups permissions).
- magpie.api.management.user.user_views.delete_user_resource_permission_name_view(request)[source]¶
Delete a permission by name from a resource for a user (not including his groups permissions).
- magpie.api.management.user.user_views.get_user_services_view(request)[source]¶
List all services a user has permissions on.
- magpie.api.management.user.user_views.get_user_service_permissions_view(request)[source]¶
List all permissions a user has on a service.
- magpie.api.management.user.user_views.create_user_service_permissions_view(request)[source]¶
Create a permission on a service for a user.
- magpie.api.management.user.user_views.replace_user_service_permissions_view(request)[source]¶
Create or modify an existing permission on a service for a user.
Can be used to adjust permission modifiers.
- magpie.api.management.user.user_views.delete_user_service_permissions_view(request)[source]¶
Delete a permission from a service for a user (not including his groups permissions).