Skip to content

Commit 0d8eb39

Browse files
authored
Merge pull request #53916 from nextcloud/backport/53855/stable31
[stable31] fix: hide rename action in trashbin
2 parents 02eb875 + 740c803 commit 0d8eb39

File tree

7 files changed

+44
-17
lines changed

7 files changed

+44
-17
lines changed

apps/files/src/actions/renameAction.spec.ts

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,23 @@
33
* SPDX-License-Identifier: AGPL-3.0-or-later
44
*/
55
import { action } from './renameAction'
6-
import { File, Permission, View, FileAction } from '@nextcloud/files'
6+
import { File, Folder, Permission, View, FileAction } from '@nextcloud/files'
77
import * as eventBus from '@nextcloud/event-bus'
8-
import { describe, expect, test, vi } from 'vitest'
8+
import { describe, expect, test, vi, beforeEach } from 'vitest'
9+
import { useFilesStore } from '../store/files'
10+
import { getPinia } from '../store/index.ts'
911

1012
const view = {
1113
id: 'files',
1214
name: 'Files',
1315
} as View
1416

17+
beforeEach(() => {
18+
const root = new Folder({ owner: 'test', source: 'https://cloud.domain.com/remote.php/dav/files/admin/', id: 1, permissions: Permission.CREATE })
19+
const files = useFilesStore(getPinia())
20+
files.setRoot({ service: 'files', root })
21+
})
22+
1523
describe('Rename action conditions tests', () => {
1624
test('Default values', () => {
1725
expect(action).toBeInstanceOf(FileAction)
@@ -26,7 +34,7 @@ describe('Rename action conditions tests', () => {
2634
describe('Rename action enabled tests', () => {
2735
test('Enabled for node with UPDATE permission', () => {
2836
const file = new File({
29-
id: 1,
37+
id: 2,
3038
source: 'https://cloud.domain.com/remote.php/dav/files/admin/foobar.txt',
3139
owner: 'admin',
3240
mime: 'text/plain',
@@ -39,7 +47,7 @@ describe('Rename action enabled tests', () => {
3947

4048
test('Disabled for node without DELETE permission', () => {
4149
const file = new File({
42-
id: 1,
50+
id: 2,
4351
source: 'https://cloud.domain.com/remote.php/dav/files/admin/foobar.txt',
4452
owner: 'admin',
4553
mime: 'text/plain',
@@ -54,13 +62,13 @@ describe('Rename action enabled tests', () => {
5462
window.OCA = { Files: { Sidebar: {} } }
5563

5664
const file1 = new File({
57-
id: 1,
65+
id: 2,
5866
source: 'https://cloud.domain.com/remote.php/dav/files/admin/foo.txt',
5967
owner: 'admin',
6068
mime: 'text/plain',
6169
})
6270
const file2 = new File({
63-
id: 1,
71+
id: 2,
6472
source: 'https://cloud.domain.com/remote.php/dav/files/admin/bar.txt',
6573
owner: 'admin',
6674
mime: 'text/plain',
@@ -76,7 +84,7 @@ describe('Rename action exec tests', () => {
7684
vi.spyOn(eventBus, 'emit')
7785

7886
const file = new File({
79-
id: 1,
87+
id: 2,
8088
source: 'https://cloud.domain.com/remote.php/dav/files/admin/foobar.txt',
8189
owner: 'admin',
8290
mime: 'text/plain',

apps/files/src/actions/renameAction.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ import { emit } from '@nextcloud/event-bus'
66
import { Permission, type Node, FileAction, View } from '@nextcloud/files'
77
import { translate as t } from '@nextcloud/l10n'
88
import PencilSvg from '@mdi/svg/svg/pencil.svg?raw'
9+
import { getPinia } from '../store'
10+
import { useFilesStore } from '../store/files'
11+
import { dirname } from 'path'
912

1013
export const ACTION_RENAME = 'rename'
1114

@@ -18,12 +21,23 @@ export const action = new FileAction({
1821
if (nodes.length === 0) {
1922
return false
2023
}
24+
2125
// Disable for single file shares
2226
if (view.id === 'public-file-share') {
2327
return false
2428
}
25-
// Only enable if all nodes have the delete permission
26-
return nodes.every((node) => Boolean(node.permissions & Permission.DELETE))
29+
30+
const node = nodes[0]
31+
const filesStore = useFilesStore(getPinia())
32+
const parentNode = node.dirname === '/'
33+
? filesStore.getRoot(view.id)
34+
: filesStore.getNode(dirname(node.source))
35+
const parentPermissions = parentNode?.permissions || Permission.NONE
36+
37+
// Only enable if the node have the delete permission
38+
// and if the parent folder allows creating files
39+
return Boolean(node.permissions & Permission.DELETE)
40+
&& Boolean(parentPermissions & Permission.CREATE)
2741
},
2842

2943
async exec(node: Node) {

apps/files/src/services/HotKeysService.spec.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@
33
* SPDX-License-Identifier: AGPL-3.0-or-later
44
*/
55
import { describe, it, vi, expect, beforeEach, beforeAll, afterEach } from 'vitest'
6-
import { File, Permission, View } from '@nextcloud/files'
6+
import { File, Folder, Permission, View } from '@nextcloud/files'
77
import axios from '@nextcloud/axios'
88

99
import { getPinia } from '../store/index.ts'
1010
import { useActiveStore } from '../store/active.ts'
11+
import { useFilesStore } from '../store/files'
1112

1213
import { action as deleteAction } from '../actions/deleteAction.ts'
1314
import { action as favoriteAction } from '../actions/favoriteAction.ts'
@@ -49,13 +50,17 @@ describe('HotKeysService testing', () => {
4950

5051
// Make sure the file is reset before each test
5152
file = new File({
52-
id: 1,
53+
id: 2,
5354
source: 'https://cloud.domain.com/remote.php/dav/files/admin/foobar.txt',
5455
owner: 'admin',
5556
mime: 'text/plain',
5657
permissions: Permission.ALL,
5758
})
5859

60+
const root = new Folder({ owner: 'test', source: 'https://cloud.domain.com/remote.php/dav/files/admin/', id: 1, permissions: Permission.CREATE })
61+
const files = useFilesStore(getPinia())
62+
files.setRoot({ service: 'files', root })
63+
5964
// Setting the view first as it reset the active node
6065
activeStore.onChangedView(view)
6166
activeStore.setActiveNode(file)

dist/files-init.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/files-init.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/files-main.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/files-main.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)