Skip to content

Commit

Permalink
Improve inherited acls ui
Browse files Browse the repository at this point in the history
- inherited acls cannot be removed
- if non inherited acl is removed, inherited acl takes it's place if any


Signed-off-by: Miloslav Nenadal <nenadalm@gmail.com>
  • Loading branch information
nenadalm committed Feb 18, 2020
1 parent 4c7c49b commit 6ad20ae
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 17 deletions.
27 changes: 12 additions & 15 deletions src/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,8 @@ class AclDavService {
properties: [ACL_PROPERTIES.PROPERTY_ACL_LIST, ACL_PROPERTIES.PROPERTY_INHERITED_ACL_LIST, ACL_PROPERTIES.GROUP_FOLDER_ID, ACL_PROPERTIES.PROPERTY_ACL_ENABLED, ACL_PROPERTIES.PROPERTY_ACL_CAN_MANAGE]
} ).then((status, fileInfo) => {
if (fileInfo) {
let acls = []
let existingMappings = {};
let aclsById = {};
let inheritedAclsById = {};
for ( let i in fileInfo.acl ) {
let acl = new Rule();
acl.fromValues(
Expand All @@ -176,30 +176,27 @@ class AclDavService {
fileInfo.acl[i].mask,
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);
aclsById[acl.getUniqueMappingIdentifier()] = acl;
}
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);
true
);
let id = acl.getUniqueMappingIdentifier();
inheritedAclsById[id] = acl;
if (aclsById[id] == null) {
aclsById[id] = acl;
}
}
return {
acls,
acls: Object.values(aclsById),
inheritedAclsById,
aclEnabled: fileInfo.aclEnabled,
aclCanManage: fileInfo.aclCanManage,
groupFolderId: fileInfo.groupFolderId
Expand Down
9 changes: 8 additions & 1 deletion src/components/SharingSidebarView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
<AclStateButton :state="getState(OC.PERMISSION_SHARE, item.permissions, item.mask)"
@update="changePermission(item, OC.PERMISSION_SHARE, $event)" :disabled="loading"/>
</td>
<td class="state-column"><a class="icon-close" v-tooltip="t('groupfolders', 'Remove access rule')"
<td class="state-column"><a v-if="item.inherited === false" class="icon-close" v-tooltip="t('groupfolders', 'Remove access rule')"
@click="removeAcl(item)"></a></td>
</tr>
</tbody>
Expand Down Expand Up @@ -140,6 +140,7 @@
if (data.acls) {
this.list = data.acls;
}
this.inheritedAclsById = data.inheritedAclsById;
this.aclEnabled = data.aclEnabled;
this.aclCanManage = data.aclCanManage;
this.groupFolderId = data.groupFolderId;
Expand Down Expand Up @@ -229,6 +230,10 @@
}
client.propPatch(this.model, list).then(() => {
this.list.splice(index, 1);
const inheritedAcl = this.inheritedAclsById[rule.getUniqueMappingIdentifier()];
if (inheritedAcl != null) {
this.list.splice(index, 0, inheritedAcl);
}
});

},
Expand All @@ -237,6 +242,7 @@
const inherit = ($event < 2);
const allow = ($event & (0b01)) === 1;
const bit = BinaryTools.firstHigh(permission);
item = item.clone();
if (inherit) {
item.mask = BinaryTools.clear(item.mask, bit)
// TODO check if: we can ignore permissions, since they are inherited
Expand All @@ -248,6 +254,7 @@
item.permissions = BinaryTools.clear(item.permissions, bit)
}
}
item.inherited = false;
Vue.set(this.list, index, item)
client.propPatch(this.model, this.list).then(() => {
// TODO block UI during save
Expand Down
12 changes: 11 additions & 1 deletion src/model/Rule.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,13 @@ export default class Rule {
this.permissions = props[PROPERTIES.PROPERTY_ACL_PERMISSIONS];
}

fromValues(mappingType, mappingId, mappingDisplayName, mask = 0, permissions = 31) {
fromValues(mappingType, mappingId, mappingDisplayName, mask = 0, permissions = 31, inherited = false) {
this.mappingType = mappingType;
this.mappingId = mappingId;
this.mappingDisplayName = mappingDisplayName;
this.mask = mask;
this.permissions = permissions;
this.inherited = inherited;
}

getProperties() {
Expand All @@ -56,4 +57,13 @@ export default class Rule {
return this.mappingType + ':' + this.mappingId;
}

clone() {
let rule = new Rule();
Object.getOwnPropertyNames(this)
.forEach(prop => {
rule[prop] = this[prop];
})

return rule;
}
}

0 comments on commit 6ad20ae

Please sign in to comment.