Skip to content

The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:

Fix @tenant.slug tooltip to read 'system defined' on the create tenant user from (#76321)

Andrei Chernykhc96ad1f49a28
diff --git a/enterprise/frontend/src/metabase-enterprise/sandboxes/utils.tsx b/enterprise/frontend/src/metabase-enterprise/sandboxes/utils.tsx
index d9fe83c4e1f..34a871b92d8 100644
--- a/enterprise/frontend/src/metabase-enterprise/sandboxes/utils.tsx
+++ b/enterprise/frontend/src/metabase-enterprise/sandboxes/utils.tsx
@@ -111,9 +111,10 @@ export const getExtraAttributes = (
// for newly created tenant users, we want to pre-populate their inherited attributes
return {
+ // the slug is system defined and frozen, matching what the backend returns for existing users
[TENANT_SLUG_ATTRIBUTE]: {
value: tenant.slug,
- source: "tenant",
+ source: "system",
frozen: true,
},
...Object.fromEntries(
diff --git a/enterprise/frontend/src/metabase-enterprise/sandboxes/utils.unit.spec.tsx b/enterprise/frontend/src/metabase-enterprise/sandboxes/utils.unit.spec.tsx
new file mode 100644
index 00000000000..d62a7bde661
--- /dev/null
+++ b/enterprise/frontend/src/metabase-enterprise/sandboxes/utils.unit.spec.tsx
@@ -0,0 +1,56 @@
+import type { StructuredUserAttributes } from "metabase-types/api";
+import { createMockTenant } from "metabase-types/api/mocks";
+
+import { getExtraAttributes } from "./utils";
+
+describe("getExtraAttributes", () => {
+ it("synthesizes @tenant.slug as a system-defined, frozen attribute for new tenant users", () => {
+ const tenant = createMockTenant({ slug: "ten01", attributes: {} });
+
+ const attributes = getExtraAttributes(undefined, tenant);
+
+ // must match what the backend returns for existing users so the
+ // "This attribute is system defined" tooltip shows on the create form too
+ expect(attributes?.["@tenant.slug"]).toEqual({
+ value: "ten01",
+ source: "system",
+ frozen: true,
+ });
+ });
+
+ it("synthesizes custom tenant attributes as overridable tenant attributes", () => {
+ const tenant = createMockTenant({
+ slug: "ten01",
+ attributes: { region: "emea" },
+ });
+
+ const attributes = getExtraAttributes(undefined, tenant);
+
+ expect(attributes?.region).toEqual({
+ value: "emea",
+ source: "tenant",
+ frozen: false,
+ });
+ });
+
+ it("returns existing structured attributes untouched when the slug is already present", () => {
+ const tenant = createMockTenant({ slug: "ten01" });
+ const structuredAttributes: StructuredUserAttributes = {
+ "@tenant.slug": { value: "ten01", source: "system", frozen: true },
+ };
+
+ expect(getExtraAttributes(structuredAttributes, tenant)).toBe(
+ structuredAttributes,
+ );
+ });
+
+ it("returns structured attributes unchanged when there is no tenant", () => {
+ const structuredAttributes: StructuredUserAttributes = {
+ region: { value: "emea", source: "tenant", frozen: false },
+ };
+
+ expect(getExtraAttributes(structuredAttributes, undefined)).toBe(
+ structuredAttributes,
+ );
+ });
+});