import { Injectable } from "@angular/core" ; import { Entity , EntityConstructor } from "../entity/model/entity" ; import { SessionService } from "../session/session-service/session.service" ; import { EntityConfigService } from "../entity/entity-config.service" ; export enum OperationType { CREATE = "create" , READ = "read" , UPDATE = "update" , DELETE = "delete" } @ Injectable ( { providedIn : "root" , } ) export class EntityPermissionsService { constructor ( private entityConfigService , private sessionService ) { } param entity param operation public userIsPermitted ( entity , operation ) { const currentUser = this . sessionService . getCurrentUser ( ) ; const entityConfig = this . entityConfigService . getEntityConfig ( entity ) ; if ( entityConfig ?. permissions && entityConfig . permissions [ operation ] ) { return entityConfig . permissions [ operation ] . some ( ( role ) => currentUser . roles . includes ( role ) ) ; } return true ; } }