From 4c7c49b6ba0a682d799b57738f2b6e5ce67eb64a Mon Sep 17 00:00:00 2001 From: Miloslav Nenadal Date: Wed, 12 Feb 2020 13:04:29 +0100 Subject: [PATCH] Show inherited acls Signed-off-by: Miloslav Nenadal --- src/client.js | 48 ++++++++++++++++++++++++++++++++++-------------- 1 file changed, 34 insertions(+), 14 deletions(-) diff --git a/src/client.js b/src/client.js index 52225ed5a..42dcd99a7 100644 --- a/src/client.js +++ b/src/client.js @@ -140,21 +140,20 @@ client.addFileInfoParser(function(response) { data.aclCanManage = !!aclCanManage; } - var acls = props[ACL_PROPERTIES.PROPERTY_ACL_LIST]; - var inheritedAcls = props[ACL_PROPERTIES.PROPERTY_INHERITED_ACL_LIST]; + var acls = props[ACL_PROPERTIES.PROPERTY_ACL_LIST] || []; + var inheritedAcls = props[ACL_PROPERTIES.PROPERTY_INHERITED_ACL_LIST] || []; - if (!_.isUndefined(acls)) { - data.acl = parseAclList(acls); - data.inheritedAcls = parseAclList(inheritedAcls); + data.acl = parseAclList(acls); + data.inheritedAcls = parseAclList(inheritedAcls); + + data.acl.map((acl) => { + let inheritedAcl = data.inheritedAcls.find((inheritedAclRule) => inheritedAclRule.mappingType === acl.mappingType && inheritedAclRule.mappingId === acl.mappingId) + if (inheritedAcl) { + acl.permissions = (acl.permissions & acl.mask) | (inheritedAcl.permissions & ~acl.mask) + } + return acl; + }) - data.acl.map((acl) => { - let inheritedAcl = data.inheritedAcls.find((inheritedAclRule) => inheritedAclRule.mappingType === acl.mappingType && inheritedAclRule.mappingId === acl.mappingId) - if (inheritedAcl) { - acl.permissions = (acl.permissions & acl.mask) | (inheritedAcl.permissions & ~acl.mask) - } - return acl; - }) - } return data; }); patchClientForNestedPropPatch(client); @@ -167,8 +166,9 @@ class AclDavService { } ).then((status, fileInfo) => { if (fileInfo) { let acls = [] + let existingMappings = {}; for ( let i in fileInfo.acl ) { - let acl = new Rule() + let acl = new Rule(); acl.fromValues( fileInfo.acl[i].mappingType, fileInfo.acl[i].mappingId, @@ -177,6 +177,26 @@ class AclDavService { fileInfo.acl[i].permissions, ) acls.push(acl); + + if (existingMappings[fileInfo.acl[i].mappingType] == null) { + existingMappings[fileInfo.acl[i].mappingType] = new Set(); + } + existingMappings[fileInfo.acl[i].mappingType].add(fileInfo.acl[i].mappingId); + } + for ( let i in fileInfo.inheritedAcls ) { + if (existingMappings[fileInfo.inheritedAcls[i].mappingType] != null && existingMappings[fileInfo.inheritedAcls[i].mappingType].has(fileInfo.inheritedAcls[i].mappingId)) { + continue; + } + + let acl = new Rule(); + acl.fromValues( + fileInfo.inheritedAcls[i].mappingType, + fileInfo.inheritedAcls[i].mappingId, + fileInfo.inheritedAcls[i].mappingDisplayName, + fileInfo.inheritedAcls[i].mask, + fileInfo.inheritedAcls[i].permissions, + ) + acls.push(acl); } return { acls,