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
Button in Metabase Admin section to purchase Metabase AI add-on (#62513)
Dennis Schridde6bf6cb679dbe
diff --git a/.clj-kondo/config/modules/config.edn b/.clj-kondo/config/modules/config.ednindex 2dfb8fbe7bb..6957d58af40 100644--- a/.clj-kondo/config/modules/config.edn+++ b/.clj-kondo/config/modules/config.edn@@ -303,6 +303,7 @@modelspremium-featuressettings+ store-apitaskutil}}@@ -1190,6 +1191,14 @@:api #{metabase.startup.core}:uses #{util}}+ store-api+ {:team "Cloud"+ :api #{metabase.store-api.core+ metabase.store-api.init}+ :uses #{config+ settings+ util}}+sync{:team "Querying":api #{metabase.sync.api@@ -1592,6 +1601,14 @@taskutil}}+ enterprise/cloud-add-ons+ {:team "Cloud"+ :api #{metabase-enterprise.cloud-add-ons.api}+ :uses #{api+ premium-features+ util+ enterprise/harbormaster}}+enterprise/content-translation{:team "UX West":api #{metabase-enterprise.content-translation.dictionary@@ -1704,7 +1721,7 @@{:team "Cloud":api #{metabase-enterprise.harbormaster.client}:uses #{api- cloud-migration+ store-apiutil}}enterprise/impersonationdiff --git a/enterprise/backend/src/metabase_enterprise/api/routes.clj b/enterprise/backend/src/metabase_enterprise/api/routes.cljindex a2e32670ea9..45f987e300a 100644--- a/enterprise/backend/src/metabase_enterprise/api/routes.clj+++ b/enterprise/backend/src/metabase_enterprise/api/routes.clj@@ -14,6 +14,7 @@[metabase-enterprise.api.routes.common :as ee.api.common][metabase-enterprise.audit-app.api.routes][metabase-enterprise.billing.api.routes]+ [metabase-enterprise.cloud-add-ons.api][metabase-enterprise.content-translation.routes][metabase-enterprise.content-verification.api.routes][metabase-enterprise.database-replication.api :as database-replication.api]@@ -91,6 +92,7 @@"/autodescribe" (premium-handler 'metabase-enterprise.llm.api :llm-autodescription)"/billing" metabase-enterprise.billing.api.routes/routes"/content-translation" (premium-handler metabase-enterprise.content-translation.routes/routes :content-translation)+ "/cloud-add-ons" metabase-enterprise.cloud-add-ons.api/routes"/database-replication" (-> database-replication.api/routes ;; database-replication requires all these features.(premium-handler :attached-dwh)(premium-handler :etl-connections)diff --git a/enterprise/backend/src/metabase_enterprise/cloud_add_ons/api.clj b/enterprise/backend/src/metabase_enterprise/cloud_add_ons/api.cljnew file mode 100644index 00000000000..39feba5b0b1--- /dev/null+++ b/enterprise/backend/src/metabase_enterprise/cloud_add_ons/api.clj@@ -0,0 +1,61 @@+(ns metabase-enterprise.cloud-add-ons.api+ "/api/ee/cloud-add-ons endpoints. "+ (:require+ [metabase-enterprise.harbormaster.client :as hm.client]+ [metabase.api.common :as api]+ [metabase.api.macros :as api.macros]+ [metabase.api.routes.common :refer [+auth]]+ [metabase.premium-features.core :as premium-features]+ [metabase.util.i18n :refer [deferred-tru]]+ [metabase.util.log :as log]))++(def ^:private error-no-connection+ (deferred-tru "Could not establish a connection to Metabase Cloud."))+(def ^:private error-cannot-purchase+ (deferred-tru "Could not purchase this add-on."))+(def ^:private error-unexpected+ (deferred-tru "Unexpected error"))++(api.macros/defendpoint :post "/:product-type"+ "Purchase an add-on."+ [{:keys [product-type]} :- [:map+ [:product-type [:enum "metabase-ai"]]]+ _query-params+ {:keys [terms_of_service]} :- [:map+ [:terms_of_service :boolean]]]+ (api/check-superuser)+ (cond+ (not terms_of_service)+ {:status 400 :body {:errors {:terms_of_service "Need to accept terms of service."}}}++ (not (premium-features/is-hosted?))+ {:status 400 :body "Can only purchase add-ons for Metabase Cloud instances."}++ (not (premium-features/offer-metabase-ai?))+ {:status 400 :body "Can only purchase add-ons for eligible subscriptions."}++ (not (contains? (set (map :email (:store-users (premium-features/token-status))))+ (:email @api/*current-user*)))+ {:status 403 :body "Only Metabase Store users can purchase add-ons."}++ :else+ (try+ (hm.client/call :change-add-ons+ :upsert-add-ons [{:product-type product-type}]+ :metabase-user (-> (select-keys @api/*current-user* [:email :id])+ (update-vals str)))+ (premium-features/clear-cache)+ {:status 200 :body {}}+ (catch Exception e+ (log/warnf e "Error adding purchasing add-on '%s'" product-type)+ (case (-> e ex-data :status)+ 404 {:status 404 :body error-no-connection}+ 403 {:status 403 :body error-no-connection}+ 401 {:status 401 :body error-no-connection}+ 400 {:status 400 :body error-cannot-purchase}+ {:status 500 :body error-unexpected})))))++(def ^{:arglists '([request respond raise])} routes+ "`/api/ee/cloud-add-ons` routes."+ (api/+check-superuser+ (api.macros/ns-handler *ns* api/+check-superuser +auth)))diff --git a/enterprise/backend/src/metabase_enterprise/harbormaster/client.clj b/enterprise/backend/src/metabase_enterprise/harbormaster/client.cljindex dd9c3d21366..80462fe8d3b 100644--- a/enterprise/backend/src/metabase_enterprise/harbormaster/client.clj+++ b/enterprise/backend/src/metabase_enterprise/harbormaster/client.clj@@ -7,7 +7,7 @@[martian.core :as martian][medley.core :as m][metabase.api.settings :as api.auth]- [metabase.cloud-migration.core :as cloud-migration]+ [metabase.store-api.core :as store-api][metabase.util :as m.util][metabase.util.i18n :refer [tru]][metabase.util.json :as json]@@ -44,7 +44,7 @@`->config` either gets the store-api-url and api-key from settings or throws an exception when either are unset orblank."[]- (let [store-api-url (cloud-migration/store-api-url)+ (let [store-api-url (store-api/store-api-url)_ (when (str/blank? store-api-url)(log/error "Missing store-api-url. Cannot create hm client config.")(throw (ex-info (tru "Missing store-api-url.") {:store-api-url store-api-url})))@@ -138,7 +138,7 @@(memoize create-client))(defn- client []- (let [store-api-url (cloud-migration/store-api-url)+ (let [store-api-url (store-api/store-api-url)api-key (api.auth/api-key)](when (str/blank? store-api-url)(log/error "Missing store-api-url. Cannot create hm client config.")@@ -213,6 +213,5 @@;; :as :text};; Call the :list-connections operation.- (call :list-connections)+ (call :list-connections));; => ()- )diff --git a/enterprise/backend/test/metabase_enterprise/api/session_test.clj b/enterprise/backend/test/metabase_enterprise/api/session_test.cljindex a64c1f1874c..4b43284f3ee 100644--- a/enterprise/backend/test/metabase_enterprise/api/session_test.clj+++ b/enterprise/backend/test/metabase_enterprise/api/session_test.clj@@ -32,6 +32,7 @@:ai-sql-fixer:ai-sql-generation:no-upsell+ :offer-metabase-ai:official-collections:query-reference-validation:sandboxes@@ -74,6 +75,7 @@:ai_entity_analysis true:ai_sql_fixer true:ai_sql_generation true+ :offer_metabase_ai true:official_collections true:query_reference_validation true:sandboxes truediff --git a/enterprise/backend/test/metabase_enterprise/cloud_add_ons/api_test.clj b/enterprise/backend/test/metabase_enterprise/cloud_add_ons/api_test.cljnew file mode 100644index 00000000000..5a8548ec2ba--- /dev/null+++ b/enterprise/backend/test/metabase_enterprise/cloud_add_ons/api_test.clj@@ -0,0 +1,67 @@+(ns metabase-enterprise.cloud-add-ons.api-test+ (:require+ [clojure.test :refer :all]+ [metabase-enterprise.harbormaster.client :as hm.client]+ [metabase-enterprise.semantic-search.test-util :as semantic.tu]+ [metabase.premium-features.core :as premium-features]+ [metabase.test :as mt]))++(deftest ^:sequential post-product-type-test+ (testing "POST /api/ee/cloud-add-ons/metabase-ai"+ (testing "requires superuser"+ (mt/with-premium-features #{}+ (is (=? "You don't have permissions to do that."+ (mt/user-http-request :rasta :post 403 "ee/cloud-add-ons/metabase-ai"+ {:terms_of_service true})))))+ (testing "requires accepting terms of service"+ (mt/with-premium-features #{}+ (is (=? {:errors {:terms_of_service "Need to accept terms of service."}}+ (mt/user-http-request :crowberto :post 400 "ee/cloud-add-ons/metabase-ai"+ {:terms_of_service false})))))+ (testing "requires token feature 'hosting'"+ (mt/with-premium-features #{}+ (is (=? "Can only purchase add-ons for Metabase Cloud instances."+ (mt/user-http-request :crowberto :post 400 "ee/cloud-add-ons/metabase-ai"+ {:terms_of_service true})))))+ (testing "requires token feature 'offer-metabase-ai'"+ (mt/with-premium-features #{:hosting}+ (is (=? "Can only purchase add-ons for eligible subscriptions."+ (mt/user-http-request :crowberto :post 400 "ee/cloud-add-ons/metabase-ai"+ {:terms_of_service true})))))+ (testing "requires current user being a store user"+ (mt/with-premium-features #{:hosting :offer-metabase-ai}+ (is (=? "Only Metabase Store users can purchase add-ons."+ (mt/user-http-request :crowberto :post 403 "ee/cloud-add-ons/metabase-ai"+ {:terms_of_service true})))))+ (testing "when all conditions are met"+ (mt/with-temp [:model/User user {:is_superuser true}]+ (mt/with-premium-features #{:hosting :offer-metabase-ai}+ ;; FIXME: With `(mt/with-temporary-setting-values [token-status {:store-users [{:email (:email user)}]}])`,+ ;; `(premium-features/token-status)` still returns `nil`; thus resort to `with-redefs`:+ (with-redefs [premium-features/token-status (constantly {:store-users [{:email (:email user)}]})]+ (doseq [[status-code error-message] {404 "Could not establish a connection to Metabase Cloud."+ 403 "Could not establish a connection to Metabase Cloud."+ 401 "Could not establish a connection to Metabase Cloud."+ 400 "Could not purchase this add-on."}]+ (testing (format "passes through HTTP status %d from Store API" status-code)+ (with-redefs [hm.client/call (fn [& _] (throw (ex-info "TEST" {:status status-code})))]+ (is (=? error-message+ (mt/user-http-request user :post status-code "ee/cloud-add-ons/metabase-ai"+ {:terms_of_service true}))))))+ (testing "responds with HTTP status 500 for other errors from Store API"+ (with-redefs [hm.client/call (fn [& _] (throw (ex-info "TEST" {})))]+ (is (=? "Unexpected error"+ (mt/user-http-request user :post 500 "ee/cloud-add-ons/metabase-ai"+ {:terms_of_service true})))))+ (testing "succeeds"+ (let [{store-api-proxy :proxy store-api-calls :calls} (semantic.tu/spy (constantly nil))+ {clear-token-cache-proxy :proxy clear-token-cache-calls :calls} (semantic.tu/spy premium-features/clear-cache)]+ (with-redefs [hm.client/call store-api-proxy+ premium-features/clear-cache clear-token-cache-proxy]+ (is (=? {}+ (mt/user-http-request user :post 200 "ee/cloud-add-ons/metabase-ai"+ {:terms_of_service true})))+ (is (not-empty @store-api-calls)+ "Store API was called")+ (is (not-empty @clear-token-cache-calls)+ "Token cache was cleared"))))))))))diff --git a/enterprise/frontend/src/metabase-enterprise/metabot/components/MetabotAdmin/MetabotPurchasePage.tsx b/enterprise/frontend/src/metabase-enterprise/metabot/components/MetabotAdmin/MetabotPurchasePage.tsxnew file mode 100644index 00000000000..a74c68da260--- /dev/null+++ b/enterprise/frontend/src/metabase-enterprise/metabot/components/MetabotAdmin/MetabotPurchasePage.tsx@@ -0,0 +1,189 @@+import { useDisclosure } from "@mantine/hooks";+import type { FetchBaseQueryError } from "@reduxjs/toolkit/query";+import { useCallback } from "react";+import { t } from "ttag";+import * as Yup from "yup";++import {+ SettingsPageWrapper,+ SettingsSection,+} from "metabase/admin/components/SettingsSection";+import { getCurrentUser } from "metabase/admin/datamodel/selectors";+import { usePurchaseMetabotCloudAddOnMutation } from "metabase/api/metabot";+import ExternalLink from "metabase/common/components/ExternalLink";+import Markdown from "metabase/common/components/Markdown";+import { useSetting } from "metabase/common/hooks";+import {+ Form,+ FormCheckbox,+ FormProvider,+ FormSubmitButton,+} from "metabase/forms";+import { useSelector } from "metabase/lib/redux";+import { Divider, Flex, Group, List, Stack, Text } from "metabase/ui";+import { MetabotPurchaseSettingUpModal } from "metabase-enterprise/metabot/components/MetabotAdmin/MetabotPurchaseSettingUpModal";++// https://redux-toolkit.js.org/rtk-query/usage/error-handling+// https://redux-toolkit.js.org/rtk-query/usage-with-typescript#type-safe-error-handling+const isFetchBaseQueryError = (error: unknown): error is FetchBaseQueryError =>+ error instanceof Object && "status" in error && "data" in error;++type IFieldError =+ | string+ | {+ message: string;+ }+ | {+ errors: { [key: string]: any };+ };++const isFieldError = (error: unknown): error is IFieldError =>+ typeof error === "string" ||+ (error instanceof Object &&+ (("message" in error && typeof error.message === "string") ||+ ("errors" in error &&+ error.errors instanceof Object &&+ "terms_of_service" in error.errors &&+ typeof error.errors.terms_of_service === "string")));++export const handleFieldError = (error: unknown) => {+ if (!isFieldError(error)) {+ return;+ }++ if (typeof error === "string") {+ throw { data: { errors: { terms_of_service: error } } };+ }++ if ("message" in error) {+ throw { data: { errors: { terms_of_service: error.message } } };+ }++ if ("errors" in error) {+ throw { data: error };+ }+};++const validationSchema = Yup.object({+ terms_of_service: Yup.boolean(),+});++interface MetabotPurchaseFormFields {+ terms_of_service: boolean;+}++export const MetabotPurchasePage = () => {+ const currentUser = useSelector(getCurrentUser);+ const tokenStatus = useSetting("token-status");+ const storeUserEmails =+ tokenStatus?.["store-users"]?.map(({ email }) => email) ?? [];+ const isStoreUser = storeUserEmails.includes(currentUser?.email);+ const anyStoreUserEmailAddress =+ storeUserEmails.length > 0 ? storeUserEmails[0] : undefined;++ const [settingUpModalOpened, settingUpModalHandlers] = useDisclosure(false);+ const [purchaseMetabotAddOn] = usePurchaseMetabotCloudAddOnMutation();+ const onSubmit = useCallback(+ async ({ terms_of_service }: MetabotPurchaseFormFields) => {+ settingUpModalHandlers.open();+ await purchaseMetabotAddOn({+ terms_of_service,+ })+ .unwrap()+ .catch((error: unknown) => {+ settingUpModalHandlers.close();+ isFetchBaseQueryError(error) && handleFieldError(error.data);+ });+ },+ [purchaseMetabotAddOn, settingUpModalHandlers],+ );++ return (+ <SettingsPageWrapper title={t`Metabot AI`}>+ <SettingsSection+ title={+ /* eslint-disable-next-line no-literal-metabase-strings -- This string only shows for admins. */+ t`Get a free month of Metabot, the new AI assistant for Metabase.`+ }+ >+ <Stack>+ <Text>{t`Metabot helps you move faster and understand your data better. You can ask it to:`}</Text>+ <List>+ <List.Item>+ <Markdown>{+ /* eslint-disable-next-line no-literal-metabase-strings -- This string only shows for admins. */+ t`**Act as a SQL generation copilot** in the Metabase SQL editor`+ }</Markdown>+ </List.Item>+ <List.Item>+ <Markdown>{t`**Help you build queries** based on models and metrics in a specified collection`}</Markdown>+ </List.Item>+ <List.Item>+ <Markdown>{t`**Explain queries** or existing charts`}</Markdown>+ </List.Item>+ </List>+ <video controls aria-label={t`Demonstration of Metabot AI features`}>+ <source+ src="https://www.metabase.com/images/features/metabot.mp4"+ type="video/mp4"+ />+ {t`Your browser does not support the video tag.`}+ </video>+ <Text>{t`Metabot is a new feature in active development. We're constantly rolling out improvements and appreciate your feedback.`}</Text>+ </Stack>+ <Divider />++ {isStoreUser ? (+ <FormProvider+ initialValues={{ terms_of_service: false }}+ onSubmit={onSubmit}+ validationSchema={validationSchema}+ >+ {({ values }) => (+ <Form>+ <Stack>+ <FormCheckbox+ name="terms_of_service"+ label={+ <Text>+ {t`I agree with the Metabot AI add-on`}{" "}+ <ExternalLink href="https://www.metabase.com/license/metabot-addendum">{t`Terms of Service`}</ExternalLink>+ </Text>+ }+ />+ <Flex justify="start">+ <Group align="center" gap="sm">+ <FormSubmitButton+ disabled={!values.terms_of_service}+ label={t`Add Metabot AI`}+ variant="filled"+ mt="xs"+ />+ </Group>+ </Flex>+ <Markdown>+ {t`Your first month is on us. **You won't be charged automatically.** After the trial, you can decide if you'd like to subscribe.`}+ </Markdown>+ </Stack>+ </Form>+ )}+ </FormProvider>+ ) : (+ <Text fw="bold">+ {+ /* eslint-disable-next-line no-literal-metabase-strings -- This string only shows for admins. */+ t`Please ask a Metabase Store Admin${anyStoreUserEmailAddress && ` (${anyStoreUserEmailAddress})`} of your organization to enable this for you.`+ }+ </Text>+ )}+ </SettingsSection>+ <MetabotPurchaseSettingUpModal+ opened={settingUpModalOpened}+ onClose={() => {+ settingUpModalHandlers.close();+ window.location.reload();+ }}+ />+ </SettingsPageWrapper>+ );+};diff --git a/enterprise/frontend/src/metabase-enterprise/metabot/components/MetabotAdmin/MetabotPurchasePage.unit.spec.tsx b/enterprise/frontend/src/metabase-enterprise/metabot/components/MetabotAdmin/MetabotPurchasePage.unit.spec.tsxnew file mode 100644index 00000000000..37b25ca6267--- /dev/null+++ b/enterprise/frontend/src/metabase-enterprise/metabot/components/MetabotAdmin/MetabotPurchasePage.unit.spec.tsx@@ -0,0 +1,132 @@+import userEvent from "@testing-library/user-event";+import fetchMock from "fetch-mock";++import {+ findRequests,+ setupCurrentUserEndpoint,+ setupPropertiesEndpoints,+} from "__support__/server-mocks";+import { renderWithProviders, screen } from "__support__/ui";+import {+ createMockSettings,+ createMockTokenFeatures,+ createMockUser,+} from "metabase-types/api/mocks";+import { createMockSettingsState } from "metabase-types/store/mocks";++import { MetabotPurchasePage } from "./MetabotPurchasePage";++const setupRefreshableProperties = ({+ current_user_matches_store_user,+ has_metabot_v3 = false,+}: {+ current_user_matches_store_user: boolean;+ has_metabot_v3?: boolean;+}) => {+ const settings = createMockSettings({+ "token-status": {+ status: "",+ valid: true,+ features: has_metabot_v3 ? ["metabot-v3"] : [],+ "store-users": current_user_matches_store_user+ ? [{ email: "[email protected]" }]+ : [],+ },+ "token-features": createMockTokenFeatures({ metabot_v3: has_metabot_v3 }),+ });+ setupPropertiesEndpoints(settings);+ return settings;+};++const setup = async ({+ current_user_matches_store_user,+}: {+ current_user_matches_store_user: boolean;+}) => {+ const settings = setupRefreshableProperties({+ current_user_matches_store_user,+ });++ const user = createMockUser({ email: "[email protected]" });+ setupCurrentUserEndpoint(user);++ fetchMock.post("path:/api/ee/cloud-add-ons/metabase-ai", 200);++ renderWithProviders(<MetabotPurchasePage />, {+ // Calling `setupPropertiesEndpoints` above is not enough; we also need to set `storeInitialState`:+ storeInitialState: {+ settings: createMockSettingsState(settings),+ currentUser: user,+ },+ });++ await screen.findByText(/Get a free month of Metabot/);+};++describe("MetabotPurchasePage", () => {+ it("shows empty state alternate text when current user is not a store user", async () => {+ await setup({ current_user_matches_store_user: false });+ expect(screen.getByText(/Get a free month of Metabot/)).toBeInTheDocument();+ expect(+ screen.getByText(/Please ask a Metabase Store Admin/),+ ).toBeInTheDocument();+ });++ it("requires Terms of Service to be accepted", async () => {+ await setup({+ current_user_matches_store_user: true,+ });+ expect(+ screen.queryByText(/Please ask a Metabase Store Admin/),+ ).not.toBeInTheDocument();+ expect(+ screen.getByRole("checkbox", { name: /Terms of Service/ }),+ ).not.toBeChecked();+ expect(+ screen.getByRole("button", { name: /Add Metabot AI/ }),+ ).toBeDisabled();+ await userEvent.click(+ screen.getByRole("checkbox", { name: /Terms of Service/ }),+ );+ expect(+ screen.getByRole("checkbox", { name: /Terms of Service/ }),+ ).toBeChecked();+ expect(+ screen.getByRole("button", { name: /Add Metabot AI/ }),+ ).toBeEnabled();+ });++ it("submits a HTTP request", async () => {+ await setup({+ current_user_matches_store_user: true,+ });+ await userEvent.click(+ screen.getByRole("checkbox", { name: /Terms of Service/ }),+ );++ await userEvent.click(+ screen.getByRole("button", { name: /Add Metabot AI/ }),+ );+ expect(screen.getByRole("button", { name: /Success/ })).toBeInTheDocument();++ expect(+ await screen.findByText(/Setting up Metabot AI, please wait/),+ ).toBeInTheDocument();+ expect(screen.getByRole("button", { name: /Done/ })).toBeDisabled();++ const postRequests = await findRequests("POST");+ const cloudAddOnsRequest = postRequests.find(({ url }) =>+ /\/api\/ee\/cloud-add-ons\/metabase-ai$/.test(url),+ );+ expect(cloudAddOnsRequest).toBeTruthy();+ expect("terms_of_service" in cloudAddOnsRequest?.body).toBeTruthy();+ expect(cloudAddOnsRequest?.body?.terms_of_service).toEqual(true);++ setupRefreshableProperties({+ current_user_matches_store_user: true,+ has_metabot_v3: true,+ });+ expect(await screen.findByText(/Metabot AI is ready/)).toBeInTheDocument();+ expect(screen.getByRole("button", { name: /Done/ })).toBeEnabled();+ });+});diff --git a/enterprise/frontend/src/metabase-enterprise/metabot/components/MetabotAdmin/MetabotPurchaseSettingUpModal.tsx b/enterprise/frontend/src/metabase-enterprise/metabot/components/MetabotAdmin/MetabotPurchaseSettingUpModal.tsxnew file mode 100644index 00000000000..cfe471f726e--- /dev/null+++ b/enterprise/frontend/src/metabase-enterprise/metabot/components/MetabotAdmin/MetabotPurchaseSettingUpModal.tsx@@ -0,0 +1,94 @@+import { t } from "ttag";++import MetabotCloudIcon from "assets/img/metabot-cloud-96x96.svg";+import { useTokenRefreshUntil } from "metabase/api/utils";+import {+ Box,+ Button,+ Flex,+ Image,+ Loader,+ Modal,+ type ModalProps,+ Stack,+ Text,+ Title,+} from "metabase/ui";+import { hasPremiumFeature } from "metabase-enterprise/settings";++export const MetabotPurchaseSettingUpModal = ({+ onClose,+ opened,+}: Pick<ModalProps, "opened" | "onClose">) => {+ useTokenRefreshUntil("metabot-v3", { intervalMs: 1000, skip: !opened });+ const isSettingUp = !hasPremiumFeature("metabot_v3");++ return (+ <Modal+ opened={opened}+ onClose={onClose}+ closeOnClickOutside={false}+ closeOnEscape={false}+ withCloseButton={false}+ size="30rem"+ padding="2.5rem"+ mah="80%"+ >+ <Stack align="center" gap="lg" my="4.5rem">+ <Box h={96} pos="relative" w={96}>+ <Image src={MetabotCloudIcon} h={96} w={96} alt={t`Metabot Cloud`} />++ {isSettingUp && (+ <Flex+ bottom={0}+ align="center"+ direction="row"+ gap={0}+ justify="center"+ pos="absolute"+ right={0}+ wrap="nowrap"+ bg="white"+ fz={0}+ p="sm"+ ta="center"+ style={{+ borderRadius: "100%",+ boxShadow: `0 1px 6px 0 var(--mb-color-shadow)`,+ }}+ >+ <Loader size="xs" ml={1} mt={1} />+ </Flex>+ )}+ </Box>+ {isSettingUp ? (+ <Box ta="center">+ <Title c="text-primary" fz="lg">+ {t`Setting up Metabot AI, please wait`}+ </Title>+ <Text c="text-secondary" fz="md" lh={1.43}>+ {t`This will take just a minute or so`}+ </Text>+ </Box>+ ) : (+ <Box ta="center">+ <Title c="text-primary" fz="lg">+ {t`Metabot AI is ready`}+ </Title>+ <Text c="text-secondary" fz="md" lh={1.43}>+ {t`Happy exploring!`}+ </Text>+ </Box>+ )}+ <Button+ disabled={isSettingUp}+ variant="filled"+ size="md"+ onClick={onClose}+ >+ {t`Done`}+ </Button>+ </Stack>+ </Modal>+ );+};diff --git a/enterprise/frontend/src/metabase-enterprise/metabot/index.tsx b/enterprise/frontend/src/metabase-enterprise/metabot/index.tsxindex 0746ca1c4e2..6399be6d62c 100644--- a/enterprise/frontend/src/metabase-enterprise/metabot/index.tsx+++ b/enterprise/frontend/src/metabase-enterprise/metabot/index.tsx@@ -3,9 +3,11 @@ import { IndexRoute } from "react-router";import { t } from "ttag";import { createAdminRouteGuard } from "metabase/admin/utils";+import { AdminSettingsLayout } from "metabase/common/components/AdminLayout/AdminSettingsLayout";import { Route } from "metabase/hoc/Title";import type { PaletteAction } from "metabase/palette/types";import { PLUGIN_METABOT, PLUGIN_REDUCERS } from "metabase/plugins";+import { MetabotPurchasePage } from "metabase-enterprise/metabot/components/MetabotAdmin/MetabotPurchasePage";import { hasPremiumFeature } from "metabase-enterprise/settings";import { Metabot } from "./components/Metabot";@@ -20,17 +22,16 @@ if (hasPremiumFeature("metabot_v3")) {PLUGIN_METABOT.isEnabled = () => true;PLUGIN_METABOT.Metabot = Metabot;- PLUGIN_METABOT.adminNavItem = [+ PLUGIN_METABOT.getMetabotRoutes = getMetabotQuickLinks;++ PLUGIN_METABOT.getAdminPaths = () => [{name: t`AI`,path: "/admin/metabot",key: "metabot",},];-- PLUGIN_METABOT.getMetabotRoutes = getMetabotQuickLinks;-- PLUGIN_METABOT.AdminRoute = (+ PLUGIN_METABOT.getAdminRoutes = () => (<Routekey="metabot"path="metabot"@@ -70,6 +71,21 @@ if (hasPremiumFeature("metabot_v3")) {PLUGIN_METABOT.SearchButton = MetabotSearchButton;PLUGIN_REDUCERS.metabotPlugin = metabotReducer;+} else if (hasPremiumFeature("offer_metabase_ai")) {+ PLUGIN_METABOT.getAdminPaths = () => [+ {+ name: t`AI`,+ path: "/admin/metabot",+ key: "metabot",+ },+ ];+ PLUGIN_METABOT.getAdminRoutes = () => (+ <Route path="metabot" component={createAdminRouteGuard("metabot")}>+ <Route title={t`AI`} component={AdminSettingsLayout}>+ <IndexRoute component={MetabotPurchasePage} />+ </Route>+ </Route>+ );}/**diff --git a/frontend/src/metabase-types/api/metabot.ts b/frontend/src/metabase-types/api/metabot.tsindex 9fc1f631fc8..6196885768f 100644--- a/frontend/src/metabase-types/api/metabot.ts+++ b/frontend/src/metabase-types/api/metabot.ts@@ -245,3 +245,9 @@ export interface MetabotGenerateContentResponse {description: string;error: string | null;}++/* Metabot v3 - Add-on Purchase Types */++export interface PurchaseMetabotAddOnRequest {+ terms_of_service: boolean;+}diff --git a/frontend/src/metabase-types/api/mocks/settings.ts b/frontend/src/metabase-types/api/mocks/settings.tsindex 1655ca56f46..a33b5036ea5 100644--- a/frontend/src/metabase-types/api/mocks/settings.ts+++ b/frontend/src/metabase-types/api/mocks/settings.ts@@ -132,6 +132,7 @@ export const createMockTokenFeatures = (ai_entity_analysis: false,ai_sql_fixer: false,ai_sql_generation: false,+ offer_metabase_ai: false,database_routing: false,development_mode: false,documents: false,diff --git a/frontend/src/metabase-types/api/settings.ts b/frontend/src/metabase-types/api/settings.tsindex 2632729dd6c..650c4cca4bb 100644--- a/frontend/src/metabase-types/api/settings.ts+++ b/frontend/src/metabase-types/api/settings.ts@@ -210,6 +210,7 @@ const tokenStatusFeatures = ["metabase-store-managed","metabot-v3","no-upsell",+ "offer-metabase-ai","official-collections","query-reference-validation","question-error-logs",@@ -230,6 +231,10 @@ const tokenStatusFeatures = [export type TokenStatusFeature = (typeof tokenStatusFeatures)[number];+interface TokenStatusStoreUsers {+ email: string;+}+export interface TokenStatus {status: TokenStatusStatus;valid: boolean;@@ -237,6 +242,7 @@ export interface TokenStatus {"error-details"?: string;trial?: boolean;features?: TokenStatusFeature[];+ "store-users"?: TokenStatusStoreUsers[];}export type DayOfWeekId =@@ -279,6 +285,7 @@ export const tokenFeatures = ["collection_cleanup","cache_preemptive","metabot_v3",+ "offer_metabase_ai","ai_sql_fixer","ai_sql_generation","ai_entity_analysis",diff --git a/frontend/src/metabase/admin/app/reducers.ts b/frontend/src/metabase/admin/app/reducers.tsindex f642d5735b1..bdb220d9357 100644--- a/frontend/src/metabase/admin/app/reducers.ts+++ b/frontend/src/metabase/admin/app/reducers.ts@@ -23,6 +23,7 @@ export const getAdminPaths: () => AdminPath[] = () => {path: "/admin/databases",key: "databases",},+ ...PLUGIN_METABOT.getAdminPaths(),{name: t`Table Metadata`,path: "/admin/datamodel",@@ -49,7 +50,6 @@ export const getAdminPaths: () => AdminPath[] = () => {path: "/admin/tools",key: "tools",},- ...PLUGIN_METABOT.adminNavItem,];return items;diff --git a/frontend/src/metabase/admin/routes.jsx b/frontend/src/metabase/admin/routes.jsxindex 91bbd0e85b4..141e2bab719 100644--- a/frontend/src/metabase/admin/routes.jsx+++ b/frontend/src/metabase/admin/routes.jsx@@ -168,7 +168,7 @@ const getRoutes = (store, CanAccessSettings, IsAdmin) => (/></Route></Route>- {PLUGIN_METABOT.AdminRoute}+ {PLUGIN_METABOT.getAdminRoutes()}<Route path="tools" component={createAdminRouteGuard("tools")}><Route title={t`Tools`} component={ToolsApp}><IndexRedirect to="help" />diff --git a/frontend/src/metabase/api/metabot.ts b/frontend/src/metabase/api/metabot.tsnew file mode 100644index 00000000000..796a1fe3e57--- /dev/null+++ b/frontend/src/metabase/api/metabot.ts@@ -0,0 +1,20 @@+import type { PurchaseMetabotAddOnRequest } from "metabase-types/api/metabot";++import { Api } from "./api";++export const metabotCloudAddOnApi = Api.injectEndpoints({+ endpoints: (builder) => ({+ purchaseMetabotCloudAddOn: builder.mutation<+ void,+ PurchaseMetabotAddOnRequest+ >({+ query: (body) => ({+ method: "POST",+ url: "/api/ee/cloud-add-ons/metabase-ai",+ body,+ }),+ }),+ }),+});++export const { usePurchaseMetabotCloudAddOnMutation } = metabotCloudAddOnApi;diff --git a/frontend/src/metabase/api/utils/use-token-refresh.ts b/frontend/src/metabase/api/utils/use-token-refresh.tsindex 484286ae82d..4656eeba48b 100644--- a/frontend/src/metabase/api/utils/use-token-refresh.ts+++ b/frontend/src/metabase/api/utils/use-token-refresh.ts@@ -2,6 +2,7 @@ import { useEffect } from "react";import { Api, useGetSettingsQuery } from "metabase/api";import { useDispatch } from "metabase/lib/redux";+import type { TokenStatusFeature } from "metabase-types/api";const REFRESH_INTERVAL = 10 * 1000; // 10 seconds@@ -29,3 +30,37 @@ export function useTokenRefresh() {}}, [res, dispatch]);}++/**+ * In some circumstances, a metabase instance may expect to see a certain token feature.+ * This hook will keep refreshing the session properties every 10 seconds until it gets+ * a payload with the expected token feature. This is logically the opposite of+ * `useTokenRefresh`.+ */+export function useTokenRefreshUntil(+ tokenFeature: TokenStatusFeature,+ {+ intervalMs = REFRESH_INTERVAL,+ skip = false,+ }: { intervalMs?: number; skip?: boolean },+) {+ /* in order to force this hook to re-run on every request, even if the response data is the same, we can't destructure only the data prop from this hook, as is the patten in many components */+ const res = useGetSettingsQuery();+ const dispatch = useDispatch();++ useEffect(() => {+ if (skip) {+ return;+ }++ const tokenStatusFeatures = res?.data?.["token-status"]?.features;+ const isTokenFeatureMissing = !tokenStatusFeatures?.includes(tokenFeature);++ if (isTokenFeatureMissing) {+ const timeout = setTimeout(() => {+ dispatch(Api.util.invalidateTags(["session-properties"]));+ }, intervalMs);+ return () => clearTimeout(timeout);+ }+ }, [res, dispatch, tokenFeature, intervalMs, skip]);+}diff --git a/frontend/src/metabase/common/components/AdminLayout/AdminSettingsLayout.tsx b/frontend/src/metabase/common/components/AdminLayout/AdminSettingsLayout.tsxindex c60cd75878d..4de4c46c09a 100644--- a/frontend/src/metabase/common/components/AdminLayout/AdminSettingsLayout.tsx+++ b/frontend/src/metabase/common/components/AdminLayout/AdminSettingsLayout.tsx@@ -12,16 +12,18 @@ export const AdminSettingsLayout = ({children,maw = "50rem",}: {- sidebar: React.ReactNode;+ sidebar?: React.ReactNode;children?: React.ReactNode;maw?: string;}) => {return (<Box className={S.Wrapper}><Box className={S.Main}>- <Box className={S.Sidebar} data-testid="admin-layout-sidebar">- {sidebar}- </Box>+ {sidebar && (+ <Box className={S.Sidebar} data-testid="admin-layout-sidebar">+ {sidebar}+ </Box>+ )}<Box className={S.Content} data-testid="admin-layout-content"><Box maw={maw} w="100%"><Box pb="2rem">diff --git a/frontend/src/metabase/plugins/index.ts b/frontend/src/metabase/plugins/index.tsindex 62f7a68d358..ffc8431c8d1 100644--- a/frontend/src/metabase/plugins/index.ts+++ b/frontend/src/metabase/plugins/index.ts@@ -724,8 +724,8 @@ export const PLUGIN_METABOT = {},useMetabotPalletteActions: (_searchText: string) =>useMemo(() => [] as PaletteAction[], []),- adminNavItem: [] as AdminPath[],- AdminRoute: PluginPlaceholder as unknown as React.ReactElement,+ getAdminPaths: () => [] as AdminPath[],+ getAdminRoutes: () => PluginPlaceholder as unknown as React.ReactElement,getMetabotRoutes: () => null as React.ReactElement | null,MetabotAdminPage: () => `placeholder`,getMetabotVisible: (_state: State) => false,diff --git a/resources/frontend_client/app/assets/img/metabot-cloud-96x96.svg b/resources/frontend_client/app/assets/img/metabot-cloud-96x96.svgnew file mode 100644index 00000000000..5a52392c236--- /dev/null+++ b/resources/frontend_client/app/assets/img/metabot-cloud-96x96.svg@@ -0,0 +1,31 @@+<svg width="96" height="96" viewBox="0 0 96 96" fill="none" xmlns="http://www.w3.org/2000/svg">+<g clip-path="url(#clip0_18354_823)">+<circle cx="48" cy="48" r="48" fill="#0572D2" fill-opacity="0.07"/>+<path d="M24 35.0004C24 32.7912 25.7909 31.0004 28 31.0004H68C70.2091 31.0004 72 32.7912 72 35.0004V61.0004C72 63.2095 70.2091 65.0004 68 65.0004H28C25.7909 65.0004 24 63.2095 24 61.0004V35.0004Z" fill="#0572D2" fill-opacity="0.07"/>+<path d="M71.375 35.0004C71.375 33.1364 69.864 31.6254 68 31.6254H28C26.136 31.6254 24.625 33.1364 24.625 35.0004V61.0004C24.625 62.8643 26.136 64.3754 28 64.3754H68C69.864 64.3754 71.375 62.8643 71.375 61.0004V35.0004ZM72.625 61.0004C72.625 63.5547 70.5543 65.6254 68 65.6254H28C25.4457 65.6254 23.375 63.5547 23.375 61.0004V35.0004C23.375 32.446 25.4457 30.3754 28 30.3754H68C70.5543 30.3754 72.625 32.446 72.625 35.0004V61.0004Z" fill="#509EE3"/>+<path d="M29.5 38.0004C29.5 37.1719 30.1716 36.5004 31 36.5004H65C65.8284 36.5004 66.5 37.1719 66.5 38.0004V55.0004C66.5 55.8288 65.8284 56.5004 65 56.5004H31C30.1716 56.5004 29.5 55.8288 29.5 55.0004V38.0004Z" fill="white"/>+<path d="M65.875 38.0004C65.875 37.5171 65.4832 37.1254 65 37.1254H31C30.5168 37.1254 30.125 37.5171 30.125 38.0004V55.0004C30.125 55.4836 30.5168 55.8754 31 55.8754H65C65.4832 55.8754 65.875 55.4836 65.875 55.0004V38.0004ZM67.125 55.0004C67.125 56.174 66.1736 57.1254 65 57.1254H31C29.8264 57.1254 28.875 56.174 28.875 55.0004V38.0004C28.875 36.8268 29.8264 35.8754 31 35.8754H65C66.1736 35.8754 67.125 36.8268 67.125 38.0004V55.0004Z" fill="#509EE3"/>+<path d="M61.536 60.7142C61.5358 60.4579 61.3275 60.2503 61.0712 60.2503C60.8151 60.2505 60.6076 60.4581 60.6074 60.7142C60.6074 60.9704 60.815 61.1788 61.0712 61.179V62.4289L60.8964 62.4201C60.032 62.3324 59.3574 61.6018 59.3574 60.7142C59.3576 59.7678 60.1248 59.0006 61.0712 59.0004C62.0178 59.0004 62.7858 59.7676 62.786 60.7142L62.7772 60.8899C62.6894 61.7543 61.9588 62.4289 61.0712 62.4289V61.179C61.3276 61.179 61.536 60.9706 61.536 60.7142Z" fill="#509EE3"/>+<path d="M66.036 60.7142C66.0358 60.4579 65.8275 60.2503 65.5712 60.2503C65.3151 60.2505 65.1076 60.4581 65.1074 60.7142C65.1074 60.9704 65.315 61.1788 65.5712 61.179V62.4289L65.3964 62.4201C64.532 62.3324 63.8574 61.6018 63.8574 60.7142C63.8576 59.7678 64.6248 59.0006 65.5712 59.0004C66.5178 59.0004 67.2858 59.7676 67.286 60.7142L67.2772 60.8899C67.1894 61.7543 66.4588 62.4289 65.5712 62.4289V61.179C65.8276 61.179 66.036 60.9706 66.036 60.7142Z" fill="#509EE3"/>+<circle cx="41" cy="43.5" r="1.5" fill="#509EE3"/>+<circle cx="55" cy="43.5" r="1.5" fill="#509EE3"/>+<path d="M46.375 47.5C46.375 48.0967 46.5718 48.4831 46.833 48.7246C47.1025 48.9735 47.5027 49.125 48 49.125C48.4973 49.125 48.8975 48.9735 49.167 48.7246C49.4282 48.4831 49.625 48.0967 49.625 47.5H50.875C50.875 48.3943 50.5676 49.1328 50.0146 49.6436C49.4698 50.1466 48.7452 50.375 48 50.375C47.2548 50.375 46.5302 50.1466 45.9854 49.6436C45.4324 49.1328 45.125 48.3943 45.125 47.5H46.375Z" fill="#509EE3"/>+<path d="M16.625 51V53H15.375V51H16.625Z" fill="#509EE3"/>+<path d="M13 53.375L15 53.375L15 54.625L13 54.625L13 53.375Z" fill="#509EE3"/>+<path d="M16.625 55V57H15.375V55H16.625Z" fill="#509EE3"/>+<path d="M17 53.375L19 53.375L19 54.625L17 54.625L17 53.375Z" fill="#509EE3"/>+<g opacity="0.5">+<path d="M43.625 75V77H42.375V75H43.625Z" fill="#509EE3"/>+<path d="M40 77.375L42 77.375L42 78.625L40 78.625L40 77.375Z" fill="#509EE3"/>+<path d="M43.625 79V81H42.375V79H43.625Z" fill="#509EE3"/>+<path d="M44 77.375L46 77.375L46 78.625L44 78.625L44 77.375Z" fill="#509EE3"/>+</g>+<path fill-rule="evenodd" clip-rule="evenodd" d="M27.7637 61.0103C24.4491 61.1925 21.8203 63.8045 21.8203 67.0001C21.8203 70.3137 24.6471 73 28.1342 73H42.8665C46.3535 73 49.1803 70.3137 49.1803 67.0001C49.1803 63.8045 46.5515 61.1925 43.2369 61.0103C42.5099 57.5818 39.3223 55 35.5003 55C31.6782 55 28.4907 57.5818 27.7637 61.0103Z" fill="#0572D2" fill-opacity="0.15"/>+<path d="M32.5 52.625C36.0423 52.625 38.9623 55.0152 39.625 58.1396L39.7246 58.6084L40.2021 58.6348C43.2153 58.8004 45.5556 61.1654 45.5557 64C45.5557 66.9388 43.0385 69.375 39.8662 69.375H25.1338C21.9617 69.3748 19.4453 66.9387 19.4453 64C19.4454 61.1655 21.7848 58.8005 24.7979 58.6348L25.2754 58.6084L25.375 58.1396C26.0377 55.0152 28.9577 52.6251 32.5 52.625Z" fill="white" stroke="#509EE3" stroke-width="1.25"/>+</g>+<defs>+<clipPath id="clip0_18354_823">+<rect width="96" height="96" fill="white"/>+</clipPath>+</defs>+</svg>diff --git a/src/metabase/cloud_migration/core.clj b/src/metabase/cloud_migration/core.cljindex bacc66eab71..d6d64d330d5 100644--- a/src/metabase/cloud_migration/core.clj+++ b/src/metabase/cloud_migration/core.clj@@ -8,6 +8,4 @@(p/import-vars[metabase.cloud-migration.settingsread-only-mode- read-only-mode!-- store-api-url])+ read-only-mode!])diff --git a/src/metabase/cloud_migration/models/cloud_migration.clj b/src/metabase/cloud_migration/models/cloud_migration.cljindex 015c2d80e6e..679bc26a0d0 100644--- a/src/metabase/cloud_migration/models/cloud_migration.clj+++ b/src/metabase/cloud_migration/models/cloud_migration.clj@@ -11,6 +11,7 @@[metabase.config.core :as config][metabase.models.interface :as mi][metabase.settings.core :as setting]+ [metabase.store-api.core :as store-api][metabase.task.bootstrap :as task.bootstrap][metabase.task.core :as task][metabase.util :as u]@@ -76,7 +77,7 @@(defn migration-url"Store API URL for migrations."([]- (str (cloud-migration.settings/store-api-url) "/api/v2/migration"))+ (str (store-api/store-api-url) "/api/v2/migration"))([external-id path](str (migration-url) "/" external-id path)))@@ -279,7 +280,7 @@;; test settings you might want to change manually;; local HM store api url- #_(cloud-migration.settings/store-api-url! "http://localhost:5010")+ #_(store-api/store-api-url! "http://localhost:5010");; make sure to use a version that store supports, and a dump for that version.#_(cloud-migration.settings/migration-dump-version! "v0.49.7");; make a new dump with any released metabase jar using the command below:diff --git a/src/metabase/cloud_migration/settings.clj b/src/metabase/cloud_migration/settings.cljindex cb60a62acd2..3899647473f 100644--- a/src/metabase/cloud_migration/settings.clj+++ b/src/metabase/cloud_migration/settings.clj@@ -45,15 +45,6 @@:doc false:export? false)-(defsetting store-api-url- (deferred-tru "Store API URL.")- :type :string- :encryption :no- :visibility :internal- :default (str "https://store-api" (when (default-to-staging?) ".staging") ".metabase.com")- :doc false- :export? false)-(defsetting migration-dump-file(deferred-tru "Dump file for migrations."):encryption :nodiff --git a/src/metabase/core/init.clj b/src/metabase/core/init.cljindex 234bb13d9ce..a789f8db100 100644--- a/src/metabase/core/init.clj+++ b/src/metabase/core/init.clj@@ -52,6 +52,7 @@[metabase.settings.init][metabase.setup.init][metabase.sso.init]+ [metabase.store-api.init][metabase.sync.init][metabase.system.init][metabase.task-history.init]diff --git a/src/metabase/premium_features/core.clj b/src/metabase/premium_features/core.cljindex f4235c4d53f..1cf975af314 100644--- a/src/metabase/premium_features/core.clj+++ b/src/metabase/premium_features/core.clj@@ -28,7 +28,8 @@log-enabled?max-users-allowedplan-alias- TokenStatus]+ TokenStatus+ clear-cache](metabase.premium-features.settingsactive-users-count@@ -76,6 +77,7 @@has-attached-dwh?hide-embed-branding?is-hosted?+ offer-metabase-ai?premium-embedding-tokensite-uuid-for-premium-features-token-checkstable-data-editing?diff --git a/src/metabase/premium_features/settings.clj b/src/metabase/premium_features/settings.cljindex b1aded53e76..58b167b60f3 100644--- a/src/metabase/premium_features/settings.clj+++ b/src/metabase/premium_features/settings.clj@@ -259,6 +259,10 @@"Should Metabase do AI analysis on entities?":ai-entity-analysis)+(define-premium-feature ^{:added "0.55.0"} offer-metabase-ai?+ "Offer Metabase AI add-on"+ :offer-metabase-ai)+(define-premium-feature ^{:added "0.56.0"} cloud-custom-smtp?"Can Metabase have a custom smtp details separate from the default Cloud details.":cloud-custom-smtp)@@ -317,6 +321,7 @@:hosting (is-hosted?):llm_autodescription (enable-llm-autodescription?):metabot_v3 (enable-metabot-v3?)+ :offer_metabase_ai (offer-metabase-ai?):official_collections (enable-official-collections?):query_reference_validation (enable-query-reference-validation?):sandboxes (enable-sandboxes?)diff --git a/src/metabase/premium_features/token_check.clj b/src/metabase/premium_features/token_check.cljindex 41e6b5d071a..453e4912e09 100644--- a/src/metabase/premium_features/token_check.clj+++ b/src/metabase/premium_features/token_check.clj@@ -129,7 +129,9 @@[:trial {:optional true} :boolean][:valid-thru {:optional true} [:string {:min 1}]][:max-users {:optional true} pos-int?]- [:company {:optional true} [:string {:min 1}]]])+ [:company {:optional true} [:string {:min 1}]]+ [:store-users {:optional true} [:maybe [:sequential [:map+ [:email :string]]]]]])(def ^:private ^:const token-status-cache-ttl"Amount of time in ms to cache the status of a valid enterprise token before forcing a re-check."@@ -201,6 +203,11 @@(catch dev.failsafe.FailsafeException e(throw (.getCause e)))))+(defn clear-cache+ "Clear the token cache so that [[fetch-token-and-parse-body]] will return the latest data."+ []+ (memoize/memo-clear! fetch-token-and-parse-body*))+;;;;;;;;;;;;;;;;;;;; Airgap Tokens ;;;;;;;;;;;;;;;;;;;;(declare decode-airgap-token)diff --git a/src/metabase/server/middleware/security.clj b/src/metabase/server/middleware/security.cljindex 52a117e31c2..06566e336f4 100644--- a/src/metabase/server/middleware/security.clj+++ b/src/metabase/server/middleware/security.clj@@ -168,7 +168,8 @@;; CLJS REPL(when config/is-dev?"ws://*:9630")]- :manifest-src ["'self'"]}]+ :manifest-src ["'self'"]+ :media-src ["www.metabase.com"]}](format "%s %s; " (name k) (str/join " " vs))))})(defn- content-security-policy-header-with-frame-ancestorsdiff --git a/src/metabase/store_api/core.clj b/src/metabase/store_api/core.cljnew file mode 100644index 00000000000..ce403610686--- /dev/null+++ b/src/metabase/store_api/core.clj@@ -0,0 +1,9 @@+(ns metabase.store-api.core+ (:require+ [metabase.store-api.settings]+ [potemkin :as p]))++(p/import-vars+ [metabase.store-api.settings+ store-api-url+ store-api-url!])diff --git a/src/metabase/store_api/init.clj b/src/metabase/store_api/init.cljnew file mode 100644index 00000000000..cf840e6f425--- /dev/null+++ b/src/metabase/store_api/init.clj@@ -0,0 +1,3 @@+(ns metabase.store-api.init+ (:require+ [metabase.store-api.settings]))diff --git a/src/metabase/store_api/settings.clj b/src/metabase/store_api/settings.cljnew file mode 100644index 00000000000..51f47defce4--- /dev/null+++ b/src/metabase/store_api/settings.clj@@ -0,0 +1,23 @@+(ns metabase.store-api.settings+ (:require+ [metabase.config.core :as config]+ [metabase.settings.core :refer [defsetting]]+ [metabase.util.i18n :refer [deferred-tru]]))++(defn- default-to-staging?+ "It's against the rules to use setting values on namespace load, since they need the app DB to be loaded, and it isn't+ yet. So this is here so we can define default values for the settings below based on the env var value+ of [[store-use-staging]]."+ []+ (if-some [env-var-value (config/config-bool :mb-store-use-staging)]+ env-var-value+ config/is-dev?))++(defsetting store-api-url+ (deferred-tru "Store API URL.")+ :type :string+ :encryption :no+ :visibility :internal+ :default (str "https://store-api" (when (default-to-staging?) ".staging") ".metabase.com")+ :doc false+ :export? false)diff --git a/test/metabase/analytics/stats_test.clj b/test/metabase/analytics/stats_test.cljindex c61356cecf6..039b9a322ed 100644--- a/test/metabase/analytics/stats_test.clj+++ b/test/metabase/analytics/stats_test.clj@@ -550,7 +550,8 @@:llm-autodescription:query-reference-validation:cloud-custom-smtp- :session-timeout-config})+ :session-timeout-config+ :offer-metabase-ai})(deftest every-feature-is-accounted-for-test(testing "Is every premium feature either tracked under the :features key, or intentionally excluded?"