mirror of
https://github.com/nextcloud/server.git
synced 2026-02-19 02:38:40 -05:00
Merge pull request #53855 from nextcloud/fix/rename-trashbin
This commit is contained in:
commit
cf3ffb3fd1
7 changed files with 44 additions and 17 deletions
|
|
@ -3,15 +3,23 @@
|
|||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
import { action } from './renameAction'
|
||||
import { File, Permission, View, FileAction } from '@nextcloud/files'
|
||||
import { File, Folder, Permission, View, FileAction } from '@nextcloud/files'
|
||||
import * as eventBus from '@nextcloud/event-bus'
|
||||
import { describe, expect, test, vi } from 'vitest'
|
||||
import { describe, expect, test, vi, beforeEach } from 'vitest'
|
||||
import { useFilesStore } from '../store/files'
|
||||
import { getPinia } from '../store/index.ts'
|
||||
|
||||
const view = {
|
||||
id: 'files',
|
||||
name: 'Files',
|
||||
} as View
|
||||
|
||||
beforeEach(() => {
|
||||
const root = new Folder({ owner: 'test', source: 'https://cloud.domain.com/remote.php/dav/files/admin/', id: 1, permissions: Permission.CREATE })
|
||||
const files = useFilesStore(getPinia())
|
||||
files.setRoot({ service: 'files', root })
|
||||
})
|
||||
|
||||
describe('Rename action conditions tests', () => {
|
||||
test('Default values', () => {
|
||||
expect(action).toBeInstanceOf(FileAction)
|
||||
|
|
@ -26,7 +34,7 @@ describe('Rename action conditions tests', () => {
|
|||
describe('Rename action enabled tests', () => {
|
||||
test('Enabled for node with UPDATE permission', () => {
|
||||
const file = new File({
|
||||
id: 1,
|
||||
id: 2,
|
||||
source: 'https://cloud.domain.com/remote.php/dav/files/admin/foobar.txt',
|
||||
owner: 'admin',
|
||||
mime: 'text/plain',
|
||||
|
|
@ -39,7 +47,7 @@ describe('Rename action enabled tests', () => {
|
|||
|
||||
test('Disabled for node without DELETE permission', () => {
|
||||
const file = new File({
|
||||
id: 1,
|
||||
id: 2,
|
||||
source: 'https://cloud.domain.com/remote.php/dav/files/admin/foobar.txt',
|
||||
owner: 'admin',
|
||||
mime: 'text/plain',
|
||||
|
|
@ -54,13 +62,13 @@ describe('Rename action enabled tests', () => {
|
|||
window.OCA = { Files: { Sidebar: {} } }
|
||||
|
||||
const file1 = new File({
|
||||
id: 1,
|
||||
id: 2,
|
||||
source: 'https://cloud.domain.com/remote.php/dav/files/admin/foo.txt',
|
||||
owner: 'admin',
|
||||
mime: 'text/plain',
|
||||
})
|
||||
const file2 = new File({
|
||||
id: 1,
|
||||
id: 2,
|
||||
source: 'https://cloud.domain.com/remote.php/dav/files/admin/bar.txt',
|
||||
owner: 'admin',
|
||||
mime: 'text/plain',
|
||||
|
|
@ -76,7 +84,7 @@ describe('Rename action exec tests', () => {
|
|||
vi.spyOn(eventBus, 'emit')
|
||||
|
||||
const file = new File({
|
||||
id: 1,
|
||||
id: 2,
|
||||
source: 'https://cloud.domain.com/remote.php/dav/files/admin/foobar.txt',
|
||||
owner: 'admin',
|
||||
mime: 'text/plain',
|
||||
|
|
|
|||
|
|
@ -6,6 +6,9 @@ import { emit } from '@nextcloud/event-bus'
|
|||
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'
|
||||
import { getPinia } from '../store'
|
||||
import { useFilesStore } from '../store/files'
|
||||
import { dirname } from 'path'
|
||||
|
||||
export const ACTION_RENAME = 'rename'
|
||||
|
||||
|
|
@ -18,12 +21,23 @@ export const action = new FileAction({
|
|||
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))
|
||||
|
||||
const node = nodes[0]
|
||||
const filesStore = useFilesStore(getPinia())
|
||||
const parentNode = node.dirname === '/'
|
||||
? filesStore.getRoot(view.id)
|
||||
: filesStore.getNode(dirname(node.source))
|
||||
const parentPermissions = parentNode?.permissions || Permission.NONE
|
||||
|
||||
// Only enable if the node have the delete permission
|
||||
// and if the parent folder allows creating files
|
||||
return Boolean(node.permissions & Permission.DELETE)
|
||||
&& Boolean(parentPermissions & Permission.CREATE)
|
||||
},
|
||||
|
||||
async exec(node: Node) {
|
||||
|
|
|
|||
|
|
@ -2,13 +2,14 @@
|
|||
* SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
import { File, Permission, View } from '@nextcloud/files'
|
||||
import { File, Folder, Permission, View } from '@nextcloud/files'
|
||||
import { describe, it, vi, expect, beforeEach, beforeAll, afterEach } from 'vitest'
|
||||
import { nextTick } from 'vue'
|
||||
import axios from '@nextcloud/axios'
|
||||
|
||||
import { getPinia } from '../store/index.ts'
|
||||
import { useActiveStore } from '../store/active.ts'
|
||||
import { useFilesStore } from '../store/files'
|
||||
|
||||
import { action as deleteAction } from '../actions/deleteAction.ts'
|
||||
import { action as favoriteAction } from '../actions/favoriteAction.ts'
|
||||
|
|
@ -49,13 +50,17 @@ describe('HotKeysService testing', () => {
|
|||
|
||||
// Make sure the file is reset before each test
|
||||
file = new File({
|
||||
id: 1,
|
||||
id: 2,
|
||||
source: 'https://cloud.domain.com/remote.php/dav/files/admin/foobar.txt',
|
||||
owner: 'admin',
|
||||
mime: 'text/plain',
|
||||
permissions: Permission.ALL,
|
||||
})
|
||||
|
||||
const root = new Folder({ owner: 'test', source: 'https://cloud.domain.com/remote.php/dav/files/admin/', id: 1, permissions: Permission.CREATE })
|
||||
const files = useFilesStore(getPinia())
|
||||
files.setRoot({ service: 'files', root })
|
||||
|
||||
// Setting the view first as it reset the active node
|
||||
activeStore.activeView = view
|
||||
activeStore.activeNode = file
|
||||
|
|
|
|||
4
dist/files-init.js
vendored
4
dist/files-init.js
vendored
File diff suppressed because one or more lines are too long
2
dist/files-init.js.map
vendored
2
dist/files-init.js.map
vendored
File diff suppressed because one or more lines are too long
4
dist/files-main.js
vendored
4
dist/files-main.js
vendored
File diff suppressed because one or more lines are too long
2
dist/files-main.js.map
vendored
2
dist/files-main.js.map
vendored
File diff suppressed because one or more lines are too long
Loading…
Reference in a new issue