Skip to main content
has_role(principal=, role=None, options=)[source]

Checks if the specified user has the specified role.

Parameters

principal (str) –

Name of the user for which role membership is being checked. Must be an existing user. If blank, will use the current user. The default value is ‘’.

role (str) –

Name of role to check for membership.

options (dict of str to str) –

Optional parameters. Allowed keys are:

  • no_error_if_not_exists – If false will return an error if the provided input parameter role does not exist or is blank. If true then it will return false for output parameter has_role. Allowed values are:

    • true

    • false

    The default value is ‘false’.

  • only_direct – If false will search recursively if the input parameter principal is a member of input parameter role. If true then input parameter principal must directly be a member of input parameter role. Allowed values are:

    • true

    • false

    The default value is ‘false’.

The default value is an empty dict ( ).

Returns

A dict with the following entries–

principal (str) –

Value of input parameter principal.

role (str) –

Input parameter role for which membership is being checked.

has_role (bool) –

Indicates whether the specified user has membership in the specified target input parameter role. Allowed values are:

  • True – User has membership in the role.

  • False – User does not have membership in the role.

info (dict of str to str) –

Additional information. Allowed keys are:

  • directtrue when principal is directly a member of the role. Allowed values are:

    • true

    • false

    The default value is ‘false’.

The default value is an empty dict ( ).