nextcloud/apps/files/src/utils/permissions.ts
John Molakvoæ 7b53dacfdd fix(files): use isDownloadable for isSyncable
Signed-off-by: John Molakvoæ <skjnldsv@users.noreply.github.com>

[skip ci]
2025-11-28 09:55:01 +01:00

56 lines
1.6 KiB
TypeScript

/*!
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
import type { Node } from '@nextcloud/files'
import type { ShareAttribute } from '../../../files_sharing/src/sharing.ts'
import { Permission } from '@nextcloud/files'
/**
* Check permissions on the node if it can be downloaded
* @param node The node to check
* @return True if downloadable, false otherwise
*/
export function isDownloadable(node: Node): boolean {
if ((node.permissions & Permission.READ) === 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
}
/**
* 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.isDavResource) {
return false
}
if ((node.permissions & Permission.UPDATE) === 0) {
return false
}
// Syncable has the same permissions as downloadable for now
return isDownloadable(node)
}