Skip to content

Commit

Permalink
fix(files): handle failed node properly
Browse files Browse the repository at this point in the history
Signed-off-by: skjnldsv <skjnldsv@protonmail.com>
  • Loading branch information
skjnldsv committed Feb 21, 2025
1 parent 306fa8d commit a150128
Show file tree
Hide file tree
Showing 3 changed files with 121 additions and 26 deletions.
24 changes: 22 additions & 2 deletions apps/files/src/components/FileEntryMixin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,16 @@ export default defineComponent({
return this.source.status === NodeStatus.FAILED
},

canDrag() {
canDrag(): boolean {
if (this.isRenaming) {
return false
}

// Ignore if the node is not available
if (this.isFailedSource) {
return false
}

const canDrag = (node: Node): boolean => {
return (node?.permissions & Permission.UPDATE) !== 0
}
Expand All @@ -148,11 +153,16 @@ export default defineComponent({
return canDrag(this.source)
},

canDrop() {
canDrop(): boolean {
if (this.source.type !== FileType.Folder) {
return false
}

// Ignore if the node is not available
if (this.isFailedSource) {
return false
}

// If the current folder is also being dragged, we can't drop it on itself
if (this.draggingFiles.includes(this.source.source)) {
return false
Expand Down Expand Up @@ -275,6 +285,11 @@ export default defineComponent({
return
}

// Ignore right click if the node is not available
if (this.isFailedSource) {
return
}

// The grid mode is compact enough to not care about
// the actions menu mouse position
if (!this.gridMode) {
Expand Down Expand Up @@ -312,6 +327,11 @@ export default defineComponent({
return
}

// Ignore right click if the node is not available
if (this.isFailedSource) {
return
}

// if ctrl+click or middle mouse button, open in new tab
if (event.ctrlKey || event.metaKey || event.button === 1) {
event.preventDefault()
Expand Down
75 changes: 75 additions & 0 deletions cypress/e2e/files_external/files-external-failed.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/**
* SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

import { User } from '@nextcloud/cypress'
import { AuthBackend, createStorageWithConfig, StorageBackend } from './StorageUtils'
import { getRowForFile } from '../files/FilesUtils'

describe('Files user credentials', { testIsolation: true }, () => {
let currentUser: User

beforeEach(() => {
})

before(() => {
cy.runOccCommand('app:enable files_external')
cy.createRandomUser().then((user) => { currentUser = user })
})

afterEach(() => {
// Cleanup global storages
cy.runOccCommand('files_external:list --output=json').then(({ stdout }) => {
const list = JSON.parse(stdout)
list.forEach((storage) => cy.runOccCommand(`files_external:delete --yes ${storage.mount_id}`), { failOnNonZeroExit: false })
})
})

after(() => {
cy.runOccCommand('app:disable files_external')
})

it('Create a failed user storage with invalid url', () => {
const url = 'http://cloud.domain.com/remote.php/dav/files/abcdef123456'
createStorageWithConfig('Storage1', StorageBackend.DAV, AuthBackend.LoginCredentials, { host: url.replace('index.php/', ''), secure: 'false' })

cy.login(currentUser)
cy.visit('/apps/files')

// Ensure the row is visible and marked as unavailable
getRowForFile('Storage1').as('row').should('be.visible')
cy.get('@row').find('[data-cy-files-list-row-name-link]')
.should('have.attr', 'title', 'This node is unavailable')

// Ensure clicking on the location does not open the folder
cy.location().then((loc) => {
cy.get('@row').find('[data-cy-files-list-row-name-link]').click()
cy.location('href').should('eq', loc.href)
})
})

it('Create a failed user storage with invalid login credentials', () => {
const url = 'http://cloud.domain.com/remote.php/dav/files/abcdef123456'
createStorageWithConfig('Storage2', StorageBackend.DAV, AuthBackend.Password, {
host: url.replace('index.php/', ''),
user: 'invaliduser',
password: 'invalidpassword',
secure: 'false',
})

cy.login(currentUser)
cy.visit('/apps/files')

// Ensure the row is visible and marked as unavailable
getRowForFile('Storage2').as('row').should('be.visible')
cy.get('@row').find('[data-cy-files-list-row-name-link]')
.should('have.attr', 'title', 'This node is unavailable')

// Ensure clicking on the location does not open the folder
cy.location().then((loc) => {
cy.get('@row').find('[data-cy-files-list-row-name-link]').click()
cy.location('href').should('eq', loc.href)
})
})
})
48 changes: 24 additions & 24 deletions cypress/e2e/files_external/files-user-credentials.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ describe('Files user credentials', { testIsolation: true }, () => {
cy.runOccCommand('app:enable files_external')

// Create some users
cy.createRandomUser().then((user) => user1 = user)
cy.createRandomUser().then((user) => user2 = user)
cy.createRandomUser().then((user) => { user1 = user })
cy.createRandomUser().then((user) => { user2 = user })

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

cy.login(user2)
cy.visit('/apps/files/extstoragemounts')
Expand Down

0 comments on commit a150128

Please sign in to comment.