Skip to content

Commit

Permalink
fix(public): Use @nextcloud/sharing to detect public shares
Browse files Browse the repository at this point in the history
Fixes: #6324

Signed-off-by: Jonas <[email protected]>
  • Loading branch information
mejo- committed Sep 9, 2024
1 parent 259be3d commit 122ba83
Show file tree
Hide file tree
Showing 8 changed files with 11 additions and 17 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"@nextcloud/moment": "^1.3.1",
"@nextcloud/notify_push": "^1.3.0",
"@nextcloud/router": "^3.0.1",
"@nextcloud/sharing": "^0.2.3",
"@nextcloud/vue": "^8.17.1",
"@quartzy/markdown-it-mentions": "^0.2.0",
"@tiptap/core": "^2.6.6",
Expand Down
3 changes: 2 additions & 1 deletion src/components/Editor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
import Vue, { ref, set, watch } from 'vue'
import { getCurrentUser } from '@nextcloud/auth'
import { loadState } from '@nextcloud/initial-state'
import { isPublicShare } from '@nextcloud/sharing/public'
import { emit, subscribe, unsubscribe } from '@nextcloud/event-bus'
import { Collaboration } from '@tiptap/extension-collaboration'
import Autofocus from '../extensions/Autofocus.js'
Expand Down Expand Up @@ -269,7 +270,7 @@ export default {
return this.fileId || this.shareToken || this.initialSession
},
isPublic() {
return this.isDirectEditing || (document.getElementById('isPublic') && document.getElementById('isPublic').value === '1')
return this.isDirectEditing || isPublicShare()
},
isRichEditor() {
return loadState('text', 'rich_editing_enabled', true) && this.mime === 'text/markdown'
Expand Down
2 changes: 1 addition & 1 deletion src/components/ViewerComponent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@
<script>
import Vue from 'vue'
import axios from '@nextcloud/axios'
import { getSharingToken } from '@nextcloud/sharing/public'
import PencilIcon from 'vue-material-design-icons/Pencil.vue'
import NcButton from '@nextcloud/vue/dist/Components/NcButton.js'
import PlainTextReader from './PlainTextReader.vue'
import MarkdownContentEditor from './Editor/MarkdownContentEditor.vue'
import { translate, translatePlural } from '@nextcloud/l10n'
import { getSharingToken } from '../helpers/token.js'
import getEditorInstance from './Editor.singleton.js'
Vue.prototype.t = translate
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@

import { getCurrentUser } from '@nextcloud/auth'
import { showSuccess, showError } from '@nextcloud/dialogs'
import { getSharingToken } from '@nextcloud/sharing/public'
import { emit } from '@nextcloud/event-bus'
import { Header, addNewFileMenuEntry, Permission, File, NewMenuEntryCategory } from '@nextcloud/files'
import { loadState } from '@nextcloud/initial-state'
import { imagePath } from '@nextcloud/router'
import { dirname } from 'path'

import { getSharingToken } from './token.js'
import { openMimetypes } from './mime.js'
import store from '../store/index.js'
import axios from '@nextcloud/axios'
Expand Down
10 changes: 0 additions & 10 deletions src/helpers/token.js

This file was deleted.

3 changes: 2 additions & 1 deletion src/public.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/

import { loadState } from '@nextcloud/initial-state'
import { getSharingToken } from '@nextcloud/sharing/public'
// eslint-disable-next-line import/no-unresolved, n/no-missing-import
import 'vite/modulepreload-polyfill'

Expand Down Expand Up @@ -134,7 +135,7 @@ const loadEditor = ({ sharingToken, mimetype, fileId, $el }) => {
}

documentReady(() => {
const sharingToken = document.getElementById('sharingToken') ? document.getElementById('sharingToken').value : null
const sharingToken = getSharingToken()

if (!sharingToken) {
return
Expand Down
5 changes: 3 additions & 2 deletions src/views/RichWorkspace.vue
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,11 @@
import axios from '@nextcloud/axios'
import { generateOcsUrl } from '@nextcloud/router'
import { subscribe, unsubscribe } from '@nextcloud/event-bus'
import { getSharingToken, isPublicShare } from '@nextcloud/sharing/public'
import getEditorInstance from '../components/Editor.singleton.js'
import RichTextReader from '../components/RichTextReader.vue'
const IS_PUBLIC = !!(document.getElementById('isPublic'))
const IS_PUBLIC = isPublicShare()
const WORKSPACE_URL = generateOcsUrl('apps/text' + (IS_PUBLIC ? '/public' : '') + '/workspace', 2)
const SUPPORTED_STATIC_FILENAMES = ['Readme.md', 'README.md', 'readme.md']
Expand Down Expand Up @@ -77,7 +78,7 @@ export default {
},
computed: {
shareToken() {
return document.getElementById('sharingToken')?.value
return getSharingToken()
},
},
watch: {
Expand Down

0 comments on commit 122ba83

Please sign in to comment.