Skip to content
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

fix(public): Use @nextcloud/sharing to detect public shares #6339

Merged
merged 2 commits into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
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/e2e/nodes/CodeBlock.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ describe('Front matter support', function() {
cy.getContent().find('code').eq(1).find('.hljs-keyword').eq(1).contains('function')

// Mermaid diagram
cy.get('#app-content').scrollTo('bottom')
cy.getEditor().scrollTo('bottom')
cy.getContent().find('.split-view__preview').eq(2).should('be.visible')
cy.get('.code-block').eq(2).find('code').should('not.be.visible')
cy.get('.split-view__preview').find('svg .entityTitleText')
Expand Down
6 changes: 3 additions & 3 deletions cypress/e2e/share.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ describe('Open test.md in viewer', function() {
return cy.visit(`/s/${token}`)
})
.then(() => {
cy.openFileInShare('test.md')
cy.openFile('test.md')
cy.getModal().getContent().should('be.visible')
cy.getModal().getContent().should('contain', 'Hello world')
cy.getModal().getContent().find('h2').should('contain', 'Hello world')
Expand All @@ -105,8 +105,8 @@ describe('Open test.md in viewer', function() {
})
})

it('Opens the editor as guest', function() {
cy.shareFile('/test3.md')
it('Opens the editor as guest and set a session username', function() {
cy.shareFile('/test3.md', { edit: true })
.then((token) => {
cy.logout()
cy.visit(`/s/${token}`)
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 0 additions & 6 deletions cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -272,12 +272,6 @@ Cypress.Commands.add('openFile', (fileName, params = {}) => {
cy.get(`[data-cy-files-list] tr[data-cy-files-list-row-name="${fileName}"] [data-cy-files-list-row-name-link]`).click(params)
})

Cypress.Commands.add('openFileInShare', fileName => {
cy.get(`.files-fileList tr[data-file="${CSS.escape(fileName)}"] a.name`).click()
// eslint-disable-next-line
cy.wait(250)
})

Cypress.Commands.add('closeFile', (params = {}) => {
cy.intercept({ method: 'POST', url: '**/apps/text/session/*/close' })
.as('close')
Expand Down
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
Loading