The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:
TypeScript analyticsbibusiness-intelligencebusinessintelligenceclojuredashboarddatadata-analysisdata-visualizationdatabasemetabasemysqlpostgrespostgresqlreportingslacksql-editorvisualization
Support env variables for remote-sync configuration (#68583)
Nathan Voxlandf0efbb36a80d
diff --git a/.clj-kondo/config/modules/config.edn b/.clj-kondo/config/modules/config.ednindex 13b34510d3c..ef1e20e8446 100644--- a/.clj-kondo/config/modules/config.edn+++ b/.clj-kondo/config/modules/config.edn@@ -3079,6 +3079,7 @@modelspremium-featuressettings+ startuptasktask-historyutildiff --git a/enterprise/backend/src/metabase_enterprise/remote_sync/init.clj b/enterprise/backend/src/metabase_enterprise/remote_sync/init.cljindex 6d5b3d3f4c2..03516243612 100644--- a/enterprise/backend/src/metabase_enterprise/remote_sync/init.clj+++ b/enterprise/backend/src/metabase_enterprise/remote_sync/init.clj@@ -1,10 +1,16 @@(ns metabase-enterprise.remote-sync.init(:require[clojure.java.io :as io]+ [clojure.string :as str][metabase-enterprise.remote-sync.events]- [metabase-enterprise.remote-sync.settings]+ [metabase-enterprise.remote-sync.impl :as impl]+ [metabase-enterprise.remote-sync.models.remote-sync-object :as remote-sync.object]+ [metabase-enterprise.remote-sync.settings :as settings][metabase-enterprise.remote-sync.task.import]- [metabase-enterprise.remote-sync.task.table-cleanup])+ [metabase-enterprise.remote-sync.task.table-cleanup]+ [metabase.collections.models.collection :as collection]+ [metabase.startup.core :as startup]+ [metabase.util.log :as log])(:import(org.eclipse.jgit.storage.file FileBasedConfig)(org.eclipse.jgit.util FS SystemReader SystemReader$Delegate)))@@ -32,4 +38,30 @@(load [] nil)(save [] nil))))))+(defn- remote-sync-init []+ (if (settings/remote-sync-enabled)+ (do+ (when (= :read-only (settings/remote-sync-type))+ (let [branch (settings/remote-sync-branch)]+ (when (str/blank? branch)+ (throw (ex-info "Remote sync is enabled with read-only type, but no branch is set." {})))+ (when (remote-sync.object/dirty?)+ (if (str/includes? (settings/remote-sync-allow) "overwrite-unpublished")+ (impl/async-import! branch true {})+ (throw (ex-info "Remote sync is enabled with read-only type, but there are unpublished changes. To force an overwrite, set `MB_REMOTE_SYNC_ALLOW=overwrite-unpublished`" {}))))))++ (when-not (collection/has-remote-synced-collection?)+ (if (nil? (settings/remote-sync-branch))+ (log/warn "Remote sync is enabled but no remote-sync branch is set. Cannot do initial import.")+ (do+ (log/info "Remote sync is enabled but no remote-sync collection exists. Importing")+ (impl/async-import! (settings/remote-sync-branch) true {})))))+ (when (collection/has-remote-synced-collection?)+ (log/info "Remote sync is disabled but a remote-synced collection exists. Marking collections as not remote-sync.")+ (collection/clear-remote-synced-collection!))))+(SystemReader/setInstance (create-isolated-system-reader))++(defmethod startup/def-startup-logic! ::remote-sync-setup+ [_]+ (remote-sync-init))diff --git a/enterprise/backend/src/metabase_enterprise/remote_sync/settings.clj b/enterprise/backend/src/metabase_enterprise/remote_sync/settings.cljindex abff003cc9d..34a5359a7ee 100644--- a/enterprise/backend/src/metabase_enterprise/remote_sync/settings.clj+++ b/enterprise/backend/src/metabase_enterprise/remote_sync/settings.clj@@ -26,7 +26,7 @@:visibility :admin:encryption :no:export? false- :can-read-from-env? false)+ :can-read-from-env? true)(defsetting remote-sync-token(deferred-tru "An Authorization Bearer token allowing access to the git repo over HTTP")@@ -37,15 +37,15 @@:sensitive? true:encryption :when-encryption-key-set:audit :getter- :can-read-from-env? false)+ :can-read-from-env? true)(defsetting remote-sync-url- (deferred-tru "The location of your git repository, e.g. https://git-host.example.com/yourcompany/repo.git")+ (deferred-tru "The location of your git repository, e.g. https://github.com/acme-inco/metabase.git"):type :string:visibility :admin:encryption :no:export? false- :can-read-from-env? false)+ :can-read-from-env? true)(defsetting remote-sync-type(deferred-tru "Git synchronization type - :read-write or :read-only")@@ -62,7 +62,7 @@{:value new-value:options (seq valid-types)})))](setting/set-value-of-type! :keyword :remote-sync-type value)))- :can-read-from-env? false)+ :can-read-from-env? true)(defsetting remote-sync-auto-import(deferred-tru "Whether to automatically import from the remote git repository. Only applies if remote-sync-type is :read-only.")@@ -185,6 +185,14 @@(when (and (= :read-only remote-sync-type) (not (str/blank? remote-sync-branch)) (not (some #{remote-sync-branch} (git/branches source))))(throw (ex-info "Invalid branch name" {:url remote-sync-url :branch remote-sync-branch}))))))+(defsetting remote-sync-allow+ (deferred-tru "Allow specific remote sync behaviors. Set to overwrite-unpublished to allow overwriting unpublished changes on startup.")+ :type :string+ :visibility :internal+ :export? false+ :encryption :no+ :doc false)+(defn check-and-update-remote-settings!"Validates and updates git sync settings in the application database.@@ -198,21 +206,29 @@Throws ExceptionInfo if the git settings are invalid or if unable to connect to the repository."[{:keys [remote-sync-url remote-sync-token] :as settings}](let [git-related-keys #{:remote-sync-url :remote-sync-token :remote-sync-type :remote-sync-branch}- updating-git-settings? (some git-related-keys (keys settings))]+ updating-git-settings? (some git-related-keys (keys settings))+ env-set-url (= :env (setting/get-raw-value-source :remote-sync-url))+ env-set-token (= :env (setting/get-raw-value-source :remote-sync-token))+ env-set-branch (= :env (setting/get-raw-value-source :remote-sync-branch))](if (and (contains? settings :remote-sync-url)(str/blank? remote-sync-url))(t2/with-transaction [_conn]- (setting/set! :remote-sync-url nil)- (setting/set! :remote-sync-token nil)- (setting/set! :remote-sync-branch nil))- (let [current-token (setting/get :remote-sync-token)- obfuscated? (= remote-sync-token (setting/obfuscate-value current-token))- token-to-check (if obfuscated? current-token remote-sync-token)]+ (when-not env-set-url+ (setting/set! :remote-sync-url nil))+ (when-not env-set-token+ (setting/set! :remote-sync-token nil))+ (when-not env-set-branch+ (setting/set! :remote-sync-branch nil)))+ (let [current-token (setting/get :remote-sync-token)+ obfuscated? (= remote-sync-token (setting/obfuscate-value current-token))+ token-to-check (if env-set-token+ (setting/get :remote-sync-token)+ (if obfuscated? current-token remote-sync-token))](when updating-git-settings?(check-git-settings! (assoc settings :remote-sync-token token-to-check)))(t2/with-transaction [_conn](doseq [k [:remote-sync-url :remote-sync-token :remote-sync-type :remote-sync-branch :remote-sync-auto-import :remote-sync-transforms]]- (when (and (contains? settings k)+ (when (and (not= :env (setting/get-raw-value-source k)) (contains? settings k)(not (and (= k :remote-sync-token) obfuscated?)))(setting/set! k (k settings)))))))))diff --git a/enterprise/frontend/src/metabase-enterprise/remote_sync/components/GitSyncControls/GitSyncControls.tsx b/enterprise/frontend/src/metabase-enterprise/remote_sync/components/GitSyncControls/GitSyncControls.tsxindex 5876f51c1ae..1873e3b07f7 100644--- a/enterprise/frontend/src/metabase-enterprise/remote_sync/components/GitSyncControls/GitSyncControls.tsx+++ b/enterprise/frontend/src/metabase-enterprise/remote_sync/components/GitSyncControls/GitSyncControls.tsx@@ -30,7 +30,7 @@ type DropdownView = "options" | "branch";export const GitSyncControls = () => {const dispatch = useDispatch();const conflictVariant = useSelector(getSyncConflictVariant);- const { isVisible, currentBranch } = useGitSyncVisible();+ const { isVisible, currentBranch, isBranchSetByEnv } = useGitSyncVisible();const [importChanges, { isLoading: isImporting }] =useImportChangesMutation();@@ -205,6 +205,7 @@ export const GitSyncControls = () => {isPullError={hasRemoteChangesError}isLoadingPull={isFetchingRemoteChanges}isPushDisabled={!isDirty || isLoading}+ isSwitchBranchDisabled={isBranchSetByEnv}onPullClick={handlePullClick}onPushClick={handlePushClick}onSwitchBranchClick={handleSwitchBranchClick}diff --git a/enterprise/frontend/src/metabase-enterprise/remote_sync/components/GitSyncControls/GitSyncOptionsDropdown.tsx b/enterprise/frontend/src/metabase-enterprise/remote_sync/components/GitSyncControls/GitSyncOptionsDropdown.tsxindex 0c03583cdbf..c9df7f07024 100644--- a/enterprise/frontend/src/metabase-enterprise/remote_sync/components/GitSyncControls/GitSyncOptionsDropdown.tsx+++ b/enterprise/frontend/src/metabase-enterprise/remote_sync/components/GitSyncControls/GitSyncOptionsDropdown.tsx@@ -1,12 +1,22 @@import { t } from "ttag";-import { Box, Combobox, Group, Icon, Loader, Text, Tooltip } from "metabase/ui";+import {+ Badge,+ Box,+ Combobox,+ Group,+ Icon,+ Loader,+ Text,+ Tooltip,+} from "metabase/ui";export interface GitSyncOptionsDropdownProps {isPullDisabled: boolean;isPullError: boolean;isLoadingPull: boolean;isPushDisabled: boolean;+ isSwitchBranchDisabled?: boolean;onPullClick: VoidFunction;onPushClick: VoidFunction;onSwitchBranchClick: VoidFunction;@@ -17,6 +27,7 @@ export const GitSyncOptionsDropdown = ({isPullError,isLoadingPull,isPushDisabled,+ isSwitchBranchDisabled,onPullClick,onPushClick,onSwitchBranchClick,@@ -72,16 +83,29 @@ export const GitSyncOptionsDropdown = ({</Combobox.Option></Tooltip>- <Combobox.Option- onClick={onSwitchBranchClick}- py="sm"- value="switch-branch"- >- <Group gap="md" wrap="nowrap">- <Icon name="git_branch" size={12} />- <Text>{t`Switch branch`}</Text>- </Group>- </Combobox.Option>+ {isSwitchBranchDisabled ? (+ <Badge+ color="text-primary"+ bg="background-secondary"+ size="md"+ fz="12px"+ py="md"+ my="xs"+ style={{ textTransform: "none" }}+ bdrs="sm"+ >{t`Branch set by an environment variable`}</Badge>+ ) : (+ <Combobox.Option+ onClick={onSwitchBranchClick}+ py="sm"+ value="switch-branch"+ >+ <Group gap="md" wrap="nowrap">+ <Icon name="git_branch" size={12} />+ <Text>{t`Switch branch`}</Text>+ </Group>+ </Combobox.Option>+ )}</Combobox.Options></Combobox.Dropdown>);diff --git a/enterprise/frontend/src/metabase-enterprise/remote_sync/components/RemoteSyncAdminSettings/RemoteSyncSettingsForm.setup.spec.tsx b/enterprise/frontend/src/metabase-enterprise/remote_sync/components/RemoteSyncAdminSettings/RemoteSyncSettingsForm.setup.spec.tsxindex c9775bc07f8..e285f566512 100644--- a/enterprise/frontend/src/metabase-enterprise/remote_sync/components/RemoteSyncAdminSettings/RemoteSyncSettingsForm.setup.spec.tsx+++ b/enterprise/frontend/src/metabase-enterprise/remote_sync/components/RemoteSyncAdminSettings/RemoteSyncSettingsForm.setup.spec.tsx@@ -9,9 +9,15 @@ import {import { mockSettings } from "__support__/settings";import { renderWithProviders } from "__support__/ui";import { createMockState } from "metabase/redux/store/mocks";-import type { Collection, CollectionItem } from "metabase-types/api";+import type {+ Collection,+ CollectionItem,+ EnterpriseSettingKey,+ SettingDefinition,+} from "metabase-types/api";import {createMockCollection,+ createMockSettingDefinition,createMockSettings,createMockUser,} from "metabase-types/api/mocks";@@ -43,6 +49,7 @@ const setupEndpoints = ({dirty = [] as any[],rootCollectionItems = [] as CollectionItem[],settingsError,+ envSettings = [],}: {remoteSyncEnabled?: boolean;remoteSyncUrl?: string;@@ -55,6 +62,7 @@ const setupEndpoints = ({dirty?: any[];rootCollectionItems?: CollectionItem[];settingsError?: { status: number; message: string };+ envSettings?: EnterpriseSettingKey[];} = {}) => {const settings = createMockSettings({"remote-sync-enabled": remoteSyncEnabled,@@ -66,8 +74,17 @@ const setupEndpoints = ({"remote-sync-transforms": remoteSyncTransforms,});+ const settingDefinitions: SettingDefinition[] = envSettings.map((key) =>+ createMockSettingDefinition({+ key,+ value: settings[key],+ is_env_setting: true,+ env_name: `MB_${key.toUpperCase().replace(/-/g, "_")}`,+ } as SettingDefinition),+ );+setupPropertiesEndpoints(settings);- setupSettingsEndpoints([]);+ setupSettingsEndpoints(settingDefinitions);setupRemoteSyncEndpoints({dirty,branches: [remoteSyncBranch],@@ -112,6 +129,7 @@ interface SetupOpts {rootCollectionItems?: CollectionItem[];variant?: RemoteSyncSettingsFormProps["variant"];settingsError?: { status: number; message: string };+ envSettings?: EnterpriseSettingKey[];}export const setup = ({@@ -127,6 +145,7 @@ export const setup = ({rootCollectionItems = [],variant,settingsError,+ envSettings = [],}: SetupOpts = {}) => {setupEndpoints({remoteSyncEnabled,@@ -139,6 +158,7 @@ export const setup = ({dirty,rootCollectionItems,settingsError,+ envSettings,});renderWithProviders(diff --git a/enterprise/frontend/src/metabase-enterprise/remote_sync/components/RemoteSyncAdminSettings/RemoteSyncSettingsForm.tsx b/enterprise/frontend/src/metabase-enterprise/remote_sync/components/RemoteSyncAdminSettings/RemoteSyncSettingsForm.tsxindex 3cd1fa904ad..33fc76b89af 100644--- a/enterprise/frontend/src/metabase-enterprise/remote_sync/components/RemoteSyncAdminSettings/RemoteSyncSettingsForm.tsx+++ b/enterprise/frontend/src/metabase-enterprise/remote_sync/components/RemoteSyncAdminSettings/RemoteSyncSettingsForm.tsx@@ -400,13 +400,20 @@ export const RemoteSyncSettingsForm = (props: RemoteSyncSettingsFormProps) => {</Text>}type="password"- {...getEnvSettingProps(settingDetails?.[TOKEN_KEY])}+ {...getEnvSettingProps(settingDetails?.[TOKEN_KEY], {+ inputWrapperOrder: ["label", "description", "erorr"],+ })}/></RemoteSyncSettingsSection>{/* Section 2: Sync mode for this instance */}<RemoteSyncSettingsSectiontitle={t`Sync mode for this instance`}+ description={+ settingDetails?.[TYPE_KEY]?.is_env_setting+ ? t`Using ${settingDetails[TYPE_KEY].env_name}`+ : undefined+ }variant={variant}><FormRadioGroup name={TYPE_KEY}>@@ -427,7 +434,10 @@ export const RemoteSyncSettingsForm = (props: RemoteSyncSettingsFormProps) => {{t`Usually you should use this for your production ${applicationName} instance. All synced collections are read-only, and will automatically sync with the specified branch (we'd recommend syncing with main).`}</Text>}- disabled={hasUnsyncedChanges}+ disabled={+ hasUnsyncedChanges ||+ !!settingDetails?.[TYPE_KEY]?.is_env_setting+ }label={<Text fw={700} lh="1.25rem" mb="xs">{t`Read-only`}@@ -439,6 +449,7 @@ export const RemoteSyncSettingsForm = (props: RemoteSyncSettingsFormProps) => {</Tooltip><Radiovalue="read-write"+ disabled={!!settingDetails?.[TYPE_KEY]?.is_env_setting}label={<Text fw={700} lh="1.25rem" mb="xs">{t`Read-write`}@@ -460,7 +471,7 @@ export const RemoteSyncSettingsForm = (props: RemoteSyncSettingsFormProps) => {title={t`Branch to sync with`}variant={variant}>- <Flex align="flex-end" gap="md">+ <Stack gap="md"><Box style={{ flex: 1 }}><FormTextInputname={BRANCH_KEY}@@ -475,8 +486,12 @@ export const RemoteSyncSettingsForm = (props: RemoteSyncSettingsFormProps) => {mb="0.6125rem"name={AUTO_IMPORT_KEY}size="sm"+ {...getEnvSettingProps(+ settingDetails?.[AUTO_IMPORT_KEY],+ { disabled: true },+ )}/>- </Flex>+ </Stack>{isRemoteSyncEnabled && (<Box><PullChangesButton@@ -524,18 +539,19 @@ export const RemoteSyncSettingsForm = (props: RemoteSyncSettingsFormProps) => {{/* Footer Actions - Outside Sections */}<Flex justify="space-between" align="center"><Box>- {isRemoteSyncEnabled && (- <Button- c="error"- variant="subtle"- size="md"- w="12rem"- leftSection={<Icon name="close" />}- onClick={handleDisable}- >- {t`Disable remote sync`}- </Button>- )}+ {isRemoteSyncEnabled &&+ !settingDetails?.[REMOTE_SYNC_KEY]?.is_env_setting && (+ <Button+ c="error"+ variant="subtle"+ size="md"+ w="12rem"+ leftSection={<Icon name="close" />}+ onClick={handleDisable}+ >+ {t`Disable remote sync`}+ </Button>+ )}</Box><Flex align="center" gap="md">@@ -606,11 +622,12 @@ const RemoteSyncSettingsSection = ({);};-const getEnvSettingProps = (setting?: SettingDefinition) => {+const getEnvSettingProps = <T,>(setting?: SettingDefinition, extras?: T) => {if (setting?.is_env_setting) {return {description: t`Using ${setting.env_name}`,readOnly: true,+ ...extras,};}return {};diff --git a/enterprise/frontend/src/metabase-enterprise/remote_sync/components/RemoteSyncAdminSettings/RemoteSyncSettingsForm.unit.spec.tsx b/enterprise/frontend/src/metabase-enterprise/remote_sync/components/RemoteSyncAdminSettings/RemoteSyncSettingsForm.unit.spec.tsxindex 68b79286222..13fb005146d 100644--- a/enterprise/frontend/src/metabase-enterprise/remote_sync/components/RemoteSyncAdminSettings/RemoteSyncSettingsForm.unit.spec.tsx+++ b/enterprise/frontend/src/metabase-enterprise/remote_sync/components/RemoteSyncAdminSettings/RemoteSyncSettingsForm.unit.spec.tsx@@ -640,6 +640,88 @@ describe("RemoteSyncSettingsForm", () => {});});+ describe("environment variable overrides", () => {+ it("should disable both sync mode radio options and show env var description when remote-sync-type is set by env", async () => {+ setup({+ remoteSyncType: "read-write",+ envSettings: ["remote-sync-type"],+ });++ await waitFor(() => {+ expect(screen.getByLabelText("Read-only")).toBeDisabled();+ });+ expect(screen.getByLabelText("Read-write")).toBeDisabled();+ expect(screen.getByText("Using MB_REMOTE_SYNC_TYPE")).toBeInTheDocument();+ });++ it("should not disable sync mode radio options when remote-sync-type is not set by env", async () => {+ setup({+ remoteSyncType: "read-write",+ });++ await waitFor(() => {+ expect(screen.getByLabelText("Read-write")).toBeChecked();+ });++ expect(screen.getByLabelText("Read-only")).toBeEnabled();+ expect(screen.getByLabelText("Read-write")).toBeEnabled();+ });++ it("should hide the disable button when remote-sync-enabled is set by env", async () => {+ setup({+ remoteSyncEnabled: true,+ remoteSyncUrl: "https://github.com/test/repo.git",+ remoteSyncType: "read-write",+ envSettings: ["remote-sync-enabled"],+ });++ await waitFor(() => {+ expect(screen.getByLabelText("Read-write")).toBeChecked();+ });++ expect(+ screen.queryByRole("button", { name: /Disable remote sync/i }),+ ).not.toBeInTheDocument();+ });++ it("should make URL and token fields read-only when set by env", async () => {+ setup({+ remoteSyncUrl: "https://github.com/test/repo.git",+ remoteSyncToken: "ghp_abc123",+ envSettings: ["remote-sync-url", "remote-sync-token"],+ });++ await waitFor(() => {+ expect(+ screen.getByText("Using MB_REMOTE_SYNC_URL"),+ ).toBeInTheDocument();+ });++ expect(screen.getByLabelText(/Repository URL/i)).toHaveAttribute(+ "readonly",+ );+ expect(+ screen.getByText("Using MB_REMOTE_SYNC_TOKEN"),+ ).toBeInTheDocument();+ });++ it("should make branch field read-only when remote-sync-branch is set by env", async () => {+ setup({+ remoteSyncType: "read-only",+ remoteSyncBranch: "main",+ envSettings: ["remote-sync-branch"],+ });++ await waitFor(() => {+ expect(+ screen.getByText("Using MB_REMOTE_SYNC_BRANCH"),+ ).toBeInTheDocument();+ });++ expect(screen.getByLabelText(/Sync branch/i)).toHaveAttribute("readonly");+ });+ });+describe("collections to sync section", () => {it("should display collections section in admin variant when read-write mode is selected during initial setup", async () => {setup({diff --git a/enterprise/frontend/src/metabase-enterprise/remote_sync/hooks/use-git-sync-visible.ts b/enterprise/frontend/src/metabase-enterprise/remote_sync/hooks/use-git-sync-visible.tsindex a33ec9083da..edf6731f2ea 100644--- a/enterprise/frontend/src/metabase-enterprise/remote_sync/hooks/use-git-sync-visible.ts+++ b/enterprise/frontend/src/metabase-enterprise/remote_sync/hooks/use-git-sync-visible.ts@@ -7,6 +7,7 @@ import { BRANCH_KEY, REMOTE_SYNC_KEY, TYPE_KEY } from "../constants";export interface GitSyncVisibleState {isVisible: boolean;currentBranch: string | null | undefined;+ isBranchSetByEnv: boolean;}/**@@ -16,7 +17,8 @@ export interface GitSyncVisibleState {export const useGitSyncVisible = (): GitSyncVisibleState => {const isAdmin = useSelector(getUserIsAdmin);const { value: isRemoteSyncEnabled } = useAdminSetting(REMOTE_SYNC_KEY);- const { value: currentBranch } = useAdminSetting(BRANCH_KEY);+ const { value: currentBranch, settingDetails: branchDetails } =+ useAdminSetting(BRANCH_KEY);const { value: syncType } = useAdminSetting(TYPE_KEY);const isVisible = !!(@@ -26,5 +28,9 @@ export const useGitSyncVisible = (): GitSyncVisibleState => {syncType === "read-write");- return { isVisible, currentBranch };+ return {+ isVisible,+ currentBranch,+ isBranchSetByEnv: !!branchDetails?.is_env_setting,+ };};diff --git a/enterprise/frontend/src/metabase-enterprise/remote_sync/hooks/use-git-sync-visible.unit.spec.ts b/enterprise/frontend/src/metabase-enterprise/remote_sync/hooks/use-git-sync-visible.unit.spec.tsindex ca4e987082a..75f60f860c7 100644--- a/enterprise/frontend/src/metabase-enterprise/remote_sync/hooks/use-git-sync-visible.unit.spec.ts+++ b/enterprise/frontend/src/metabase-enterprise/remote_sync/hooks/use-git-sync-visible.unit.spec.ts@@ -5,7 +5,11 @@ import {import { mockSettings } from "__support__/settings";import { renderHookWithProviders, waitFor } from "__support__/ui";import { createMockState } from "metabase/redux/store/mocks";-import { createMockSettings, createMockUser } from "metabase-types/api/mocks";+import {+ createMockSettingDefinition,+ createMockSettings,+ createMockUser,+} from "metabase-types/api/mocks";import { useGitSyncVisible } from "./use-git-sync-visible";@@ -14,11 +18,13 @@ const setup = ({remoteSyncEnabled = true,currentBranch = "main",syncType = "read-write",+ isBranchEnvSetting = false,}: {isAdmin?: boolean;remoteSyncEnabled?: boolean;currentBranch?: string | null;syncType?: "read-only" | "read-write";+ isBranchEnvSetting?: boolean;} = {}) => {setupPropertiesEndpoints(createMockSettings({@@ -27,7 +33,14 @@ const setup = ({"remote-sync-type": syncType,}),);- setupSettingsEndpoints([]);+ setupSettingsEndpoints([+ createMockSettingDefinition({+ key: "remote-sync-branch",+ value: currentBranch,+ is_env_setting: isBranchEnvSetting,+ env_name: "MB_REMOTE_SYNC_BRANCH",+ }),+ ]);const storeInitialState = createMockState({currentUser: createMockUser({ is_superuser: isAdmin }),@@ -109,4 +122,24 @@ describe("useGitSyncVisible", () => {expect(result.current.isVisible).toBe(false);});});++ it("should return isBranchSetByEnv: true when branch is set by environment variable", async () => {+ const { result } = setup({+ isBranchEnvSetting: true,+ });++ await waitFor(() => {+ expect(result.current.isBranchSetByEnv).toBe(true);+ });+ });++ it("should return isBranchSetByEnv: false when branch is not set by environment variable", async () => {+ const { result } = setup({+ isBranchEnvSetting: false,+ });++ await waitFor(() => {+ expect(result.current.isBranchSetByEnv).toBe(false);+ });+ });});diff --git a/frontend/src/metabase/nav/components/search/SearchBar/SearchBar.styled.tsx b/frontend/src/metabase/nav/components/search/SearchBar/SearchBar.styled.tsxindex 999168f0d73..e3072ac4db4 100644--- a/frontend/src/metabase/nav/components/search/SearchBar/SearchBar.styled.tsx+++ b/frontend/src/metabase/nav/components/search/SearchBar/SearchBar.styled.tsx@@ -40,7 +40,6 @@ export const SearchInputContainer = styled.div<{}return css`background-color: var(--mb-color-background-primary);-&:hover {background-color: var(--mb-color-background-secondary);}diff --git a/src/metabase/collections/core.clj b/src/metabase/collections/core.cljindex 16c916b38cd..f7783e0f80d 100644--- a/src/metabase/collections/core.clj+++ b/src/metabase/collections/core.clj@@ -11,6 +11,7 @@(p/import-vars[metabase.collections.models.collection+ has-remote-synced-collection?check-for-remote-sync-updatecheck-non-remote-synced-dependenciescheck-remote-synced-dependentsdiff --git a/src/metabase/collections/models/collection.clj b/src/metabase/collections/models/collection.cljindex 47d9ce161c0..0e96e0126fe 100644--- a/src/metabase/collections/models/collection.clj+++ b/src/metabase/collections/models/collection.clj@@ -174,6 +174,11 @@(binding [*clearing-remote-sync* true](t2/update! :model/Collection :is_remote_synced true {:is_remote_synced false})))+(defn has-remote-synced-collection?+ "Return true if any collections are marked remote-sync"+ []+ (pos-int? (t2/count :model/Collection :is_remote_synced true)))+(defn library-collection"Get the 'library' collection, if it exists."[]diff --git a/src/metabase/settings/core.clj b/src/metabase/settings/core.cljindex c75d9585c34..69fb8e97c73 100644--- a/src/metabase/settings/core.clj+++ b/src/metabase/settings/core.clj@@ -100,6 +100,7 @@export?getget-raw-value+ get-raw-value-sourcelog-deprecated-env-var-usage!get-value-of-typehas-advanced-setting-access?diff --git a/src/metabase/settings/models/setting.clj b/src/metabase/settings/models/setting.cljindex c413a471fc5..3489b2842f1 100644--- a/src/metabase/settings/models/setting.clj+++ b/src/metabase/settings/models/setting.clj@@ -659,6 +659,19 @@(when (pred v)v))))+(defn get-raw-value-source+ "Get the source of the raw value of a Setting from wherever it may be specified.+ Priority order is specified in `get-raw-value`."+ ([setting-definition-or-name]+ (let [setting (resolve-setting setting-definition-or-name)]+ (cond+ (some? (user-local-value setting)) :user-local+ (some? (database-local-value setting)) :database-local+ (some? (env-var-value setting)) :env+ (some? (db-or-cache-value setting)) :database+ (some? (:default setting)) :default+ :else nil))))+(defmulti get-value-of-type"Get the value of `setting-definition-or-name` as a value of type `setting-type`. This is used as the default getterfor Settings with `setting-type`.