aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files/src/actions/moveOrCopyActionUtils.ts
diff options
context:
space:
mode:
Diffstat (limited to 'apps/files/src/actions/moveOrCopyActionUtils.ts')
-rw-r--r--apps/files/src/actions/moveOrCopyActionUtils.ts37
1 files changed, 25 insertions, 12 deletions
diff --git a/apps/files/src/actions/moveOrCopyActionUtils.ts b/apps/files/src/actions/moveOrCopyActionUtils.ts
index 511fd32d134..0372e8f4bc7 100644
--- a/apps/files/src/actions/moveOrCopyActionUtils.ts
+++ b/apps/files/src/actions/moveOrCopyActionUtils.ts
@@ -4,28 +4,31 @@
*/
import type { Folder, Node } from '@nextcloud/files'
+import type { ShareAttribute } from '../../../files_sharing/src/sharing'
+
import { Permission } from '@nextcloud/files'
+import { isPublicShare } from '@nextcloud/sharing/public'
import PQueue from 'p-queue'
+import { loadState } from '@nextcloud/initial-state'
+
+const sharePermissions = loadState<number>('files_sharing', 'sharePermissions', Permission.NONE)
// This is the processing queue. We only want to allow 3 concurrent requests
let queue: PQueue
+// Maximum number of concurrent operations
+const MAX_CONCURRENCY = 5
+
/**
* Get the processing queue
*/
export const getQueue = () => {
if (!queue) {
- queue = new PQueue({ concurrency: 3 })
+ queue = new PQueue({ concurrency: MAX_CONCURRENCY })
}
return queue
}
-type ShareAttribute = {
- enabled: boolean
- key: string
- scope: string
-}
-
export enum MoveCopyAction {
MOVE = 'Move',
COPY = 'Copy',
@@ -39,20 +42,30 @@ export type MoveCopyResult = {
export const canMove = (nodes: Node[]) => {
const minPermission = nodes.reduce((min, node) => Math.min(min, node.permissions), Permission.ALL)
- return (minPermission & Permission.UPDATE) !== 0
+ return Boolean(minPermission & Permission.DELETE)
}
export const canDownload = (nodes: Node[]) => {
return nodes.every(node => {
const shareAttributes = JSON.parse(node.attributes?.['share-attributes'] ?? '[]') as Array<ShareAttribute>
- return !shareAttributes.some(attribute => attribute.scope === 'permissions' && attribute.enabled === false && attribute.key === 'download')
+ return !shareAttributes.some(attribute => attribute.scope === 'permissions' && attribute.value === false && attribute.key === 'download')
})
}
export const canCopy = (nodes: Node[]) => {
// a shared file cannot be copied if the download is disabled
- // it can be copied if the user has at least read permissions
- return canDownload(nodes)
- && !nodes.some(node => node.permissions === Permission.NONE)
+ if (!canDownload(nodes)) {
+ return false
+ }
+ // it cannot be copied if the user has only view permissions
+ if (nodes.some((node) => node.permissions === Permission.NONE)) {
+ return false
+ }
+ // on public shares all files have the same permission so copy is only possible if write permission is granted
+ if (isPublicShare()) {
+ return Boolean(sharePermissions & Permission.CREATE)
+ }
+ // otherwise permission is granted
+ return true
}