#1 PDF Application on GitHub that lets you edit PDFs on any device anywhere
TypeScript dockerhacktoberfestjavapdfpdf-converterpdf-editorpdf-manipulationpdf-mergerpdf-ocrpdf-toolspdf-web-appspdfmergerself-hosted
Hide save-to-server and sharing controls from guest accounts (#8230)
Anthony Stirling7663117ff893
diff --git a/frontend/src/editor/core/components/fileEditor/FileEditorThumbnail.tsx b/frontend/src/editor/core/components/fileEditor/FileEditorThumbnail.tsxindex abcdbddf25..8acf927e17 100644--- a/frontend/src/editor/core/components/fileEditor/FileEditorThumbnail.tsx+++ b/frontend/src/editor/core/components/fileEditor/FileEditorThumbnail.tsx@@ -39,6 +39,7 @@ import UploadToServerModal from "@editor/components/shared/UploadToServerModal";import ShareFileModal from "@editor/components/shared/ShareFileModal";import { VersionHistoryModal } from "@editor/components/filesPage/VersionHistoryModal";import { useAppConfig } from "@editor/contexts/AppConfigContext";+import { useAuth } from "@editor/auth/UseSession";import { useFileThumbnail } from "@editor/hooks/useFileThumbnail";import { usePdfAccess } from "@editor/hooks/usePdfAccess";import { Tooltip as StirlingTooltip } from "@editor/components/shared/Tooltip";@@ -86,6 +87,7 @@ const FileEditorThumbnail = ({? t("files.notIncludedInToolRun", "Not included in this tool run"): undefined;const { config } = useAppConfig();+ const { isAnonymous } = useAuth();const terminology = useFileActionTerminology();const icons = useFileActionIcons();const {@@ -150,7 +152,8 @@ const FileEditorThumbnail = ({const isCBZ = extLower === "cbz";const isCBR = extLower === "cbr";- const uploadEnabled = config?.storageEnabled === true;+ // Guests have no server storage to save or share into.+ const uploadEnabled = config?.storageEnabled === true && !isAnonymous;const sharingEnabled =uploadEnabled && config?.storageSharingEnabled === true;const shareLinksEnabled =diff --git a/frontend/src/editor/core/components/filesPage/FileDetailsActions.tsx b/frontend/src/editor/core/components/filesPage/FileDetailsActions.tsxindex 8b088b33e4..7a42ecb2d0 100644--- a/frontend/src/editor/core/components/filesPage/FileDetailsActions.tsx+++ b/frontend/src/editor/core/components/filesPage/FileDetailsActions.tsx@@ -3,6 +3,7 @@ import { useTranslation } from "react-i18next";import { Button } from "@editor/ui/Button";import { ActionIcon } from "@editor/ui/ActionIcon";import { Icon } from "@editor/ui/Icon";+import { useAuth } from "@editor/auth/UseSession";import { isBrowserOnlyFile } from "@editor/components/filesPage/fileOrigin";import { FileId } from "@editor/types/file";import { StirlingFileStub } from "@editor/types/fileContext";@@ -45,6 +46,14 @@ export function FileDetailsActions({onShare,}: FileDetailsActionsProps) {const { t } = useTranslation();+ const { isAnonymous } = useAuth();+ // Guests are off because they have no server storage, not because sharing is off.+ const shareDisabledHint = isAnonymous+ ? t("filesPage.signInRequired", "Sign in to use cloud storage.")+ : t(+ "filesPage.shareDisabledHint",+ "File sharing isn't enabled on this server. Ask your admin to enable it.",+ );const addLabel =fileCount === 1@@ -95,10 +104,7 @@ export function FileDetailsActions({{/* Keep sharing discoverable when server settings disable it. */}{single && (<Tooltip- label={t(- "filesPage.shareDisabledHint",- "File sharing isn't enabled on this server. Ask your admin to enable it.",- )}+ label={shareDisabledHint}disabled={sharingEnabled}withinPortalmultilinediff --git a/frontend/src/editor/core/hooks/useSharingEnabled.test.ts b/frontend/src/editor/core/hooks/useSharingEnabled.test.tsnew file mode 100644index 0000000000..1433ac49e3--- /dev/null+++ b/frontend/src/editor/core/hooks/useSharingEnabled.test.ts@@ -0,0 +1,34 @@+import { describe, it, expect, vi, beforeEach } from "vitest";+import { renderHook } from "@testing-library/react";+import { useSharingEnabled } from "@editor/hooks/useSharingEnabled";++vi.mock("@editor/contexts/AppConfigContext", () => ({+ useAppConfig: () => ({+ config: { storageSharingEnabled: true, storageShareLinksEnabled: true },+ }),+}));+const authState = vi.hoisted(() => ({ isAnonymous: false }));+vi.mock("@editor/auth/UseSession", () => ({ useAuth: () => authState }));++describe("useSharingEnabled", () => {+ beforeEach(() => {+ authState.isAnonymous = false;+ });++ it("follows the server config for an account", () => {+ const { result } = renderHook(() => useSharingEnabled());+ expect(result.current).toEqual({+ sharingEnabled: true,+ shareLinksEnabled: true,+ });+ });++ it("is off for a guest", () => {+ authState.isAnonymous = true;+ const { result } = renderHook(() => useSharingEnabled());+ expect(result.current).toEqual({+ sharingEnabled: false,+ shareLinksEnabled: false,+ });+ });+});diff --git a/frontend/src/editor/core/hooks/useSharingEnabled.ts b/frontend/src/editor/core/hooks/useSharingEnabled.tsindex 59f321aa42..42cfe3dc05 100644--- a/frontend/src/editor/core/hooks/useSharingEnabled.ts+++ b/frontend/src/editor/core/hooks/useSharingEnabled.ts@@ -1,4 +1,5 @@import { useAppConfig } from "@editor/contexts/AppConfigContext";+import { useAuth } from "@editor/auth/UseSession";export interface SharingEnabledResult {sharingEnabled: boolean;@@ -7,12 +8,15 @@ export interface SharingEnabledResult {/*** Returns whether file-sharing features are available.- * Core implementation reads directly from server config.+ * Core implementation reads server config and turns it off for guests.*/export function useSharingEnabled(): SharingEnabledResult {const { config } = useAppConfig();+ // Sharing needs server storage, which guests do not have.+ const { isAnonymous } = useAuth();return {- sharingEnabled: config?.storageSharingEnabled === true,- shareLinksEnabled: config?.storageShareLinksEnabled === true,+ sharingEnabled: !isAnonymous && config?.storageSharingEnabled === true,+ shareLinksEnabled:+ !isAnonymous && config?.storageShareLinksEnabled === true,};}