Skip to content

Commit

Permalink
Merge pull request #4070 from nextcloud/backport/4048/stable28
Browse files Browse the repository at this point in the history
[stable28] fix(sharing): Don't ask for guest name on view-only share
  • Loading branch information
elzody authored Sep 24, 2024
2 parents 16b8493 + bef85d2 commit d573d45
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 74 deletions.
141 changes: 67 additions & 74 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,108 +34,102 @@ 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')
},
})

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

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

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()
})

cy.visit(`/s/${token}`, {
onBeforeLoad(win) {
cy.spy(win, 'postMessage').as('postMessage')
},
})
describe('Editable file', () => {
it('Loads editable file as guest: ' + guestName, () => {
cy.shareLink(shareOwner, '/document.odt', { permissions: 19 }).then((token) => {
cy.logout()

cy.get('tr[data-file="document.odt"] a.name').click()
cy.visit(`/s/${token}`, {
onBeforeLoad(win) {
cy.spy(win, 'postMessage').as('postMessage')
},
})

cy.inputCollaboraGuestName(guestName)
cy.waitForViewer()
cy.waitForCollabora()
cy.waitForPostMessage('App_LoadingStatus', { Status: 'Document_Loaded' })
// Assert that we do ask for guest name if we can edit as a guest
cy.get('[data-cy="guestNameModal"]').should('be.visible')

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

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

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 d573d45

Please sign in to comment.