Skip to content

A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.

feat: configuration to disable sharing actions (#5432)

Kyrre Wahl Kongsgård32d5e7bb8e80
diff --git a/frontend/src/components/editor/actions/useNotebookActions.tsx b/frontend/src/components/editor/actions/useNotebookActions.tsx
index ac270e3e49..da860519ef 100644
--- a/frontend/src/components/editor/actions/useNotebookActions.tsx
+++ b/frontend/src/components/editor/actions/useNotebookActions.tsx
@@ -55,6 +55,7 @@ import {
useCellActions,
} from "@/core/cells/cells";
import { disabledCellIds, enabledCellIds } from "@/core/cells/utils";
+import { useResolvedMarimoConfig } from "@/core/config/config";
import { Constants } from "@/core/constants";
import { useLayoutActions, useLayoutState } from "@/core/layout/layout";
import { useTogglePresenting } from "@/core/layout/useTogglePresenting";
@@ -99,6 +100,7 @@ export function useNotebookActions() {
const [viewState] = useAtom(viewStateAtom);
const kioskMode = useAtomValue(kioskModeAtom);
const hideAllMarkdownCode = useHideAllMarkdownCode();
+ const [resolvedConfig] = useResolvedMarimoConfig();
const {
updateCellConfig,
@@ -122,6 +124,10 @@ export function useNotebookActions() {
const { setLayoutView } = useLayoutActions();
const togglePresenting = useTogglePresenting();
+ // Fallback: if sharing is undefined, both are enabled by default
+ const sharingHtmlEnabled = resolvedConfig.sharing?.html ?? true;
+ const sharingWasmEnabled = resolvedConfig.sharing?.wasm ?? true;
+
const renderCheckboxElement = (checked: boolean) => (
<div className="w-8 flex justify-end">
{checked && <CheckIcon size={14} />}
@@ -133,10 +139,12 @@ export function useNotebookActions() {
icon: <Share2Icon size={14} strokeWidth={1.5} />,
label: "Share",
handle: NOOP_HANDLER,
+ hidden: !sharingHtmlEnabled && !sharingWasmEnabled,
dropdown: [
{
icon: <GlobeIcon size={14} strokeWidth={1.5} />,
label: "Publish HTML to web",
+ hidden: !sharingHtmlEnabled,
handle: async () => {
openModal(<ShareStaticNotebookModal onClose={closeModal} />);
},
@@ -144,6 +152,7 @@ export function useNotebookActions() {
{
icon: <LinkIcon size={14} strokeWidth={1.5} />,
label: "Create WebAssembly link",
+ hidden: !sharingWasmEnabled,
handle: async () => {
const code = await readCode();
const url = createShareableLink({ code: code.contents });
@@ -536,5 +545,15 @@ export function useNotebookActions() {
},
];
- return actions.filter((a) => !a.hidden);
+ return actions
+ .filter((a) => !a.hidden)
+ .map((action) => {
+ if (action.dropdown) {
+ return {
+ ...action,
+ dropdown: action.dropdown.filter((item) => !item.hidden),
+ };
+ }
+ return action;
+ });
}
diff --git a/frontend/src/core/config/config-schema.ts b/frontend/src/core/config/config-schema.ts
index 85668926c4..6a703aa1ce 100644
--- a/frontend/src/core/config/config-schema.ts
+++ b/frontend/src/core/config/config-schema.ts
@@ -163,6 +163,13 @@ export const UserConfigSchema = z
.passthrough()
.default({}),
server: z.object({}).passthrough().default({}),
+ sharing: z
+ .object({
+ html: z.boolean(),
+ wasm: z.boolean(),
+ })
+ .passthrough()
+ .optional(),
})
// Pass through so that we don't remove any extra keys that the user has added
.passthrough()
diff --git a/marimo/_config/config.py b/marimo/_config/config.py
index 9d9584551e..65445fa4d4 100644
--- a/marimo/_config/config.py
+++ b/marimo/_config/config.py
@@ -383,6 +383,21 @@ class DatasourcesConfig(TypedDict):
auto_discover_columns: NotRequired[Union[bool, Literal["auto"]]]
+@mddoc
+@dataclass
+class SharingConfig(TypedDict):
+ """Configuration for sharing features.
+
+ **Keys.**
+
+ - `html`: if `False`, HTML sharing options will be hidden from the UI
+ - `wasm`: if `False`, WebAssembly sharing options will be hidden from the UI
+ """
+
+ html: bool
+ wasm: bool
+
+
@mddoc
@dataclass
class MarimoConfig(TypedDict):
@@ -402,6 +417,7 @@ class MarimoConfig(TypedDict):
experimental: NotRequired[dict[str, Any]]
snippets: NotRequired[SnippetsConfig]
datasources: NotRequired[DatasourcesConfig]
+ sharing: NotRequired[SharingConfig]
@mddoc
@@ -423,6 +439,7 @@ class PartialMarimoConfig(TypedDict, total=False):
experimental: NotRequired[dict[str, Any]]
snippets: SnippetsConfig
datasources: NotRequired[DatasourcesConfig]
+ sharing: NotRequired[SharingConfig]
DEFAULT_CONFIG: MarimoConfig = {
diff --git a/openapi/api.yaml b/openapi/api.yaml
index 4d72cee2d9..0cb6fded9a 100644
--- a/openapi/api.yaml
+++ b/openapi/api.yaml
@@ -1725,6 +1725,16 @@ components:
- browser
- follow_symlink
type: object
+ sharing:
+ properties:
+ html:
+ type: boolean
+ wasm:
+ type: boolean
+ required:
+ - html
+ - wasm
+ type: object
snippets:
properties:
custom_paths:
diff --git a/openapi/src/api.ts b/openapi/src/api.ts
index 7a880d5597..e24fe51171 100644
--- a/openapi/src/api.ts
+++ b/openapi/src/api.ts
@@ -3255,6 +3255,10 @@ export interface components {
browser: "default" | string;
follow_symlink: boolean;
};
+ sharing?: {
+ html: boolean;
+ wasm: boolean;
+ };
snippets?: {
custom_paths?: string[];
include_default_snippets?: boolean;