Skip to content

Commit bb63ca9

Browse files
skjnldsvAndyScherzinger
authored andcommitted
fix(files): handle failed node properly
Signed-off-by: skjnldsv <skjnldsv@protonmail.com>
1 parent b1711e9 commit bb63ca9

File tree

3 files changed

+121
-26
lines changed

3 files changed

+121
-26
lines changed

apps/files/src/components/FileEntryMixin.ts

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,11 +133,16 @@ export default defineComponent({
133133
return this.source.status === NodeStatus.FAILED
134134
},
135135

136-
canDrag() {
136+
canDrag(): boolean {
137137
if (this.isRenaming) {
138138
return false
139139
}
140140

141+
// Ignore if the node is not available
142+
if (this.isFailedSource) {
143+
return false
144+
}
145+
141146
const canDrag = (node: Node): boolean => {
142147
return (node?.permissions & Permission.UPDATE) !== 0
143148
}
@@ -150,11 +155,16 @@ export default defineComponent({
150155
return canDrag(this.source)
151156
},
152157

153-
canDrop() {
158+
canDrop(): boolean {
154159
if (this.source.type !== FileType.Folder) {
155160
return false
156161
}
157162

163+
// Ignore if the node is not available
164+
if (this.isFailedSource) {
165+
return false
166+
}
167+
158168
// If the current folder is also being dragged, we can't drop it on itself
159169
if (this.draggingFiles.includes(this.source.source)) {
160170
return false
@@ -274,6 +284,11 @@ export default defineComponent({
274284
return
275285
}
276286

287+
// Ignore right click if the node is not available
288+
if (this.isFailedSource) {
289+
return
290+
}
291+
277292
// The grid mode is compact enough to not care about
278293
// the actions menu mouse position
279294
if (!this.gridMode) {
@@ -311,6 +326,11 @@ export default defineComponent({
311326
return
312327
}
313328

329+
// Ignore if the node is not available
330+
if (this.isFailedSource) {
331+
return
332+
}
333+
314334
// if ctrl+click / cmd+click (MacOS uses the meta key) or middle mouse button (button & 4), open in new tab
315335
// also if there is no default action use this as a fallback
316336
const metaKeyPressed = event.ctrlKey || event.metaKey || Boolean(event.button & 4)
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/**
2+
* SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors
3+
* SPDX-License-Identifier: AGPL-3.0-or-later
4+
*/
5+
6+
import { User } from '@nextcloud/cypress'
7+
import { AuthBackend, createStorageWithConfig, StorageBackend } from './StorageUtils'
8+
import { getRowForFile } from '../files/FilesUtils'
9+
10+
describe('Files user credentials', { testIsolation: true }, () => {
11+
let currentUser: User
12+
13+
beforeEach(() => {
14+
})
15+
16+
before(() => {
17+
cy.runOccCommand('app:enable files_external')
18+
cy.createRandomUser().then((user) => { currentUser = user })
19+
})
20+
21+
afterEach(() => {
22+
// Cleanup global storages
23+
cy.runOccCommand('files_external:list --output=json').then(({ stdout }) => {
24+
const list = JSON.parse(stdout)
25+
list.forEach((storage) => cy.runOccCommand(`files_external:delete --yes ${storage.mount_id}`), { failOnNonZeroExit: false })
26+
})
27+
})
28+
29+
after(() => {
30+
cy.runOccCommand('app:disable files_external')
31+
})
32+
33+
it('Create a failed user storage with invalid url', () => {
34+
const url = 'http://cloud.domain.com/remote.php/dav/files/abcdef123456'
35+
createStorageWithConfig('Storage1', StorageBackend.DAV, AuthBackend.LoginCredentials, { host: url.replace('index.php/', ''), secure: 'false' })
36+
37+
cy.login(currentUser)
38+
cy.visit('/apps/files')
39+
40+
// Ensure the row is visible and marked as unavailable
41+
getRowForFile('Storage1').as('row').should('be.visible')
42+
cy.get('@row').find('[data-cy-files-list-row-name-link]')
43+
.should('have.attr', 'title', 'This node is unavailable')
44+
45+
// Ensure clicking on the location does not open the folder
46+
cy.location().then((loc) => {
47+
cy.get('@row').find('[data-cy-files-list-row-name-link]').click()
48+
cy.location('href').should('eq', loc.href)
49+
})
50+
})
51+
52+
it('Create a failed user storage with invalid login credentials', () => {
53+
const url = 'http://cloud.domain.com/remote.php/dav/files/abcdef123456'
54+
createStorageWithConfig('Storage2', StorageBackend.DAV, AuthBackend.Password, {
55+
host: url.replace('index.php/', ''),
56+
user: 'invaliduser',
57+
password: 'invalidpassword',
58+
secure: 'false',
59+
})
60+
61+
cy.login(currentUser)
62+
cy.visit('/apps/files')
63+
64+
// Ensure the row is visible and marked as unavailable
65+
getRowForFile('Storage2').as('row').should('be.visible')
66+
cy.get('@row').find('[data-cy-files-list-row-name-link]')
67+
.should('have.attr', 'title', 'This node is unavailable')
68+
69+
// Ensure clicking on the location does not open the folder
70+
cy.location().then((loc) => {
71+
cy.get('@row').find('[data-cy-files-list-row-name-link]').click()
72+
cy.location('href').should('eq', loc.href)
73+
})
74+
})
75+
})

cypress/e2e/files_external/files-user-credentials.cy.ts

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ describe('Files user credentials', { testIsolation: true }, () => {
2222
cy.runOccCommand('app:enable files_external')
2323

2424
// Create some users
25-
cy.createRandomUser().then((user) => user1 = user)
26-
cy.createRandomUser().then((user) => user2 = user)
25+
cy.createRandomUser().then((user) => { user1 = user })
26+
cy.createRandomUser().then((user) => { user2 = user })
2727

2828
// This user will hold the webdav storage
2929
cy.createRandomUser().then((user) => {
@@ -34,7 +34,7 @@ describe('Files user credentials', { testIsolation: true }, () => {
3434

3535
after(() => {
3636
// Cleanup global storages
37-
cy.runOccCommand(`files_external:list --output=json`).then(({stdout}) => {
37+
cy.runOccCommand('files_external:list --output=json').then(({ stdout }) => {
3838
const list = JSON.parse(stdout)
3939
list.forEach((storage) => cy.runOccCommand(`files_external:delete --yes ${storage.mount_id}`), { failOnNonZeroExit: false })
4040
})
@@ -44,7 +44,7 @@ describe('Files user credentials', { testIsolation: true }, () => {
4444

4545
it('Create a user storage with user credentials', () => {
4646
const url = Cypress.config('baseUrl') + '/remote.php/dav/files/' + storageUser.userId
47-
createStorageWithConfig(storageUser.userId, StorageBackend.DAV, AuthBackend.UserProvided, { host: url.replace('index.php/', ''), 'secure': 'false' })
47+
createStorageWithConfig(storageUser.userId, StorageBackend.DAV, AuthBackend.UserProvided, { host: url.replace('index.php/', ''), secure: 'false' })
4848

4949
cy.login(user1)
5050
cy.visit('/apps/files/extstoragemounts')
@@ -55,23 +55,23 @@ describe('Files user credentials', { testIsolation: true }, () => {
5555
triggerInlineActionForFile(storageUser.userId, ACTION_CREDENTIALS_EXTERNAL_STORAGE)
5656

5757
// See credentials dialog
58-
const storageDialog = cy.findByRole('dialog', { name: 'Storage credentials' })
59-
storageDialog.should('be.visible')
60-
storageDialog.findByRole('textbox', { name: 'Login' }).type(storageUser.userId)
61-
storageDialog.get('input[type="password"]').type(storageUser.password)
62-
storageDialog.get('button').contains('Confirm').click()
63-
storageDialog.should('not.exist')
58+
cy.findByRole('dialog', { name: 'Storage credentials' }).as('storageDialog')
59+
cy.get('@storageDialog').should('be.visible')
60+
cy.get('@storageDialog').findByRole('textbox', { name: 'Login' }).type(storageUser.userId)
61+
cy.get('@storageDialog').get('input[type="password"]').type(storageUser.password)
62+
cy.get('@storageDialog').get('button').contains('Confirm').click()
63+
cy.get('@storageDialog').should('not.exist')
6464

6565
// Storage dialog now closed, the user auth dialog should be visible
66-
const authDialog = cy.findByRole('dialog', { name: 'Confirm your password' })
67-
authDialog.should('be.visible')
66+
cy.findByRole('dialog', { name: 'Confirm your password' }).as('authDialog')
67+
cy.get('@authDialog').should('be.visible')
6868
handlePasswordConfirmation(user1.password)
6969

7070
// Wait for the credentials to be set
7171
cy.wait('@setCredentials')
7272

7373
// Auth dialog should be closed and the set credentials button should be gone
74-
authDialog.should('not.exist', { timeout: 2000 })
74+
cy.get('@authDialog').should('not.exist', { timeout: 2000 })
7575
getActionEntryForFile(storageUser.userId, ACTION_CREDENTIALS_EXTERNAL_STORAGE).should('not.exist')
7676

7777
// Finally, the storage should be accessible
@@ -82,7 +82,7 @@ describe('Files user credentials', { testIsolation: true }, () => {
8282

8383
it('Create a user storage with GLOBAL user credentials', () => {
8484
const url = Cypress.config('baseUrl') + '/remote.php/dav/files/' + storageUser.userId
85-
createStorageWithConfig('storage1', StorageBackend.DAV, AuthBackend.UserGlobalAuth, { host: url.replace('index.php/', ''), 'secure': 'false' })
85+
createStorageWithConfig('storage1', StorageBackend.DAV, AuthBackend.UserGlobalAuth, { host: url.replace('index.php/', ''), secure: 'false' })
8686

8787
cy.login(user2)
8888
cy.visit('/apps/files/extstoragemounts')
@@ -93,23 +93,23 @@ describe('Files user credentials', { testIsolation: true }, () => {
9393
triggerInlineActionForFile('storage1', ACTION_CREDENTIALS_EXTERNAL_STORAGE)
9494

9595
// See credentials dialog
96-
const storageDialog = cy.findByRole('dialog', { name: 'Storage credentials' })
97-
storageDialog.should('be.visible')
98-
storageDialog.findByRole('textbox', { name: 'Login' }).type(storageUser.userId)
99-
storageDialog.get('input[type="password"]').type(storageUser.password)
100-
storageDialog.get('button').contains('Confirm').click()
101-
storageDialog.should('not.exist')
96+
cy.findByRole('dialog', { name: 'Storage credentials' }).as('storageDialog')
97+
cy.get('@storageDialog').should('be.visible')
98+
cy.get('@storageDialog').findByRole('textbox', { name: 'Login' }).type(storageUser.userId)
99+
cy.get('@storageDialog').get('input[type="password"]').type(storageUser.password)
100+
cy.get('@storageDialog').get('button').contains('Confirm').click()
101+
cy.get('@storageDialog').should('not.exist')
102102

103103
// Storage dialog now closed, the user auth dialog should be visible
104-
const authDialog = cy.findByRole('dialog', { name: 'Confirm your password' })
105-
authDialog.should('be.visible')
104+
cy.findByRole('dialog', { name: 'Confirm your password' }).as('authDialog')
105+
cy.get('@authDialog').should('be.visible')
106106
handlePasswordConfirmation(user2.password)
107107

108108
// Wait for the credentials to be set
109109
cy.wait('@setCredentials')
110110

111111
// Auth dialog should be closed and the set credentials button should be gone
112-
authDialog.should('not.exist', { timeout: 2000 })
112+
cy.get('@authDialog').should('not.exist', { timeout: 2000 })
113113
getActionEntryForFile('storage1', ACTION_CREDENTIALS_EXTERNAL_STORAGE).should('not.exist')
114114

115115
// Finally, the storage should be accessible
@@ -120,7 +120,7 @@ describe('Files user credentials', { testIsolation: true }, () => {
120120

121121
it('Create another user storage while reusing GLOBAL user credentials', () => {
122122
const url = Cypress.config('baseUrl') + '/remote.php/dav/files/' + storageUser.userId
123-
createStorageWithConfig('storage2', StorageBackend.DAV, AuthBackend.UserGlobalAuth, { host: url.replace('index.php/', ''), 'secure': 'false' })
123+
createStorageWithConfig('storage2', StorageBackend.DAV, AuthBackend.UserGlobalAuth, { host: url.replace('index.php/', ''), secure: 'false' })
124124

125125
cy.login(user2)
126126
cy.visit('/apps/files/extstoragemounts')

0 commit comments

Comments
 (0)