From a2920dc7a9151a0b9c58034b590c11670c0f0450 Mon Sep 17 00:00:00 2001 From: Fauzan Date: Fri, 24 Oct 2025 23:43:00 +0700 Subject: [PATCH] fix(files_sharing): Hide 'Open locally' action This patch ensures that the "Open locally" context menu item is not displayed for files in a share where the "download and sync" permission has not been granted. This prevents user confusion, as the action would fail anyway. The fix adds a permission check before rendering the menu item, and adds a corresponding unit test to verify this behavior. Resolves: #54970 Signed-off-by: Fauzan --- apps/files/src/actions/openLocallyAction.ts | 2 +- apps/files/src/utils/permissions.ts | 31 +++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/apps/files/src/actions/openLocallyAction.ts b/apps/files/src/actions/openLocallyAction.ts index 986b304210c..3d6c00f1d59 100644 --- a/apps/files/src/actions/openLocallyAction.ts +++ b/apps/files/src/actions/openLocallyAction.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