Skip to content

Commit

Permalink
feat(auth): use @nextcloud/auth to set/get guest name
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 Aug 14, 2024
1 parent 47052e0 commit 0c9eebb
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
6 changes: 3 additions & 3 deletions src/components/GuestNamePicker.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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()
},
},
}
Expand Down
7 changes: 5 additions & 2 deletions src/helpers/guestName.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@
*
*/

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

const cookieAlreadySet = (cookieName) => {
Expand All @@ -39,7 +42,7 @@ const setGuestNameCookie = (username) => {

const shouldAskForGuestName = () => {
const noLoggedInUser = !getLoggedInUser()
const noGuestCookie = !cookieAlreadySet('guestUser')
const noGuest = !getGuestNickname()
const noCurrentUser = !getCurrentUser() || getCurrentUser()?.uid === ''

return noLoggedInUser && noGuestCookie && noCurrentUser
Expand Down
9 changes: 3 additions & 6 deletions src/view/Office.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -191,8 +191,6 @@ export default {
errorType: null,
loadingMsg: null,
guestName: null,
showLinkPicker: false,
showZotero: false,
modified: false,
Expand Down Expand Up @@ -293,8 +291,7 @@ export default {
spawnDialog(GuestNamePicker, {
fileName: basename(this.filename),
onSubmit: async (guestName) => {
this.guestName = guestName
onSubmit: async () => {
await this.load()
},
})
Expand All @@ -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', ''))
Expand Down

0 comments on commit 0c9eebb

Please sign in to comment.