AllOf class
Bases: RoleTraitsFilter
Select traits depending on whether all user roles belong to the filter or not.
Available in Taipy Enterprise only
This class exists only in the Enterprise edition of Taipy.
AllOf
is a role traits filter that recursively selects role traits
depending on the user roles: get_traits()
returns the success value
if the credentials hold all the filter roles and failure if they do not.
Example
You can create an AllOf
role traits filter with the following code:
my_filter = AllOf(["role1", "role2"], "All roles are present")
Let's pretend that a user is identified by the credentials instance
of Credentials
.
- If the credentials hold the role "role1" only, but do not hold "role2", then
my_filter.get_traits(credentials)
returns None, which is the default value for the failure case. - If the credentials hold the roles "role1" and "role2" and potentially any other
roles, then
my_filter.get_traits(credentials)
returns the string "All roles are present", which is the value that was set for the success case.
Methods¶
__init__() ¶
__init__(
filters: Union[str, List[str], Set[str]],
success: Optional[Union[RoleTraits, Any]],
failure: Optional[Union[RoleTraits, Any]] = None,
) -> None
Initialize an All Role Traits filter.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filters |
Union[str, List[str], Set[str]]
|
The role or set of roles to filter. |
required |
success |
Optional[Union[RoleTraits, Any]]
|
The role traits that are returned if all of the user roles appear in filters or if filters is empty. |
required |
failure |
Optional[Union[RoleTraits, Any]]
|
The role traits that are returned if not all of the user roles appear in filters or if the user has no roles. |
None
|
get_traits() ¶
get_traits(credentials: Optional[Credentials]) -> Any
Return the role traits for the indicated credentials.
This method is recursive: role traits filters (see AnyOf
, AllOf
or
NoneOf
) can hold both a role traits value, that the application can use
in its logic, or a RoleTraits
instance. In this latter case, this role
traits filter is processed for further role traits selection.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
credentials |
Optional[Credentials]
|
The credentials that are used to compute the roles traits. |
required |
Returns:
Name | Type | Description |
---|---|---|
Any |
Any
|
The role traits corresponding to the roles held in credentials. |