[ADF-5148] ContentService.hasPermissions() should check inhertied permission (#7059)

* [ADF-5148] ContentService.hasPermissions() should check inherited permission

* * fixed permission method
This commit is contained in:
Dharan
2021-06-01 14:15:59 +05:30
committed by GitHub
parent e94b2f99bd
commit 1a0f2f5bcc
2 changed files with 29 additions and 14 deletions

View File

@@ -152,16 +152,20 @@ export class ContentService {
* Checks if the user has permission on that node
* @param node Node to check permissions
* @param permission Required permission type
* @param userId Optional current user id will be taken by default
* @returns True if the user has the required permissions, false otherwise
*/
hasPermissions(node: Node, permission: PermissionsEnum | string): boolean {
hasPermissions(node: Node, permission: PermissionsEnum | string, userId?: string): boolean {
let hasPermissions = false;
userId = userId ?? this.authService.getEcmUsername();
if (node && node.permissions && node.permissions.locallySet) {
const permissions = [ ...(node.permissions?.locallySet || []), ...(node.permissions?.inherited || []) ]
.filter((currentPermission) => currentPermission.authorityId === userId);
if (permissions.length) {
if (permission && permission.startsWith('!')) {
hasPermissions = node.permissions.locallySet.find((currentPermission) => currentPermission.name === permission.replace('!', '')) ? false : true;
hasPermissions = permissions.find((currentPermission) => currentPermission.name === permission.replace('!', '')) ? false : true;
} else {
hasPermissions = node.permissions.locallySet.find((currentPermission) => currentPermission.name === permission) ? true : false;
hasPermissions = permissions.find((currentPermission) => currentPermission.name === permission) ? true : false;
}
} else {