Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show inherited acls #761

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 34 additions & 17 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 @@ -166,20 +165,38 @@ 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 aclsById = {};
let inheritedAclsById = {};
for ( let i in fileInfo.acl ) {
let acl = new Rule()
let acl = new Rule();
acl.fromValues(
fileInfo.acl[i].mappingType,
fileInfo.acl[i].mappingId,
fileInfo.acl[i].mappingDisplayName,
fileInfo.acl[i].mask,
fileInfo.acl[i].permissions,
)
acls.push(acl);
aclsById[acl.getUniqueMappingIdentifier()] = acl;
}
for ( let i in fileInfo.inheritedAcls ) {
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,
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
8 changes: 6 additions & 2 deletions src/components/AclStateButton.vue
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
<div v-else style="position: relative;" v-click-outside="popoverClose">
<button :disabled="disabled" @click="open = true" v-if="state === STATES.INHERIT_DENY" class="icon-deny inherited" v-tooltip="t('groupfolders', 'Denied (Inherited permission)')"></button>
<button :disabled="disabled" @click="open = true" v-else-if="state === STATES.INHERIT_ALLOW" class="icon-checkmark inherited" v-tooltip="t('groupfolders', 'Allowed (Inherited permission)')"></button>
<button :disabled="disabled" @click="open = true" v-else-if="state === STATES.SELF_DENY" class="icon-deny" v-tooltip="t('groupfolders', 'Denied')"></button>
<button :disabled="disabled" @click="open = true" v-else-if="state === STATES.SELF_ALLOW" class="icon-checkmark" v-tooltip="t('groupfolders', 'Allowed')"></button>
<button :disabled="disabled" @click="open = true" v-else-if="state === STATES.SELF_DENY" v-bind:class="'icon-deny' + (inherited ? ' inherited' : '')" v-tooltip="t('groupfolders', 'Denied')"></button>
<button :disabled="disabled" @click="open = true" v-else-if="state === STATES.SELF_ALLOW" v-bind:class="'icon-checkmark' + (inherited ? ' inherited' : '')" v-tooltip="t('groupfolders', 'Allowed')"></button>
<div class="popovermenu" :class="{open: open}"><PopoverMenu :menu="menu"></PopoverMenu></div>
</div>
</template>
Expand All @@ -47,6 +47,10 @@
name: 'AclStateButton',
components: {PopoverMenu},
props: {
inherited: {
type: Boolean,
default: false
},
state: {
type: Number,
default: STATES.INHERIT_DENY
Expand Down
14 changes: 13 additions & 1 deletion src/components/SharingSidebarView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -72,25 +72,30 @@
</td>
<td class="state-column">
<AclStateButton :state="getState(OC.PERMISSION_READ, item.permissions, item.mask)"
:inherited="item.inherited"
@update="changePermission(item, OC.PERMISSION_READ, $event)" :disabled="loading"/>
</td>
<td class="state-column">
<AclStateButton :state="getState(OC.PERMISSION_UPDATE, item.permissions, item.mask)"
:inherited="item.inherited"
@update="changePermission(item, OC.PERMISSION_UPDATE, $event)" :disabled="loading"/>
</td>
<td class="state-column" v-if="model.type === 'dir'">
<AclStateButton :state="getState(OC.PERMISSION_CREATE, item.permissions, item.mask)"
:inherited="item.inherited"
@update="changePermission(item, OC.PERMISSION_CREATE, $event)" :disabled="loading"/>
</td>
<td class="state-column">
<AclStateButton :state="getState(OC.PERMISSION_DELETE, item.permissions, item.mask)"
:inherited="item.inherited"
@update="changePermission(item, OC.PERMISSION_DELETE, $event)" :disabled="loading"/>
</td>
<td class="state-column">
<AclStateButton :state="getState(OC.PERMISSION_SHARE, item.permissions, item.mask)"
:inherited="item.inherited"
@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 +145,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 +235,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 +247,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 +259,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;
}
}