From b227be034436461de7168eb74d2819000cc44b6b 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 98f42b53ce1..5eb124baf8c 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 e7856668cec..ccbc77488b0 100644 --- a/src/components/Editor/GuestNameDialog.vue +++ b/src/components/Editor/GuestNameDialog.vue @@ -72,12 +72,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 83431692cfa..d7102672da6 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 878103a724c..0f85e74177d 100644 --- a/src/components/Editor/Status.vue +++ b/src/components/Editor/Status.vue @@ -36,7 +36,7 @@

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

- + diff --git a/src/services/SessionApi.js b/src/services/SessionApi.js index 8c592a7bd29..69d848b3cd3 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 490de22db98..8172f0aba01 100644 --- a/src/services/SyncService.js +++ b/src/services/SyncService.js @@ -132,7 +132,7 @@ class SyncService { updateSession(guestName) { if (!this.connection.isPublic) { - return + return Promise.reject(new Error()) } return this.connection.update(guestName) .catch((error) => {