+ {{ t('richdocuments', `Please enter the guest name you wish to use before proceeding to the document.
+ If you don\'t provide one, the default will be used.`) }}
+
+
+
+
+
+
+
+
+
+ {{ t('richdocuments', 'Submit name') }}
+
+
+
+
+
+
+
+
diff --git a/src/document.js b/src/document.js
index b8fbf5fca0..88b2263a0c 100644
--- a/src/document.js
+++ b/src/document.js
@@ -4,10 +4,8 @@ import { generateOcsUrl, getRootUrl, imagePath } from '@nextcloud/router'
import { getRequestToken } from '@nextcloud/auth'
import { loadState } from '@nextcloud/initial-state'
import Config from './services/config.tsx'
-import { setGuestName, shouldAskForGuestName } from './helpers/guestName.js'
import { getUIDefaults, generateCSSVarTokens, getCollaboraTheme } from './helpers/coolParameters.js'
import { enableScrollLock } from './helpers/safariFixer.js'
-
import PostMessageService from './services/postMessage.tsx'
import {
callMobileMessage,
@@ -15,7 +13,6 @@ import {
isMobileInterfaceAvailable,
} from './helpers/mobile.js'
import { getWopiUrl, getSearchParam, getNextcloudUrl } from './helpers/url.js'
-
import '../css/document.scss'
import axios from '@nextcloud/axios'
@@ -92,42 +89,6 @@ const hideLoadingIndicator = () => {
showLoadingIndicator()
-$.widget('oc.guestNamePicker', {
- _create() {
- hideLoadingIndicator()
-
- const text = document.createElement('div')
- text.setAttribute('style', 'margin: 0 auto; margin-top: 100px; text-align: center;')
- text.innerHTML = t('richdocuments', 'Please choose your nickname to continue as guest user.')
-
- const div = document.createElement('div')
- div.setAttribute('style', 'margin: 0 auto; width: 250px; display: flex;')
- const nick = ''
- const btn = ''
- div.innerHTML = nick + btn
-
- $('#documents-content').prepend(div)
- $('#documents-content').prepend(text)
- const setGuestNameSubmit = () => {
- const username = $('#nickname').val()
- div.remove()
- text.innerText = ''
- text.classList.add('icon-loading')
- setGuestName(username).then(() => {
- $('#documents-content').remove()
- documentsMain.initSession()
- })
- }
-
- $('#nickname').keyup(function(event) {
- if (event.which === 13) {
- setGuestNameSubmit()
- }
- })
- $('#btn').click(() => setGuestNameSubmit())
- },
-})
-
/**
* Type definitions for WOPI Post message objects
*
@@ -785,7 +746,7 @@ const documentsMain = {
},
}
-$(document).ready(function() {
+document.addEventListener('DOMContentLoaded', async () => {
if (!OCA.RichDocuments) {
OCA.RichDocuments = {}
@@ -797,12 +758,7 @@ $(document).ready(function() {
OCA.RichDocuments.documentsMain = documentsMain
- if (shouldAskForGuestName()) {
- PostMessages.sendPostMessage('parent', 'NC_ShowNamePicker')
- $('#documents-content').guestNamePicker()
- } else {
- documentsMain.initSession()
- }
+ documentsMain.initSession()
documentsMain.renderComplete = true
const viewport = document.querySelector('meta[name=viewport]')
diff --git a/src/helpers/getLoggedInUser.js b/src/helpers/getLoggedInUser.js
new file mode 100644
index 0000000000..27b97a0c12
--- /dev/null
+++ b/src/helpers/getLoggedInUser.js
@@ -0,0 +1,34 @@
+/**
+ * @copyright Copyright (c) 2024 Elizabeth Danzberger
+ *
+ * @author Elizabeth Danzberger
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see .
+ *
+ */
+
+import { loadState } from '@nextcloud/initial-state'
+
+/**
+ * Gets the current user's display name if logged in.
+ *
+ * @return boolean | string
+ */
+function getLoggedInUser() {
+ return loadState('richdocuments', 'loggedInUser')
+}
+
+export default getLoggedInUser
diff --git a/src/helpers/guestName.js b/src/helpers/guestName.js
index fd650e8fce..a293c74409 100644
--- a/src/helpers/guestName.js
+++ b/src/helpers/guestName.js
@@ -20,54 +20,32 @@
*
*/
-import Config from './../services/config.tsx'
import { getCurrentUser } from '@nextcloud/auth'
-import axios from '@nextcloud/axios'
-import { generateOcsUrl } from '@nextcloud/router'
-import mobile from './mobile.js'
+import getLoggedInUser from '../helpers/getLoggedInUser.js'
-let guestName = ''
-
-const getGuestNameCookie = function() {
- if (guestName === '') {
- const name = 'guestUser='
- const matchedCookie = document.cookie.split(';')
- .map((cookie) => {
- try {
- return decodeURIComponent(cookie.trim())
- } catch (e) {
- return cookie.trim()
- }
- }).find((cookie) => {
- return cookie.indexOf(name) === 0
- })
- guestName = matchedCookie ? matchedCookie.substring(name.length) : ''
- }
- return guestName
+const cookieAlreadySet = (cookieName) => {
+ return document.cookie
+ .split(';')
+ .some(cookie => {
+ return cookie.trim().startsWith(`${cookieName}=`)
+ })
}
-const setGuestName = function(username) {
+const setGuestNameCookie = (username) => {
if (username !== '') {
document.cookie = 'guestUser=' + encodeURIComponent(username) + '; path=/'
- guestName = username
}
- const accessToken = encodeURIComponent(Config.get('token'))
- return axios.post(generateOcsUrl('apps/richdocuments/api/v1/wopi/guestname', 2), {
- access_token: accessToken,
- guestName,
- })
}
const shouldAskForGuestName = () => {
- return (!mobile.isDirectEditing() || Config.get('directGuest'))
- && (!getCurrentUser() || getCurrentUser()?.uid === '')
- && !Config.get('userId')
- && getGuestNameCookie() === ''
- && (Config.get('permissions') & OC.PERMISSION_UPDATE)
+ const noLoggedInUser = !getLoggedInUser()
+ const noGuestCookie = !cookieAlreadySet('guestUser')
+ const noCurrentUser = !getCurrentUser() || getCurrentUser()?.uid === ''
+
+ return noLoggedInUser && noGuestCookie && noCurrentUser
}
export {
- getGuestNameCookie,
- setGuestName,
+ setGuestNameCookie,
shouldAskForGuestName,
}
diff --git a/src/view/Office.vue b/src/view/Office.vue
index 6bf65a8848..8ece06a142 100644
--- a/src/view/Office.vue
+++ b/src/view/Office.vue
@@ -91,7 +91,7 @@
import { NcButton, NcEmptyContent, NcLoadingIcon } from '@nextcloud/vue'
import AlertOctagonOutline from 'vue-material-design-icons/AlertOctagonOutline.vue'
import { loadState } from '@nextcloud/initial-state'
-import { showInfo } from '@nextcloud/dialogs'
+import { showInfo, spawnDialog } from '@nextcloud/dialogs'
import ZoteroHint from '../components/Modal/ZoteroHint.vue'
import { basename, dirname } from 'path'
@@ -123,6 +123,7 @@ import saveAs from '../mixins/saveAs.js'
import uiMention from '../mixins/uiMention.js'
import version from '../mixins/version.js'
import { getCurrentUser } from '@nextcloud/auth'
+import { shouldAskForGuestName } from '../helpers/guestName.js'
const FRAME_DOCUMENT = 'FRAME_DOCUMENT'
@@ -175,6 +176,8 @@ export default {
errorType: null,
loadingMsg: null,
+ guestName: null,
+
showLinkPicker: false,
showZotero: false,
modified: false,
@@ -259,7 +262,21 @@ export default {
}
this.postMessage.registerPostMessageHandler(this.postMessageHandler)
- await this.load()
+ if (shouldAskForGuestName()) {
+ const { default: GuestNamePicker } = await import(
+ /* webpackChunkName: 'GuestNamePicker' */
+ '../components/GuestNamePicker.vue')
+
+ spawnDialog(GuestNamePicker, {
+ fileName: basename(this.filename),
+ onSubmit: async (guestName) => {
+ this.guestName = guestName
+ await this.load()
+ },
+ })
+ } else {
+ await this.load()
+ }
},
beforeDestroy() {
this.postMessage.unregisterPostMessageHandler(this.postMessageHandler)
@@ -273,7 +290,7 @@ export default {
// Generate WOPI token
const { data } = await axios.post(generateUrl('/apps/richdocuments/token'), {
- fileId: fileid, shareToken: this.shareToken, version,
+ fileId: fileid, shareToken: this.shareToken, version, guestName: this.guestName,
})
Config.update('urlsrc', data.urlSrc)