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

[stable27] fix(session): Fix setting a guest name #5474

Merged
merged 1 commit into from Mar 13, 2024
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 22 additions & 0 deletions cypress/e2e/share.spec.js
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' }).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
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
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
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
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
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