Skip to content

Commit 158872d

Browse files
committed
test(e2e): hide move dialog action if destination has no CREATE permission
Signed-off-by: Maksim Sukharev <[email protected]>
1 parent 8ba3c9b commit 158872d

2 files changed

Lines changed: 162 additions & 0 deletions

File tree

Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
/**
2+
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
3+
* SPDX-License-Identifier: AGPL-3.0-or-later
4+
*/
5+
import type { User } from '@nextcloud/cypress'
6+
import { createShare } from './FilesSharingUtils.ts'
7+
import {
8+
getRowForFile,
9+
moveFile,
10+
copyFile,
11+
navigateToFolder,
12+
triggerActionForFile,
13+
} from '../files/FilesUtils.ts'
14+
15+
export const copyFileForbidden = (fileName: string, dirPath: string) => {
16+
getRowForFile(fileName).should('be.visible')
17+
triggerActionForFile(fileName, 'move-copy')
18+
19+
cy.get('.file-picker').within(() => {
20+
// intercept the copy so we can wait for it
21+
cy.intercept('COPY', /\/(remote|public)\.php\/dav\/files\//).as('copyFile')
22+
23+
const directories = dirPath.split('/')
24+
directories.forEach((directory) => {
25+
// select the folder
26+
cy.get(`[data-filename="${CSS.escape(directory)}"]`).should('be.visible').click()
27+
})
28+
29+
// check copy button
30+
cy.contains('button', `Copy to ${directories.at(-1)}`).should('be.disabled')
31+
})
32+
}
33+
34+
export const moveFileForbidden = (fileName: string, dirPath: string) => {
35+
getRowForFile(fileName).should('be.visible')
36+
triggerActionForFile(fileName, 'move-copy')
37+
38+
cy.get('.file-picker').within(() => {
39+
// intercept the copy so we can wait for it
40+
cy.intercept('MOVE', /\/(remote|public)\.php\/dav\/files\//).as('moveFile')
41+
42+
// select home folder
43+
cy.get('button[title="Home"]').should('be.visible').click()
44+
45+
const directories = dirPath.split('/')
46+
directories.forEach((directory) => {
47+
// select the folder
48+
cy.get(`[data-filename="${directory}"]`).should('be.visible').click()
49+
})
50+
51+
// click move
52+
cy.contains('button', `Move to ${directories.at(-1)}`).should('not.exist')
53+
})
54+
}
55+
56+
describe('files_sharing: Move or copy files', { testIsolation: true }, () => {
57+
let user: User
58+
let sharee: User
59+
60+
beforeEach(() => {
61+
cy.createRandomUser().then(($user) => {
62+
user = $user
63+
})
64+
cy.createRandomUser().then(($user) => {
65+
sharee = $user
66+
})
67+
})
68+
69+
70+
it('can create a file in a shared folder', () => {
71+
// share the folder
72+
cy.mkdir(user, '/folder')
73+
cy.login(user)
74+
cy.visit('/apps/files')
75+
createShare('folder', sharee.userId, { read: true, download: true })
76+
cy.logout()
77+
78+
// Now for the sharee
79+
cy.uploadContent(sharee, new Blob([]), 'text/plain', '/folder/file.txt')
80+
cy.login(sharee)
81+
// visit shared files view
82+
cy.visit('/apps/files')
83+
// see the shared folder
84+
getRowForFile('folder').should('be.visible')
85+
navigateToFolder('folder')
86+
// Content of the shared folder
87+
getRowForFile('file.txt').should('be.visible')
88+
})
89+
90+
it('can copy a file to a shared folder', () => {
91+
// share the folder
92+
cy.mkdir(user, '/folder')
93+
cy.login(user)
94+
cy.visit('/apps/files')
95+
createShare('folder', sharee.userId, { read: true, download: true })
96+
cy.logout()
97+
98+
// Now for the sharee
99+
cy.uploadContent(sharee, new Blob([]), 'text/plain', '/file.txt')
100+
cy.login(sharee)
101+
// visit shared files view
102+
cy.visit('/apps/files')
103+
// see the shared folder
104+
getRowForFile('folder').should('be.visible')
105+
// copy file to a shared folder
106+
copyFile('file.txt', 'folder')
107+
// click on the folder should open it in files
108+
navigateToFolder('folder')
109+
// Content of the shared folder
110+
getRowForFile('file.txt').should('be.visible')
111+
})
112+
113+
it('can not copy a file to a shared folder with no create permissions', () => {
114+
// share the folder
115+
cy.mkdir(user, '/folder')
116+
cy.login(user)
117+
cy.visit('/apps/files')
118+
createShare('folder', sharee.userId, { read: true, download: true, create: false })
119+
cy.logout()
120+
121+
// Now for the sharee
122+
cy.uploadContent(sharee, new Blob([]), 'text/plain', '/file.txt')
123+
cy.login(sharee)
124+
// visit shared files view
125+
cy.visit('/apps/files')
126+
// see the shared folder
127+
getRowForFile('folder').should('be.visible')
128+
copyFileForbidden('file.txt', 'folder')
129+
})
130+
131+
it('can not move a file from a shared folder with no delete permissions', () => {
132+
// share the folder
133+
cy.mkdir(user, '/folder')
134+
cy.uploadContent(user, new Blob([]), 'text/plain', '/folder/file.txt')
135+
cy.login(user)
136+
cy.visit('/apps/files')
137+
createShare('folder', sharee.userId, { read: true, download: true, delete: false })
138+
cy.logout()
139+
140+
// Now for the sharee
141+
cy.mkdir(sharee, '/folder-own')
142+
cy.login(sharee)
143+
// visit shared files view
144+
cy.visit('/apps/files')
145+
// see the shared folder
146+
getRowForFile('folder').should('be.visible')
147+
navigateToFolder('folder')
148+
getRowForFile('file.txt').should('be.visible')
149+
moveFileForbidden('file.txt', 'folder-own')
150+
})
151+
})

cypress/e2e/files_sharing/filesSharingUtils.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,17 @@ export function updateShare(fileName: string, index: number, shareSettings: Part
9595
}
9696
}
9797

98+
if (shareSettings.create !== undefined) {
99+
cy.get('[data-cy-files-sharing-share-permissions-checkbox="create"]').find('input').as('createCheckbox')
100+
if (shareSettings.create) {
101+
// Force:true because the checkbox is hidden by the pretty UI.
102+
cy.get('@createCheckbox').check({ force: true, scrollBehavior: 'nearest' })
103+
} else {
104+
// Force:true because the checkbox is hidden by the pretty UI.
105+
cy.get('@createCheckbox').uncheck({ force: true, scrollBehavior: 'nearest' })
106+
}
107+
}
108+
98109
if (shareSettings.delete !== undefined) {
99110
cy.get('[data-cy-files-sharing-share-permissions-checkbox="delete"]').find('input').as('deleteCheckbox')
100111
if (shareSettings.delete) {

0 commit comments

Comments
 (0)