Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable30] fix(files): handle failed node properly #50947

Merged
merged 3 commits into from
Feb 21, 2025
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
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
4 changes: 2 additions & 2 deletions cypress/e2e/files/files-selection.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ describe('files: Select all files', { testIsolation: true }, () => {
it('Can select range of files with shift key', () => {
cy.get('[data-cy-files-list-row-checkbox]').should('have.length', filesCount)
selectRowForFile('audio.mp3')
cy.window().trigger('keydown', { shiftKey: true })
cy.window().trigger('keydown', { shiftKey: true, key: 'Shift' })
selectRowForFile('readme.md', { shiftKey: true })
cy.window().trigger('keyup', { shiftKey: false })
cy.window().trigger('keyup', { shiftKey: false, key: 'Shift' })

cy.get('.files-list__selected').should('have.text', '4 selected')
cy.get('[data-cy-files-list-row-checkbox] input[type="checkbox"]:checked').should('have.length', 4)
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
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