Skip to content

Commit

Permalink
Show inherited acls
Browse files Browse the repository at this point in the history
Signed-off-by: Miloslav Nenadal <nenadalm@gmail.com>
  • Loading branch information
nenadalm committed Feb 12, 2020
1 parent a4f5099 commit 4c7c49b
Showing 1 changed file with 34 additions and 14 deletions.
48 changes: 34 additions & 14 deletions src/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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,
Expand All @@ -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,
Expand Down

0 comments on commit 4c7c49b

Please sign in to comment.