packages/core/src/lib/services/permission/permission.service.ts
Service for managing user permissions within the application.
This class extends EuiService and is responsible for handling user rights and permissions.
It provides methods to initialize the service with user rights, check specific rights and permissions,
and subscribe to changes in the user rights state.
See EuiService
Example :// Example of using the EuiPermissionService in an application
const permissionService = new EuiPermissionService();
permissionService.init([{ id: 'ADMIN', permissions: ['CREATE', 'READ', 'UPDATE', 'DELETE'] }]);
if (permissionService.checkRight('ADMIN')) {
console.log('User has ADMIN rights');
}
EuiService
Methods |
constructor()
|
| checkAttributePermission | ||||||||
checkAttributePermission(rightsAndPermission: string)
|
||||||||
|
Checks if the user has the specified attribute permission. This method interprets a string that represents a combination of rights and/or permissions and determines whether the user has the specified permissions. The string format can be 'RIGHT.PERMISSION' or just 'RIGHT'. For multiple rights, it can be 'RIGHT1.RIGHT2.PERMISSION'. Example :// Check a right with a specific permission const hasRightWithPermission = permissionService.checkAttributePermission('EDIT.APPROVE'); // Check multiple rights with a specific permission const hasMultipleRights = permissionService.checkAttributePermission('ADMIN.VIEW.APPROVE');
Parameters :
Returns :
boolean
True if the user has the specified attribute permission, false otherwise. |
| checkPermission | ||||||||||||
checkPermission(rightId: string, permission: string)
|
||||||||||||
|
Checks if the user has a specific permission within a right. This method determines whether the user has a specific permission associated with a given right. Example :
Parameters :
Returns :
boolean
True if the user has the specified permission in the given right, false otherwise. |
| checkRight | ||||||||
checkRight(rightId: string)
|
||||||||
|
Checks if the user has a specific right. This method determines whether the user possesses a particular right identified by its ID. Example :
Parameters :
Returns :
boolean
True if the user has the specified right, false otherwise. |
| init | ||||||||
init(rights: EuiUserRight[])
|
||||||||
|
Initializes the permission service with a set of user rights. This method sets up the initial state of the service based on the provided user rights. It should be called before using other methods of the service to ensure it is properly configured. Example :
Parameters :
Returns :
Observable<EuiServiceStatus>
An Observable that emits the status of the initialization.
The status object includes a |
| updateState | ||||||||
updateState(rights: EuiUserRight[])
|
||||||||
|
Updates the state of the service with a new set of user rights.
This method is used to modify the current user rights in the service. It takes an array of
Parameters :
Returns :
void
|