aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorskjnldsv <skjnldsv@protonmail.com>2025-02-18 10:53:11 +0100
committerskjnldsv <skjnldsv@protonmail.com>2025-02-19 09:52:53 +0100
commit70f65efb3910670fad0626cbd4cc166f6965a62a (patch)
tree05cd4a90d6d1fcd7000d0333ec4df46173318672
parent9cee2c44c4b7b0281ffd6b4e6077d711b0560895 (diff)
downloadnextcloud-server-70f65efb3910670fad0626cbd4cc166f6965a62a.tar.gz
nextcloud-server-70f65efb3910670fad0626cbd4cc166f6965a62a.zip
fix(files): properly show file not found error
Signed-off-by: skjnldsv <skjnldsv@protonmail.com>
-rw-r--r--apps/files/src/views/FilesList.vue18
-rw-r--r--cypress/e2e/files/files.cy.ts43
2 files changed, 56 insertions, 5 deletions
diff --git a/apps/files/src/views/FilesList.vue b/apps/files/src/views/FilesList.vue
index 3ee1cab43c6..47c303beb5c 100644
--- a/apps/files/src/views/FilesList.vue
+++ b/apps/files/src/views/FilesList.vue
@@ -486,16 +486,26 @@ export default defineComponent({
},
},
- mounted() {
- this.fetchContent()
-
+ async mounted() {
subscribe('files:node:deleted', this.onNodeDeleted)
subscribe('files:node:updated', this.onUpdatedNode)
subscribe('nextcloud:unified-search.search', this.onSearch)
subscribe('nextcloud:unified-search.reset', this.resetSearch)
- // reload on settings change
+ // Reload on settings change
this.unsubscribeStoreCallback = this.userConfigStore.$subscribe(() => this.fetchContent(), { deep: true })
+
+ // Finally, fetch the current directory contents
+ await this.fetchContent()
+ if (this.fileId) {
+ // If we have a fileId, let's check if the file exists
+ const node = this.dirContents.find(node => node.fileid.toString() === this.fileId.toString())
+ // If the file isn't in the current directory nor if
+ // the current directory is the file, we show an error
+ if (!node && this.currentFolder.fileid.toString() !== this.fileId.toString()) {
+ showError(t('files', 'The file could not be found'))
+ }
+ }
},
unmounted() {
diff --git a/cypress/e2e/files/files.cy.ts b/cypress/e2e/files/files.cy.ts
index 33261be417e..3cb019dd0e9 100644
--- a/cypress/e2e/files/files.cy.ts
+++ b/cypress/e2e/files/files.cy.ts
@@ -1,3 +1,5 @@
+import type { User } from "@nextcloud/cypress"
+
/**
* @copyright Copyright (c) 2022 John Molakvoæ <skjnldsv@protonmail.com>
*
@@ -20,14 +22,53 @@
*
*/
describe('Files', { testIsolation: true }, () => {
+ let currentUser: User
+
beforeEach(() => {
cy.createRandomUser().then((user) => {
- cy.login(user)
+ currentUser = user
})
})
it('Login with a user and open the files app', () => {
+ cy.login(currentUser)
cy.visit('/apps/files')
cy.get('[data-cy-files-list] [data-cy-files-list-row-name="welcome.txt"]').should('be.visible')
})
+
+ it('Opens a valid file shows it as active', () => {
+ cy.uploadContent(currentUser, new Blob(), 'text/plain', '/original.txt').then((response) => {
+ const fileId = Number.parseInt(response.headers['oc-fileid'] ?? '0')
+
+ cy.login(currentUser)
+ cy.visit('/apps/files/files/' + fileId)
+
+ cy.get(`[data-cy-files-list-row-fileid=${fileId}]`)
+ .should('be.visible')
+ cy.get(`[data-cy-files-list-row-fileid=${fileId}]`)
+ .invoke('attr', 'data-cy-files-list-row-name').should('eq', 'original.txt')
+ cy.get(`[data-cy-files-list-row-fileid=${fileId}]`)
+ .invoke('attr', 'class').should('contain', 'active')
+ cy.contains('The file could not be found').should('not.exist')
+ })
+ })
+
+ it('Opens a valid folder shows its content', () => {
+ cy.mkdir(currentUser, '/folder').then(() => {
+ cy.login(currentUser)
+ cy.visit('/apps/files/files?dir=/folder')
+
+ cy.get('[data-cy-files-content-breadcrumbs]').contains('folder').should('be.visible')
+ cy.contains('The file could not be found').should('not.exist')
+ })
+ })
+
+ it('Opens an unknown file show an error', () => {
+ cy.intercept('PROPFIND', /\/remote.php\/dav\//).as('propfind')
+ cy.login(currentUser)
+ cy.visit('/apps/files/files/123456')
+
+ cy.wait('@propfind')
+ cy.contains('The file could not be found').should('be.visible')
+ })
})