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 <fauzanfebriann@gmail.com>
pull/56737/head
Fauzan 2025-10-24 23:43:00 +07:00 committed by backportbot[bot]
parent 2043e0e140
commit 4b1477dd1b
2 changed files with 32 additions and 1 deletions

@ -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) {

@ -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<ShareAttribute>
const downloadAttribute = shareAttributes.find(({ scope, key }: ShareAttribute) => scope === 'permissions' && key === 'download')
if (downloadAttribute !== undefined) {
return downloadAttribute.value === true
}
}
return true
}