Skip to content

Commit c2bfd8b

Browse files
authored
Merge pull request #4048 from nextcloud/fix/guest-name-view-only
fix(sharing): Don't ask for guest name on view-only share
2 parents 462b37c + 256dfa2 commit c2bfd8b

File tree

2 files changed

+71
-75
lines changed

2 files changed

+71
-75
lines changed

cypress/e2e/share-link.js

Lines changed: 67 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ import { randHash } from '../utils/index.js'
88
const shareOwner = new User(randHash(), randHash())
99
const otherUser = new User(randHash(), randHash())
1010

11-
describe('Public sharing of office documents', function() {
12-
11+
describe('Public sharing of office documents', () => {
1312
before(function() {
1413
cy.createUser(shareOwner)
1514
cy.createUser(otherUser)
@@ -20,109 +19,102 @@ describe('Public sharing of office documents', function() {
2019
})
2120

2221
const userMatrix = [shareOwner, otherUser]
23-
const guestName = randHash()
2422

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

29-
it('Loads file as user: ' + viewingUser?.userId, () => {
30-
cy.shareLink(shareOwner, '/document.odt').then((token) => {
31-
cy.login(viewingUser)
32-
33-
cy.visit(`/s/${token}`, {
34-
onBeforeLoad(win) {
35-
cy.spy(win, 'postMessage').as('postMessage')
36-
},
37-
})
30+
cy.visit(`/s/${token}`, {
31+
onBeforeLoad(win) {
32+
cy.spy(win, 'postMessage').as('postMessage')
33+
},
34+
})
3835

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

42-
cy.get('@loleafletframe').within(() => {
43-
cy.get('#closebutton').click()
39+
waitForCollabora()
4440
})
45-
46-
cy.get('#viewer', { timeout: 5000 }).should('not.exist')
4741
})
48-
})
49-
}
42+
}
43+
})
5044

51-
it('Loads file as guest: ' + guestName, () => {
52-
cy.shareLink(shareOwner, '/document.odt').then((token) => {
53-
cy.logout()
45+
describe('Editable file', () => {
46+
for (const user of userMatrix) {
47+
it('Loads editable file as user: ' + user.userId, () => {
48+
cy.shareLink(shareOwner, '/document.odt', { permissions: 19 }).then((token) => {
49+
cy.login(user)
5450

55-
cy.visit(`/s/${token}`, {
56-
onBeforeLoad(win) {
57-
cy.spy(win, 'postMessage').as('postMessage')
58-
},
59-
})
51+
cy.visit(`/s/${token}`, {
52+
onBeforeLoad(win) {
53+
cy.spy(win, 'postMessage').as('postMessage')
54+
},
55+
})
6056

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

65-
cy.get('@loleafletframe').within(() => {
66-
cy.get('#closebutton').click()
60+
waitForCollabora()
61+
})
6762
})
68-
69-
cy.get('#viewer', { timeout: 5000 }).should('not.exist')
70-
})
63+
}
7164
})
7265
})
7366

74-
describe('Open a file in a shared folder', function() {
75-
for (const index in userMatrix) {
76-
const viewingUser = userMatrix[index]
77-
it('Loads file in shared folder as user: ' + viewingUser?.userId, () => {
78-
cy.login(viewingUser)
67+
const guestName = randHash()
68+
describe('Share with guests', () => {
69+
describe('Readonly file', () => {
70+
it('Loads readonly file as guest: ' + guestName, () => {
71+
cy.shareLink(shareOwner, '/document.odt').then((token) => {
72+
cy.logout()
7973

80-
cy.shareLink(shareOwner, '/my-share').then((token) => {
8174
cy.visit(`/s/${token}`, {
8275
onBeforeLoad(win) {
8376
cy.spy(win, 'postMessage').as('postMessage')
8477
},
8578
})
8679

87-
cy.get('button[data-cy-files-list-row-name-link=""]')
88-
.click()
89-
90-
cy.waitForViewer()
91-
cy.waitForCollabora()
92-
cy.waitForPostMessage('App_LoadingStatus', { Status: 'Document_Loaded' })
80+
// Assert that we do not ask for guest name if we can't edit as a guest
81+
cy.get('[data-cy="guestNameModal"]').should('not.exist')
9382

94-
cy.get('@loleafletframe').within(() => {
95-
cy.get('#closebutton').click()
96-
})
97-
98-
cy.get('#viewer', { timeout: 5000 }).should('not.exist')
83+
waitForCollabora()
9984
})
10085
})
101-
}
102-
103-
it('Loads file in shared folder as guest: ' + guestName, () => {
104-
cy.shareLink(shareOwner, '/my-share').then((token) => {
105-
cy.logout()
86+
})
10687

107-
cy.visit(`/s/${token}`, {
108-
onBeforeLoad(win) {
109-
cy.spy(win, 'postMessage').as('postMessage')
110-
},
111-
})
88+
describe('Editable file', () => {
89+
it('Loads editable file as guest: ' + guestName, () => {
90+
cy.shareLink(shareOwner, '/document.odt', { permissions: 19 }).then((token) => {
91+
cy.logout()
11292

113-
cy.get('button[data-cy-files-list-row-name-link=""]').click()
93+
cy.visit(`/s/${token}`, {
94+
onBeforeLoad(win) {
95+
cy.spy(win, 'postMessage').as('postMessage')
96+
},
97+
})
11498

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

120-
cy.get('@loleafletframe').within(() => {
121-
cy.get('#closebutton').click()
102+
cy.inputCollaboraGuestName(guestName)
103+
waitForCollabora()
122104
})
123-
124-
cy.get('#viewer', { timeout: 5000 }).should('not.exist')
125105
})
126106
})
127107
})
128108
})
109+
110+
function waitForCollabora() {
111+
cy.waitForViewer()
112+
cy.waitForCollabora()
113+
cy.waitForPostMessage('App_LoadingStatus', { Status: 'Document_Loaded' })
114+
115+
cy.get('@loleafletframe').within(() => {
116+
cy.get('#closebutton').click()
117+
})
118+
119+
cy.get('#viewer', { timeout: 5000 }).should('not.exist')
120+
}

src/helpers/guestName.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,9 @@ export function shouldAskForGuestName(mimetype, canWrite) {
2121
const noCurrentUser = !getCurrentUser() || getCurrentUser()?.uid === ''
2222
const isReadOnlyPDF = mimetype === 'application/pdf' && !canWrite
2323

24+
if (!canWrite) {
25+
return false
26+
}
27+
2428
return noLoggedInUser && noGuest && noCurrentUser && !isReadOnlyPDF
2529
}

0 commit comments

Comments
 (0)