fix(files): Do not allow rename action on single-file-shares

Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
This commit is contained in:
Ferdinand Thiessen 2024-08-02 12:32:30 +02:00
parent 563f8e7c5d
commit ada6a61688
No known key found for this signature in database
GPG key ID: 45FAE7268762B400

View file

@ -3,7 +3,7 @@
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
import { emit } from '@nextcloud/event-bus'
import { Permission, type Node, FileAction } from '@nextcloud/files'
import { Permission, type Node, FileAction, View } from '@nextcloud/files'
import { translate as t } from '@nextcloud/l10n'
import PencilSvg from '@mdi/svg/svg/pencil.svg?raw'
@ -14,10 +14,16 @@ export const action = new FileAction({
displayName: () => t('files', 'Rename'),
iconSvgInline: () => PencilSvg,
enabled: (nodes: Node[]) => {
return nodes.length > 0 && nodes
.map(node => node.permissions)
.every(permission => Boolean(permission & Permission.DELETE))
enabled: (nodes: Node[], view: View) => {
if (nodes.length === 0) {
return false
}
// Disable for single file shares
if (view.id === 'public-file-share') {
return false
}
// Only enable if all nodes have the delete permission
return nodes.every((node) => Boolean(node.permissions & Permission.DELETE))
},
async exec(node: Node) {