Skip to content

[stable29] fix: guest username not picked up the second time loading a share link #3909

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

Merged
merged 1 commit into from
Aug 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cypress/support/commands.js
Original file line number Diff line number Diff line change
@@ -142,7 +142,7 @@ Cypress.Commands.add('shareLink', (user, path, shareData = {}) => {
})

Cypress.Commands.add('openFile', fileName => {
cy.get(`[data-cy-files-list] tr[data-cy-files-list-row-name="${fileName}"] a[data-cy-files-list-row-name-link]`).click()
cy.get(`[data-cy-files-list-tbody] tr[data-cy-files-list-row-name="${fileName}"] button[data-cy-files-list-row-name-link]`).click()
})

Cypress.Commands.add('nextcloudEnableApp', (appId) => {
129 changes: 90 additions & 39 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -24,7 +24,7 @@
"test:coverage": "NODE_ENV=test jest --coverage"
},
"dependencies": {
"@nextcloud/auth": "^2.2.1",
"@nextcloud/auth": "^2.4.0",
"@nextcloud/axios": "^2.4.0",
"@nextcloud/capabilities": "^1.1.0",
"@nextcloud/dialogs": "^5.2.0",
6 changes: 3 additions & 3 deletions src/components/GuestNamePicker.vue
Original file line number Diff line number Diff line change
@@ -39,10 +39,10 @@
</template>

<script>
import { setGuestNickname } from '@nextcloud/auth'
import { NcButton, NcIconSvgWrapper, NcModal, NcTextField } from '@nextcloud/vue'
import { translate as t } from '@nextcloud/l10n'
import axios from '@nextcloud/axios'
import { setGuestNameCookie } from '../helpers/guestName.js'
export default {
name: 'GuestNamePicker',
@@ -103,10 +103,10 @@ export default {
this.guestName = guestName
},
async submit() {
setGuestNameCookie(this.guestName)
setGuestNickname(this.guestName)
this.show = false
await this.onSubmit(this.guestName)
await this.onSubmit()
},
},
}
37 changes: 14 additions & 23 deletions src/helpers/guestName.js
Original file line number Diff line number Diff line change
@@ -20,32 +20,23 @@
*
*/

import { getCurrentUser } from '@nextcloud/auth'
import {
getCurrentUser,
getGuestNickname,
} from '@nextcloud/auth'
import getLoggedInUser from '../helpers/getLoggedInUser.js'

const cookieAlreadySet = (cookieName) => {
return document.cookie
.split(';')
.some(cookie => {
return cookie.trim().startsWith(`${cookieName}=`)
})
}

const setGuestNameCookie = (username) => {
if (username !== '') {
document.cookie = 'guestUser=' + encodeURIComponent(username) + '; path=/'
}
}

const shouldAskForGuestName = () => {
/**
* Determines if the user should be asked to enter a guest name
*
* @param {string} mimetype - Mimetype of the file
* @param {boolean} canWrite - If write access is granted
*/
export function shouldAskForGuestName(mimetype, canWrite) {
const noLoggedInUser = !getLoggedInUser()
const noGuestCookie = !cookieAlreadySet('guestUser')
const noGuest = !getGuestNickname()
const noCurrentUser = !getCurrentUser() || getCurrentUser()?.uid === ''
const isReadOnlyPDF = mimetype === 'application/pdf' && !canWrite

return noLoggedInUser && noGuestCookie && noCurrentUser
}

export {
setGuestNameCookie,
shouldAskForGuestName,
return noLoggedInUser && noGuest && noCurrentUser && !isReadOnlyPDF
}
9 changes: 3 additions & 6 deletions src/view/Office.vue
Original file line number Diff line number Diff line change
@@ -132,7 +132,7 @@ import pickLink from '../mixins/pickLink.js'
import saveAs from '../mixins/saveAs.js'
import uiMention from '../mixins/uiMention.js'
import version from '../mixins/version.js'
import { getCurrentUser } from '@nextcloud/auth'
import { getCurrentUser, getGuestNickname } from '@nextcloud/auth'
import { shouldAskForGuestName } from '../helpers/guestName.js'

const FRAME_DOCUMENT = 'FRAME_DOCUMENT'
@@ -191,8 +191,6 @@ export default {
errorType: null,
loadingMsg: null,

guestName: null,

showLinkPicker: false,
showZotero: false,
modified: false,
@@ -293,8 +291,7 @@ export default {

spawnDialog(GuestNamePicker, {
fileName: basename(this.filename),
onSubmit: async (guestName) => {
this.guestName = guestName
onSubmit: async () => {
await this.load()
},
})
@@ -314,7 +311,7 @@ export default {

// Generate WOPI token
const { data } = await axios.post(generateUrl('/apps/richdocuments/token'), {
fileId: fileid, shareToken: this.shareToken, version, guestName: this.guestName,
fileId: fileid, shareToken: this.shareToken, version, guestName: getGuestNickname(),
})
Config.update('urlsrc', data.urlSrc)
Config.update('wopi_callback_url', loadState('richdocuments', 'wopi_callback_url', ''))

Unchanged files with check annotations Beta

})
// fileupload plugin
$('#richdocuments-templates').fileupload({

Check warning on line 101 in src/admin.js

GitHub Actions / NPM lint

The global property or function $ was deprecated in Nextcloud 19.0.0
dataType: 'json',
url: generateUrl('apps/richdocuments/template'),
type: 'POST',
const checkProxyStatus = () => {
checkingProxyStatus = true
const url = Config.get('urlsrc').slice(0, Config.get('urlsrc').indexOf('proxy.php') + 'proxy.php'.length)
$.get(url + '?status').done(function(val) {

Check warning on line 35 in src/document.js

GitHub Actions / NPM lint

The global property or function $ was deprecated in Nextcloud 19.0.0
if (val && val.status && val.status !== 'OK') {
if (val.status === 'starting' || val.status === 'stopped') {
document.getElementById('proxyLoadingIcon').classList.add('icon-loading-small')
showViewer(fileId, title) {
// remove previous viewer, if open, and set a new one
if (documentsMain.isViewerMode) {
$('#revViewer').remove()

Check warning on line 148 in src/document.js

GitHub Actions / NPM lint

The global property or function $ was deprecated in Nextcloud 19.0.0
$('#revViewerContainer').prepend($('<div id="revViewer">'))

Check warning on line 149 in src/document.js

GitHub Actions / NPM lint

The global property or function $ was deprecated in Nextcloud 19.0.0

Check warning on line 149 in src/document.js

GitHub Actions / NPM lint

The global property or function $ was deprecated in Nextcloud 19.0.0
}
const urlsrc = getWopiUrl({ fileId, title, readOnly: true, closeButton: !documentsMain.hideCloseButton })
// iframe that contains the Collabora Online Viewer
const frame = '<iframe data-cy="coolframe" id="loleafletframe" name="loleafletframe_viewer" allowfullscreen allow="clipboard-read *; clipboard-write *" nonce="' + btoa(getRequestToken()) + '" style="width:100%;height:100%;position:absolute;" title="' + loadState('richdocuments', 'productName', 'Nextcloud Office') + '"/>'
$('#revViewer').append(form)

Check warning on line 172 in src/document.js

GitHub Actions / NPM lint

The global property or function $ was deprecated in Nextcloud 19.0.0
$('#revViewer').append(frame)

Check warning on line 173 in src/document.js

GitHub Actions / NPM lint

The global property or function $ was deprecated in Nextcloud 19.0.0
$('#loleafletframe_viewer').focus()

Check warning on line 174 in src/document.js

GitHub Actions / NPM lint

The global property or function $ was deprecated in Nextcloud 19.0.0
// submit that
$('#loleafletform_viewer').submit()

Check warning on line 177 in src/document.js

GitHub Actions / NPM lint

The global property or function $ was deprecated in Nextcloud 19.0.0
documentsMain.isViewerMode = true
// for closing revision mode
$('#revViewerContainer .closeButton').click(function(e) {

Check warning on line 180 in src/document.js

GitHub Actions / NPM lint

The global property or function $ was deprecated in Nextcloud 19.0.0
e.preventDefault()
documentsMain.onCloseViewer()
})