Skip to content

Commit

Permalink
fix(sharing): Don't ask for guest name on view-only share
Browse files Browse the repository at this point in the history
Signed-off-by: Elizabeth Danzberger <[email protected]>

[skip ci]
  • Loading branch information
elzody authored and backportbot[bot] committed Sep 24, 2024
1 parent 16b8493 commit 9315df9
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 62 deletions.
129 changes: 67 additions & 62 deletions cypress/e2e/share-link.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ import { randHash } from '../utils/index.js'
const shareOwner = new User(randHash(), randHash())
const otherUser = new User(randHash(), randHash())

describe('Public sharing of office documents', function() {

describe('Public sharing of office documents', () => {
before(function() {
cy.createUser(shareOwner)
cy.createUser(otherUser)
Expand All @@ -35,64 +34,58 @@ describe('Public sharing of office documents', function() {
})

const userMatrix = [shareOwner, otherUser]
const guestName = randHash()

describe('Open a shared file', function() {
for (const index in userMatrix) {
const viewingUser = userMatrix[index]
describe('Share with users', () => {
describe('Readonly file', () => {
for (const user of userMatrix) {
it('Loads readonly file as user: ' + user.userId, () => {
cy.shareLink(shareOwner, '/document.odt').then((token) => {
cy.login(user)

it('Loads file as user: ' + viewingUser?.userId, () => {
cy.shareLink(shareOwner, '/document.odt').then((token) => {
cy.login(viewingUser)

cy.visit(`/s/${token}`, {
onBeforeLoad(win) {
cy.spy(win, 'postMessage').as('postMessage')
},
})
cy.visit(`/s/${token}`, {
onBeforeLoad(win) {
cy.spy(win, 'postMessage').as('postMessage')
},
})

cy.waitForCollabora()
cy.waitForPostMessage('App_LoadingStatus', { Status: 'Document_Loaded' })
// Assert that we do not ask for guest name if logged in
cy.get('[data-cy="guestNameModal"]').should('not.exist')

cy.get('@loleafletframe').within(() => {
cy.get('#closebutton').click()
waitForCollabora()
})

cy.get('#viewer', { timeout: 5000 }).should('not.exist')
})
})
}
}
})

it('Loads file as guest: ' + guestName, () => {
cy.shareLink(shareOwner, '/document.odt').then((token) => {
cy.logout()
describe('Editable file', () => {
for (const user of userMatrix) {
it('Loads editable file as user: ' + user.userId, () => {
cy.shareLink(shareOwner, '/document.odt', { permissions: 19 }).then((token) => {
cy.login(user)

cy.visit(`/s/${token}`, {
onBeforeLoad(win) {
cy.spy(win, 'postMessage').as('postMessage')
},
})
cy.visit(`/s/${token}`, {
onBeforeLoad(win) {
cy.spy(win, 'postMessage').as('postMessage')
},
})

cy.inputCollaboraGuestName(guestName)
cy.waitForCollabora()
cy.waitForPostMessage('App_LoadingStatus', { Status: 'Document_Loaded' })
// Assert that we do not ask for guest name if logged in
cy.get('[data-cy="guestNameModal"]').should('not.exist')

cy.get('@loleafletframe').within(() => {
cy.get('#closebutton').click()
waitForCollabora()
})
})

cy.get('#viewer', { timeout: 5000 }).should('not.exist')
})
}
})
})

describe('Open a file in a shared folder', function() {
for (const index in userMatrix) {
const viewingUser = userMatrix[index]
it('Loads file in shared folder as user: ' + viewingUser?.userId, () => {
cy.login(viewingUser)
const guestName = randHash()
describe('Share with guests', () => {
describe('Readonly file', () => {
it('Loads readonly file as guest: ' + guestName, () => {
cy.shareLink(shareOwner, '/document.odt').then((token) => {
cy.logout()

cy.shareLink(shareOwner, '/my-share').then((token) => {
cy.visit(`/s/${token}`, {
onBeforeLoad(win) {
cy.spy(win, 'postMessage').as('postMessage')
Expand All @@ -101,27 +94,27 @@ describe('Public sharing of office documents', function() {

cy.get('tr[data-file="document.odt"] a.name').click()

cy.waitForViewer()
cy.waitForCollabora()
cy.waitForPostMessage('App_LoadingStatus', { Status: 'Document_Loaded' })

cy.get('@loleafletframe').within(() => {
cy.get('#closebutton').click()
})

cy.get('#viewer', { timeout: 5000 }).should('not.exist')
waitForCollabora()
})
})
}
})

it('Loads file in shared folder as guest: ' + guestName, () => {
cy.shareLink(shareOwner, '/my-share').then((token) => {
cy.logout()
describe('Editable file', () => {
it('Loads editable file as guest: ' + guestName, () => {
cy.shareLink(shareOwner, '/document.odt', { permissions: 19 }).then((token) => {
cy.logout()

cy.visit(`/s/${token}`, {
onBeforeLoad(win) {
cy.spy(win, 'postMessage').as('postMessage')
},
cy.visit(`/s/${token}`, {
onBeforeLoad(win) {
cy.spy(win, 'postMessage').as('postMessage')
},
})

// Assert that we do ask for guest name if we can edit as a guest
cy.get('[data-cy="guestNameModal"]').should('be.visible')

cy.inputCollaboraGuestName(guestName)
waitForCollabora()
})

cy.get('tr[data-file="document.odt"] a.name').click()
Expand All @@ -140,3 +133,15 @@ describe('Public sharing of office documents', function() {
})
})
})

function waitForCollabora() {
cy.waitForViewer()
cy.waitForCollabora()
cy.waitForPostMessage('App_LoadingStatus', { Status: 'Document_Loaded' })

cy.get('@loleafletframe').within(() => {
cy.get('#closebutton').click()
})

cy.get('#viewer', { timeout: 5000 }).should('not.exist')
}
4 changes: 4 additions & 0 deletions src/helpers/guestName.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,9 @@ export function shouldAskForGuestName(mimetype, canWrite) {
const noCurrentUser = !getCurrentUser() || getCurrentUser()?.uid === ''
const isReadOnlyPDF = mimetype === 'application/pdf' && !canWrite

if (!canWrite) {
return false
}

return noLoggedInUser && noGuest && noCurrentUser && !isReadOnlyPDF
}

0 comments on commit 9315df9

Please sign in to comment.