Skip to content

Commit

Permalink
fix(session): Fix setting a guest name
Browse files Browse the repository at this point in the history
Fixes: #4252

Signed-off-by: Jonas <jonas@freesources.org>
  • Loading branch information
mejo- authored and backportbot[bot] committed Mar 13, 2024
1 parent 9dd63c9 commit 285c75c
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 5 deletions.
22 changes: 22 additions & 0 deletions cypress/e2e/share.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down Expand Up @@ -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}]',
Expand Down
4 changes: 2 additions & 2 deletions src/components/Editor/GuestNameDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion src/components/Editor/SessionList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ export default {
},
},
participantsPopover() {
if (this.currentSession.guestName) {
if (this.currentSession?.guestName) {
return this.participantsWithoutCurrent
}
return this.participants
Expand Down
2 changes: 1 addition & 1 deletion src/components/Editor/Status.vue
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
<p slot="lastSaved" class="last-saved">
{{ t('text', 'Last saved') }}: {{ lastSavedString }}
</p>
<GuestNameDialog v-if="$isPublic && !currentSession.userId" :session="currentSession" />
<GuestNameDialog v-if="$isPublic && currentSession && !currentSession.userId" :session="currentSession" />
</SessionList>
</div>
</template>
Expand Down
1 change: 1 addition & 0 deletions src/services/SessionApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ export class Connection {
this.#content = content
this.#documentState = documentState
this.#options = options
this.isPublic = !!options.shareToken
this.closed = false
}

Expand Down
2 changes: 1 addition & 1 deletion src/services/SyncService.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down

0 comments on commit 285c75c

Please sign in to comment.