magpie.api.management.user.user_formats¶
Classes¶
Supported statuses of user-group relationships. |
|
Values applicable to User statues. |
Functions¶
|
Evaluates the specified |
|
Search in order for matched value of |
|
Formats a User information into JSON. |
Module Contents¶
- magpie.api.management.user.user_formats.evaluate_call(call: Callable[[], Any], fallback: Callable[[], None] | None = None, http_error: Type[pyramid.httpexceptions.HTTPError] = HTTPInternalServerError, http_kwargs: magpie.typedefs.ParamsType | None = None, msg_on_fail: magpie.typedefs.Str = '', content: magpie.typedefs.JSON | None = None, content_type: magpie.typedefs.Str = CONTENT_TYPE_JSON, metadata: magpie.typedefs.JSON | None = None) Any[source]¶
Evaluates the specified
callwith a wrapped HTTP exception handling. On failure, tries to call.fallbackif specified, and finally raises the specifiedhttp_error.Any potential error generated by
fallbackorhttp_errorthemselves are treated asHTTPInternalServerError.Exceptions are generated using the standard output method formatted based on specified
content_type.- Example:
normal call:
try: res = func(args) except Exception as exc: fb_func() raise HTTPExcept(exc.message)
wrapped call:
res = evaluate_call(lambda: func(args), fallback=lambda: fb_func(), http_error=HTTPExcept, **kwargs)
- Parameters:
call – function to call, MUST be specified as lambda: <function_call>
fallback – function to call (if any) when call failed, MUST be lambda: <function_call>
http_error – alternative exception to raise on call failure
http_kwargs – additional keyword arguments to pass to http_error if called in case of HTTP exception
msg_on_fail – message details to return in HTTP exception if call failed
content – json formatted additional content to provide in case of exception
content_type – format in which to return the exception (one of magpie.common.SUPPORTED_ACCEPT_TYPES)
metadata – request metadata to add to the response body. (see:
magpie.api.requests.get_request_info())
- Raises:
http_error – on call failure
HTTPInternalServerError – on fallback failure
- Returns:
whichever return value call might have if no exception occurred
- magpie.api.management.user.user_formats.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_formats.UserGroupStatus[source]¶
Bases:
magpie.utils.FlexibleNameEnumSupported statuses of user-group relationships.
- ALL = 'all'¶
- ACTIVE = 'active'¶
- PENDING = 'pending'¶
- class magpie.api.management.user.user_formats.UserStatuses[source]¶
Bases:
enum.IntFlag,magpie.utils.FlexibleNameEnumValues applicable to User statues.
Provides allowed values for the
statussearch query ofUserandUserPendingentries. Also, defines the possible values ofUser.statusfield, omittingUserStatuses.Pendingreserved for objects defined byUserPending.Initialize self. See help(type(self)) for accurate signature.
- OK = 1¶
- WebhookError = 2¶
- Pending = 4¶
- classmethod _get_one(status: AnyUserStatus) UserStatuses | None[source]¶
- classmethod get(status: None | int | magpie.typedefs.Str | UserStatuses | Iterable[None, int, magpie.typedefs.Str, UserStatuses], default: UserStatuses | None = None) UserStatuses | None[source]¶
Obtains the combined flag
UserStatuses
- classmethod allowed() List[None | int | magpie.typedefs.Str][source]¶
Returns all supported representation values that can be mapped to a valid status for
UserSearchService.
- classmethod all() UserStatuses[source]¶
Representation of all flags combined.
- __or__(other: UserStatuses | int) UserStatuses[source]¶
Return self|value.
- __and__(other: UserStatuses | int) UserStatuses[source]¶
Return self&value.
- __xor__(other: UserStatuses | int) UserStatuses[source]¶
Return self^value.
- __iter__() Iterable[UserStatuses][source]¶
- magpie.api.management.user.user_formats.format_user(user: magpie.models.AnyUser, group_names: List[magpie.typedefs.Str] = None, basic_info: bool = False, dotted: bool = False) magpie.typedefs.JSON[source]¶
Formats a User information into JSON.
- Parameters:
user – User to be formatted.
group_names – Override of group name listing to provide as user memberships. Retrieve the complete group membership listing from the
userif not provided.basic_info – If
True, return only sufficient details to identify the User, without any additional group details.dotted – Employ a dot (
.) instead of underscore (_) to separate User from its basic information.