diff --git a/apps/files/src/actions/editLocallyAction.ts b/apps/files/src/actions/editLocallyAction.ts index d100297184b..a874bda86c7 100644 --- a/apps/files/src/actions/editLocallyAction.ts +++ b/apps/files/src/actions/editLocallyAction.ts @@ -30,7 +30,7 @@ export const action = new FileAction({ return false } - return (nodes[0].permissions & Permission.UPDATE) !== 0 + return isSyncable(nodes[0]) }, async exec(node: Node) { diff --git a/apps/files/src/utils/permissions.ts b/apps/files/src/utils/permissions.ts index 9b4c42bf49c..a13f6a13ab5 100644 --- a/apps/files/src/utils/permissions.ts +++ b/apps/files/src/utils/permissions.ts @@ -35,3 +35,34 @@ export function isDownloadable(node: Node): boolean { return true } + + +/** + * Check permissions on the node if it can be synced/open locally + * + * @param node The node to check + * @return True if syncable, false otherwise + */ +export function isSyncable(node: Node): boolean { + if ((node.permissions & Permission.UPDATE) === 0) { + return false + } + + // check hide-download property of shares + if (node.attributes['hide-download'] === true + || node.attributes['hide-download'] === 'true' + ) { + return false + } + + // If the mount type is a share, ensure it got download permissions. + if (node.attributes['share-attributes']) { + const shareAttributes = JSON.parse(node.attributes['share-attributes'] || '[]') as Array + const downloadAttribute = shareAttributes.find(({ scope, key }: ShareAttribute) => scope === 'permissions' && key === 'download') + if (downloadAttribute !== undefined) { + return downloadAttribute.value === true + } + } + + return true +} \ No newline at end of file