From b58f67cba342560d0ad1fa39a305415f4aa8f5f1 Mon Sep 17 00:00:00 2001 From: Alexander Ackermann Date: Fri, 9 Oct 2026 21:37:31 +0200 Subject: [PATCH] fix: no image from the cloud in the text editor on public links On public links the file picker only shows the shared files, for links to a single file just the edited file itself, so there is nothing to pick. --- .../src/editor/composables/useEditorActions.ts | 12 +++++++++--- .../editor/composables/useEditorActions.spec.ts | 17 ++++++++++++++++- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/packages/web-pkg/src/editor/composables/useEditorActions.ts b/packages/web-pkg/src/editor/composables/useEditorActions.ts index 0dbf5c56aa2..1d8158af1a1 100644 --- a/packages/web-pkg/src/editor/composables/useEditorActions.ts +++ b/packages/web-pkg/src/editor/composables/useEditorActions.ts @@ -6,7 +6,7 @@ import { useGettext } from 'vue3-gettext' import { storeToRefs } from 'pinia' import type { Resource } from '@opencloud-eu/web-client' import { OcEmojiPicker } from '@opencloud-eu/design-system/components' -import { useModals, useThemeStore } from '../../composables' +import { useAuthStore, useModals, useThemeStore } from '../../composables' import { useClientService, useGetMatchingSpace, useFolderLink } from '../../composables' import FilePickerModal from '../../components/Modals/FilePickerModal.vue' import EmojiPickerModal from '../../components/Modals/EmojiPickerModal.vue' @@ -66,6 +66,8 @@ export function useEditorActions(state: TextEditorState) { const { dispatchModal } = useModals() const themeStore = useThemeStore() const { currentTheme } = storeToRefs(themeStore) + // On public links, the file picker only shows the shared files. + const { publicLinkContextReady: isPublicLinkContext } = storeToRefs(useAuthStore()) const clientService = useClientService() const { getMatchingSpace } = useGetMatchingSpace() const { getParentFolderLink } = useFolderLink() @@ -738,7 +740,7 @@ export function useEditorActions(state: TextEditorState) { description: $gettext('Insert an image from your cloud files'), icon: 'cloud-line', keywords: ['image', 'picture', 'cloud'], - showInSlashCommands: true, + showInSlashCommands: !unref(isPublicLinkContext), showInToolbar: false, toolbarAction: (editor) => openCloudImagePicker(editor), slashCommandAction: ({ editor, range }) => { @@ -754,7 +756,11 @@ export function useEditorActions(state: TextEditorState) { icon: 'image-line', keywords: ['image', 'picture', 'upload', 'url', 'cloud'], showInSlashCommands: false, - childActions: [imageUpload(), imageUrl(), imageCloud()], + childActions: [ + imageUpload(), + imageUrl(), + ...(unref(isPublicLinkContext) ? [] : [imageCloud()]) + ], isActive: () => false }) diff --git a/packages/web-pkg/tests/unit/editor/composables/useEditorActions.spec.ts b/packages/web-pkg/tests/unit/editor/composables/useEditorActions.spec.ts index 3d55a7303b6..c74bc969365 100644 --- a/packages/web-pkg/tests/unit/editor/composables/useEditorActions.spec.ts +++ b/packages/web-pkg/tests/unit/editor/composables/useEditorActions.spec.ts @@ -20,7 +20,7 @@ import { useEditorActions } from '../../../../src/editor/composables/useEditorAc import type { TextEditorLinkPanelRequest, TextEditorState } from '../../../../src/editor/types' import type { Resource } from '@opencloud-eu/web-client' import { createTestingPinia } from '@opencloud-eu/web-test-helpers' -import { useModals } from '../../../../src/composables/piniaStores' +import { useAuthStore, useModals } from '../../../../src/composables/piniaStores' import { createLinkExtension } from '../../../../src/editor/extensions/link' function createState(): TextEditorState { @@ -1090,6 +1090,21 @@ describe('useEditorActions', () => { expect(childIds).toEqual(['image-upload', 'image-url', 'image-cloud']) }) + it('hides the cloud action on public links', () => { + const authStore = useAuthStore() + authStore.setPublicLinkContext({ + publicLinkContextReady: true, + publicLinkToken: 'token', + publicLinkPassword: '', + publicLinkType: 'public-link' + }) + const publicLinkActions = useEditorActions(createState()) + + const childIds = publicLinkActions.image().childActions?.map(({ id }) => id) || [] + expect(childIds).toEqual(['image-upload', 'image-url']) + expect(publicLinkActions.imageCloud().showInSlashCommands).toBe(false) + }) + it('provides "Insert from cloud" action for current resource', () => { const cloudState = createState() const cloudActions = useEditorActions(cloudState)