From 285c75c0186bd3fe3db6fda5fdf22bd9e1fecd0c Mon Sep 17 00:00:00 2001 From: Jonas Date: Tue, 12 Mar 2024 20:41:05 +0100 Subject: [PATCH] fix(session): Fix setting a guest name Fixes: #4252 Signed-off-by: Jonas --- cypress/e2e/share.spec.js | 22 ++++++++++++++++++++++ src/components/Editor/GuestNameDialog.vue | 4 ++-- src/components/Editor/SessionList.vue | 2 +- src/components/Editor/Status.vue | 2 +- src/services/SessionApi.js | 1 + src/services/SyncService.js | 2 +- 6 files changed, 28 insertions(+), 5 deletions(-) diff --git a/cypress/e2e/share.spec.js b/cypress/e2e/share.spec.js index 3d53f75e424..4c82bfdf4ed 100644 --- a/cypress/e2e/share.spec.js +++ b/cypress/e2e/share.spec.js @@ -35,6 +35,7 @@ describe('Open test.md in viewer', function() { cy.createFolder('folder') cy.uploadFile('test.md', 'text/markdown', 'folder/test.md') cy.uploadFile('test.md', 'text/markdown', 'folder/Readme.md') + cy.uploadFile('test.md', 'text/markdown', 'test3.md') cy.uploadFile('test.md', 'text/markdown', 'test2.md') cy.uploadFile('test.md', 'text/markdown') @@ -122,6 +123,27 @@ describe('Open test.md in viewer', function() { }) }) + it('Opens the editor as guest', function() { + cy.shareFile('/test3.md') + .then((token) => { + cy.logout() + cy.visit(`/s/${token}`) + }) + .then(() => { + cy.getEditor().should('be.visible') + cy.getContent() + .should('contain', 'Hello world') + .find('h2').should('contain', 'Hello world') + + cy.intercept({ method: 'POST', url: '**/apps/text/public/session/*/session' }).as('updateSession') + cy.get('button.avatar-list').click() + cy.get('.guest-name-dialog input[type="text"]') + .type('someone{enter}') + cy.wait('@updateSession') + .its('response.body.guestName').should('eq', 'someone') + }) + }) + it('Share a file with download disabled shows an error', function() { cy.shareFileToUser('test.md', recipient, { attributes: '[{"scope":"permissions","key":"download","enabled":false}]', diff --git a/src/components/Editor/GuestNameDialog.vue b/src/components/Editor/GuestNameDialog.vue index f0b061da084..e6b4151d65c 100644 --- a/src/components/Editor/GuestNameDialog.vue +++ b/src/components/Editor/GuestNameDialog.vue @@ -76,12 +76,12 @@ export default { }, }, beforeMount() { - this.guestName = this.$syncService.session.guestName + this.guestName = this.$syncService.connection.session.guestName this.updateBufferedGuestName() }, methods: { setGuestName() { - const previousGuestName = this.$syncService.session.guestName + const previousGuestName = this.$syncService.connection.session.guestName this.$syncService.updateSession(this.guestName).then(() => { localStorage.setItem('nick', this.guestName) this.updateBufferedGuestName() diff --git a/src/components/Editor/SessionList.vue b/src/components/Editor/SessionList.vue index 05a759956e6..b3ebd65bd08 100644 --- a/src/components/Editor/SessionList.vue +++ b/src/components/Editor/SessionList.vue @@ -108,7 +108,7 @@ export default { }, }, participantsPopover() { - if (this.currentSession.guestName) { + if (this.currentSession?.guestName) { return this.participantsWithoutCurrent } return this.participants diff --git a/src/components/Editor/Status.vue b/src/components/Editor/Status.vue index 9e2b2e99880..f5013e4f16c 100644 --- a/src/components/Editor/Status.vue +++ b/src/components/Editor/Status.vue @@ -35,7 +35,7 @@

{{ t('text', 'Last saved') }}: {{ lastSavedString }}

- + diff --git a/src/services/SessionApi.js b/src/services/SessionApi.js index 8cb8993b565..a29bdbbc298 100644 --- a/src/services/SessionApi.js +++ b/src/services/SessionApi.js @@ -75,6 +75,7 @@ export class Connection { this.#content = content this.#documentState = documentState this.#options = options + this.isPublic = !!options.shareToken this.closed = false } diff --git a/src/services/SyncService.js b/src/services/SyncService.js index 8de989e6b11..661ca5054f9 100644 --- a/src/services/SyncService.js +++ b/src/services/SyncService.js @@ -140,7 +140,7 @@ class SyncService { updateSession(guestName) { if (!this.connection.isPublic) { - return + return Promise.reject(new Error()) } return this.connection.update(guestName) .catch((error) => {