Skip to content

SudoSOS Back-end API / rbac / RoleManager

Class: RoleManager ​

The role manager is responsible for the management of registered roles in the system, and performing access checks based on user roles and user access.

Constructors ​

Constructor ​

ts
new RoleManager(): RoleManager;

Returns ​

RoleManager

Methods ​

can() ​

ts
can(
   roles, 
   action, 
   relations, 
   entity, 
attributes): Promise<boolean>;

Performs an access check for the given parameters. This method can be used to verify if a user with the given role(s) is permitted to perform the given action (eg. create, read, update, delete) on the given properties of the given data entity, to which the user has the given relations.

Parameters ​

ParameterTypeDescription
rolesstring | string[]The role name or list of role names to perform the check for. If a single role is supplied as string, it is converted to a list.
actionstringThe action on the entity to check access for. Commonly used actions are 'create', 'read', 'update', and 'delete'.
relationsstring | string[]The ownership relations towards the object. The ownership relations describes the status of the user related to the object: the user can be the owner, creator, editor, or not related at all. Commonly used ownership relations are 'own', 'created' and 'all'.
entitystringThe entity type name of the object. Most often this is a database entity, but it could also be a computed entity such as 'balance'.
attributesstring[]The list of attributes to access. The wildcard '*' can be used to verify that the user is allowed to access all properties.

Returns ​

Promise<boolean>

  • True if access is allowed, false otherwise.

getRoles() ​

ts
getRoles(user, getPermissions?): Promise<Role[]>;

Get all role names for which the given user passes the assignment check.

Parameters ​

ParameterTypeDefault valueDescription
userUserundefinedThe user for which role checking is performed.
getPermissionsbooleanfalseWhether the permissions of each role should also be returned

Returns ​

Promise<Role[]>

a list of role names.


getUserOrgans() ​

ts
getUserOrgans(user): Promise<User[]>;

Returns all the ORGANS the user has rights over

Parameters ​

ParameterTypeDescription
userUser-

Returns ​

Promise<User[]>


initialize() ​

ts
initialize(): Promise<RoleManager>;

Returns ​

Promise<RoleManager>


setRoleUsers() ​

ts
setRoleUsers(users, roleName): Promise<AssignedRole & object[]>;

Sets (overwrites) all the assigned users of a role.

Parameters ​

ParameterTypeDescription
usersUser[]The users being set the role
roleNamestringThe role to set

Returns ​

Promise<AssignedRole & object[]>