Front-end access control
For each element of the user interface which is shown/hidden or enabled/disabled in the front-end based on an access control policy, a separate call is defined. These calls are subsequently bundled by the PermissionService, which is exported from @valtimo/access-control.
Defining permissions
For a part of your user interface, for example a page, it is best to define all the permissions it needs to request in one file. In this file, define each permission to be requested separately, conforming to the interface PermissionRequest:
sample.permissions.ts
sample.permissions.tsimport {PermissionRequest} from '@valtimo/access-control';
// Enums are defined for use in the below permissions. This is to avoid duplication, and is optional.
enum PERMISSION_ACTION {
assign = 'ASSIGN',
claim = 'CLAIM',
}
enum DOSSIER_DETAIL_PERMISSION_RESOURCE {
domain = 'com.ritense.document.domain.impl.JsonSchemaDocument',
}
const CAN_CLAIM_CASE_PERMISSION: PermissionRequest = {
action: PERMISSION_ACTION.claim,
resource: DOSSIER_DETAIL_PERMISSION_RESOURCE.domain,
};
const CAN_ASSIGN_CASE_PERMISSION: PermissionRequest = {
action: PERMISSION_ACTION.assign,
resource: DOSSIER_DETAIL_PERMISSION_RESOURCE.domain,
};
export {CAN_CLAIM_CASE_PERMISSION, CAN_ASSIGN_CASE_PERMISSION}Using permissions
Permissions defined in the above example, are imported into your component code and transferred to the PermissionService, which returns an Observable emitting a boolean value for the respective permission:
sample.component.ts
sample.component.tsWith each permission defined as an Observable emitting a boolean value, with its own component property, they may now be used in the template code of your component. To do this efficiently, it is recommended to use async pipes:
sample.component.html
sample.component.htmlLast updated