aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files/src/utils/permissions.ts
diff options
context:
space:
mode:
Diffstat (limited to 'apps/files/src/utils/permissions.ts')
-rw-r--r--apps/files/src/utils/permissions.ts37
1 files changed, 37 insertions, 0 deletions
diff --git a/apps/files/src/utils/permissions.ts b/apps/files/src/utils/permissions.ts
new file mode 100644
index 00000000000..9b4c42bf49c
--- /dev/null
+++ b/apps/files/src/utils/permissions.ts
@@ -0,0 +1,37 @@
+/*!
+ * 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
+}