From 8f63f10aee5abfc0236e783770124fd33308af8e Mon Sep 17 00:00:00 2001 From: Elizabeth Danzberger Date: Tue, 17 Sep 2024 10:50:16 +0200 Subject: [PATCH] feat(sharing): use `@nextcloud/sharing` to detect is public share Signed-off-by: Elizabeth Danzberger --- src/helpers/index.js | 1 - src/helpers/isPublicPage.js | 16 ---------------- src/public.js | 4 ++-- src/view/FilesAppIntegration.js | 13 ++++++------- src/view/Office.vue | 3 ++- 5 files changed, 10 insertions(+), 27 deletions(-) delete mode 100644 src/helpers/isPublicPage.js diff --git a/src/helpers/index.js b/src/helpers/index.js index 9164830e01..7545a9133f 100644 --- a/src/helpers/index.js +++ b/src/helpers/index.js @@ -76,5 +76,4 @@ export { export { default as isDocument } from './isDocument.js' export { default as isPdf } from './isPdf.js' -export { default as isPublic } from './isPublicPage.js' export { default as isDownloadHidden } from './isDownloadHidden.js' diff --git a/src/helpers/isPublicPage.js b/src/helpers/isPublicPage.js deleted file mode 100644 index d53a189dc6..0000000000 --- a/src/helpers/isPublicPage.js +++ /dev/null @@ -1,16 +0,0 @@ -/** - * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors - * SPDX-License-Identifier: AGPL-3.0-or-later - */ -/** - * Determines if the resource is a public share - * @return {boolean} - */ -function isPublic() { - /** @type HTMLInputElement */ - const publicElement = document.getElementById('isPublic') - - return Boolean(publicElement) && publicElement.value === '1' -} - -export default isPublic diff --git a/src/public.js b/src/public.js index ce8e7e8bc4..76660f9b90 100644 --- a/src/public.js +++ b/src/public.js @@ -3,8 +3,8 @@ * SPDX-License-Identifier: AGPL-3.0-or-later */ +import { isPublicShare } from '@nextcloud/sharing/public' import { - isPublic, isPdf, isDocument, isDownloadHidden, @@ -13,7 +13,7 @@ import { getCapabilities } from './services/capabilities.ts' import NewFileMenu from './view/NewFileMenu.js' document.addEventListener('DOMContentLoaded', () => { - if (!isPublic() || !OCA.Viewer) { + if (!isPublicShare() || !OCA.Viewer) { return } diff --git a/src/view/FilesAppIntegration.js b/src/view/FilesAppIntegration.js index 10ec5f37c7..62c229150a 100644 --- a/src/view/FilesAppIntegration.js +++ b/src/view/FilesAppIntegration.js @@ -6,6 +6,7 @@ import { generateUrl } from '@nextcloud/router' import { getCurrentUser } from '@nextcloud/auth' import { getFilePickerBuilder, spawnDialog } from '@nextcloud/dialogs' +import { isPublicShare } from '@nextcloud/sharing/public' import axios from '@nextcloud/axios' import { emit } from '@nextcloud/event-bus' import { getCurrentDirectory } from '../helpers/filesApp.js' @@ -17,8 +18,6 @@ import { } from '@nextcloud/files' import SaveAs from '../components/Modal/SaveAs.vue' -const isPublic = document.getElementById('isPublic') && document.getElementById('isPublic').value === '1' - export default { fileNode: undefined, @@ -126,7 +125,7 @@ export default { return } - if (isPublic) { + if (isPublicShare()) { console.error('[FilesAppIntegration] Sharing is not supported') return } @@ -150,7 +149,7 @@ export default { }, insertGraphic(insertFile) { - if (isPublic) { + if (isPublicShare()) { console.error('[FilesAppIntegration] insertGraphic is not supported') } @@ -322,7 +321,7 @@ export default { } entry.append(label) - const isFileOwner = !isPublic && this.getFileModel() && typeof this.getFileModel().get('shareOwner') === 'undefined' + const isFileOwner = !isPublicShare() && this.getFileModel() && typeof this.getFileModel().get('shareOwner') === 'undefined' const canEdit = this.getFileModel() && !!(this.getFileModel().get('permissions') & OC.PERMISSION_UPDATE) if (isFileOwner && canEdit && !view.IsCurrentView) { const removeButton = $('
') @@ -406,7 +405,7 @@ export default { return } - if (isPublic || !OCA?.Files?.Sidebar) { + if (isPublicShare() || !OCA?.Files?.Sidebar) { console.error('[FilesAppIntegration] Versions are not supported') return } @@ -491,7 +490,7 @@ export default { }, async getFileNode(forceFetch = false) { - if (isPublic) { + if (isPublicShare()) { return } diff --git a/src/view/Office.vue b/src/view/Office.vue index cb1e01ad51..c27480220d 100644 --- a/src/view/Office.vue +++ b/src/view/Office.vue @@ -103,6 +103,7 @@ import { generateUrl, imagePath, } from '@nextcloud/router' +import { isPublicShare } from '@nextcloud/sharing/public' import { getCapabilities } from './../services/capabilities.ts' import { generateCSSVarTokens, @@ -231,7 +232,7 @@ export default { return !!window.TESTING }, isPublic() { - return document.getElementById('isPublic')?.value === '1' + return isPublicShare() }, shareToken() { return getSharingToken()