proknow.Roles
– Roles¶
-
class
proknow.Roles.
Roles
(proknow, requestor)¶ This class should be used to interact with the roles in a ProKnow organization. It is instantiated for you as an attribute of the
proknow.ProKnow.ProKnow
class.-
__init__
(proknow, requestor)¶ Initializes the Roles class.
Parameters: - proknow (proknow.ProKnow.ProKnow) – The ProKnow instance that is instantiating the object.
- requestor (proknow.Requestor.Requestor) – An object used to make API requests.
-
create
(name, permissions)¶ Creates a new role.
Parameters: - name (str) – The name of the role.
- permissions (dict) – A dictionary of permissions.
Returns: A representation of the created item.
Return type: Raises: AssertionError
– If the input parameters are invalid.
-
delete
(identifier)¶ Deletes a role.
Parameters: identifier (str) – The id of the role to delete. Raises: AssertionError
– If the input parameters are invalid.
-
find
(**kwargs)¶ Finds a role by id or name.
Parameters: **kwargs – A dictionary of keyword arguments that may include identifier and name. These arguments are considered—in that order—to find matching roles. Returns: A representation of the matching role. Return type: proknow.Roles.RoleItem
-
get
(identifier)¶ Gets a role.
Parameters: identifier (str) – The id of the role to get. Returns: an object representing a role in the organization Return type: proknow.Roles.RoleItem
-
query
()¶ Queries for roles.
Returns: A list of proknow.Roles.RoleSummary
objects, each representing a summarized role in the organization.Return type: list
-
-
class
proknow.Roles.
RoleSummary
(roles, role)¶ This class represents a summary view of a role. It’s instantiated by the
proknow.Roles.Roles.query()
method to represent each of the roles returned in a query result.-
id
¶ str – The id of the role (readonly).
-
name
¶ str – The name of the role (readonly).
-
data
¶ dict – The summary representation of the role as returned from the API (readonly).
-
__init__
(roles, role)¶ Initializes the RoleSummary class.
Parameters: - roles (proknow.Roles.Roles) – The Role instance that is instantiating the object.
- role (dict) – A dictionary of role attributes.
-
get
()¶ Gets the complete representation of the role.
Returns: an object representing a role in the organization Return type: proknow.Roles.RoleItem
-
-
class
proknow.Roles.
RoleItem
(roles, role)¶ This class represents a role. It’s instantiated by the
proknow.Roles.Roles
class as a complete representation of a role.-
id
¶ str – The id of the role (readonly).
-
data
¶ dict – The complete representation of the role as returned from the API (readonly).
-
name
¶ str – The name of the role.
-
permissions
¶ dict – The dictionary of role permissions.
-
__init__
(roles, role)¶ Initializes the RoleItem class.
Parameters: - roles (proknow.Roles.Roles) – The Role instance that is instantiating the object.
- role (dict) – A dictionary of role attributes.
-
delete
()¶ Deletes the role.
-
save
()¶ Saves the changes made to a role.
Example
The following example illustrates how to find a role by its slug, modify a permission, and save it:
pk = ProKnow('https://example.proknow.com', credentials_file="./credentials.json") researchers = pk.roles.find(name='researchers') researchers.permissions["organization_read"] = True researchers.save()
-