Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions apps/files/src/actions/renameAction.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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',
Expand All @@ -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',
Expand All @@ -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',
Expand All @@ -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',
Expand Down
18 changes: 16 additions & 2 deletions apps/files/src/actions/renameAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand All @@ -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) {
Expand Down
9 changes: 7 additions & 2 deletions apps/files/src/services/HotKeysService.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions dist/files-init.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/files-init.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/files-main.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/files-main.js.map

Large diffs are not rendered by default.

Loading