fix(files): handle failed node properly

Signed-off-by: skjnldsv <skjnldsv@protonmail.com>
pull/50943/head
skjnldsv 2025-02-21 10:18:47 +07:00
parent bc1943da4b
commit 4a96441437
3 changed files with 121 additions and 26 deletions

@ -133,11 +133,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
}
@ -150,11 +155,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
@ -274,6 +284,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) {
@ -311,6 +326,11 @@ export default defineComponent({
return
}
// Ignore if the node is not available
if (this.isFailedSource) {
return
}
// if ctrl+click / cmd+click (MacOS uses the meta key) or middle mouse button (button & 4), open in new tab
// also if there is no default action use this as a fallback
const metaKeyPressed = event.ctrlKey || event.metaKey || Boolean(event.button & 4)

@ -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)
})
})
})

@ -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) => {
@ -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 })
})
@ -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')
@ -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
@ -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')
@ -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
@ -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')