Skip to content

Commit

Permalink
restore acl ui in sharing tab
Browse files Browse the repository at this point in the history
Signed-off-by: Robin Appelman <robin@icewind.nl>
  • Loading branch information
icewind1991 committed Jan 10, 2024
1 parent 2fb1bae commit 193ccb3
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 38 deletions.
84 changes: 47 additions & 37 deletions src/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
import ACL_PROPERTIES from './model/Properties.js'
import Rule from './model/Rule.js'

/**
* @member {OC.Files.Client} client
*/
let client

const XML_CHAR_MAP = {
Expand Down Expand Up @@ -137,53 +140,60 @@ const parseAclList = (acls) => {
return list
}

/** @type OC.Plugin */
const FilesPlugin = {
attach(fileList) {
client = fileList.filesClient
client.addFileInfoParser((response) => {
const data = {}
const props = response.propStat[0].properties
const groupFolderId = props[ACL_PROPERTIES.GROUP_FOLDER_ID]
if (typeof groupFolderId !== 'undefined') {
data.groupFolderId = groupFolderId
}
const aclEnabled = props[ACL_PROPERTIES.PROPERTY_ACL_ENABLED]
if (typeof aclEnabled !== 'undefined') {
data.aclEnabled = !!aclEnabled
}
/**
*
* @param {OC.Files.Client} filesClient files dav client
*/
export function initFilesClient(filesClient) {
client = filesClient
patchFilesClient(filesClient)
}

const aclCanManage = props[ACL_PROPERTIES.PROPERTY_ACL_CAN_MANAGE]
if (typeof aclCanManage !== 'undefined') {
data.aclCanManage = !!aclCanManage
}
/**
*
* @param {OC.Files.Client} client files dav client
*/
function patchFilesClient(client) {
client.addFileInfoParser((response) => {
const data = {}
const props = response.propStat[0].properties
const groupFolderId = props[ACL_PROPERTIES.GROUP_FOLDER_ID]
if (typeof groupFolderId !== 'undefined') {
data.groupFolderId = groupFolderId
}
const aclEnabled = props[ACL_PROPERTIES.PROPERTY_ACL_ENABLED]
if (typeof aclEnabled !== 'undefined') {
data.aclEnabled = !!aclEnabled
}

const acls = props[ACL_PROPERTIES.PROPERTY_ACL_LIST] || []
const inheritedAcls = props[ACL_PROPERTIES.PROPERTY_INHERITED_ACL_LIST] || []
const aclCanManage = props[ACL_PROPERTIES.PROPERTY_ACL_CAN_MANAGE]
if (typeof aclCanManage !== 'undefined') {
data.aclCanManage = !!aclCanManage
}

data.acl = parseAclList(acls)
data.inheritedAcls = parseAclList(inheritedAcls)
const acls = props[ACL_PROPERTIES.PROPERTY_ACL_LIST] || []
const inheritedAcls = props[ACL_PROPERTIES.PROPERTY_INHERITED_ACL_LIST] || []

data.acl.map((acl) => {
const 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
data.acl = parseAclList(acls)
data.inheritedAcls = parseAclList(inheritedAcls)

data.acl.map((acl) => {
const 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)
},
};
patchClientForNestedPropPatch(client)
}

(function(OC) {
Object.assign(OC.Files.Client, ACL_PROPERTIES)
})(window.OC)

OC.Plugins.register('OCA.Files.FileList', FilesPlugin)

class AclDavService {

propFind(model) {
Expand Down Expand Up @@ -212,7 +222,7 @@ class AclDavService {
fileInfo.inheritedAcls[i].mappingDisplayName,
fileInfo.inheritedAcls[i].mask,
fileInfo.inheritedAcls[i].permissions,
true
true,
)
const id = acl.getUniqueMappingIdentifier()
inheritedAclsById[id] = acl
Expand Down
3 changes: 2 additions & 1 deletion src/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
*
*/
import { generateUrl, imagePath } from '@nextcloud/router'
import './client.js'
import { initFilesClient } from './client.js'

// eslint-disable-next-line
__webpack_nonce__ = btoa(OC.requestToken)
Expand All @@ -38,6 +38,7 @@ window.addEventListener('DOMContentLoaded', () => {
return
}
import(/* webpackChunkName: "sharing" */'./SharingSidebarApp.js').then((Module) => {
initFilesClient(OC.Files.getClient())
OCA.Sharing.ShareTabSections.registerSection((el, fileInfo) => {
if (fileInfo.mountType !== 'group') {
return
Expand Down

0 comments on commit 193ccb3

Please sign in to comment.