Skip to content

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

UXW-4235 Transforms nav item permissions (#76705)

Denis Berezin5c6e3e71fe0e
diff --git a/enterprise/backend/src/metabase_enterprise/advanced_permissions/common.clj b/enterprise/backend/src/metabase_enterprise/advanced_permissions/common.clj
index 1216739c42a..80ea6c226cd 100644
--- a/enterprise/backend/src/metabase_enterprise/advanced_permissions/common.clj
+++ b/enterprise/backend/src/metabase_enterprise/advanced_permissions/common.clj
@@ -76,7 +76,7 @@
:can_access_data_model can-access-data-model
:can_access_db_details (perms/user-has-any-perms-of-type? user-id :perms/manage-database)
:can_access_transforms (or api/*is-superuser?* (and api/*is-data-analyst?*
- (perms/user-has-any-perms-of-type? api/*current-user-id* :perms/view-data
+ (perms/user-has-any-perms-of-type? api/*current-user-id* :perms/transforms
:exclude-db-ids [audit/audit-db-id])))
:can_access_workspaces (or api/*is-superuser?* (and api/*is-data-analyst?*
(perms/user-has-any-perms-of-type? api/*current-user-id* :perms/view-data
diff --git a/enterprise/backend/test/metabase_enterprise/advanced_permissions/common_test.clj b/enterprise/backend/test/metabase_enterprise/advanced_permissions/common_test.clj
index 5bd1d5d530b..76a93dd1991 100644
--- a/enterprise/backend/test/metabase_enterprise/advanced_permissions/common_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/advanced_permissions/common_test.clj
@@ -7,6 +7,7 @@
[metabase.permissions.models.data-permissions :as data-perms]
[metabase.permissions.models.permissions :as perms]
[metabase.permissions.models.permissions-group :as perms-group]
+ [metabase.permissions.test-util :as perms.test-util]
[metabase.test :as mt]
[metabase.test.data.sql :as sql.tx]
[metabase.test.fixtures :as fixtures]
@@ -55,7 +56,24 @@
(testing "can_access_db_details is true if a user has any details perms"
(mt/with-all-users-data-perms-graph! {(mt/id) {:details :yes}}
(is (partial= {:can_access_db_details true}
- (user-permissions :rasta)))))))))
+ (user-permissions :rasta)))))
+ (testing "can_access_transforms requires the transforms permission, not just view-data"
+ (perms.test-util/with-data-analyst-role! (mt/user->id :rasta)
+ (testing "false when the user has view-data but no transforms permission on any database"
+ (mt/with-all-users-data-perms-graph! {(mt/id) {:view-data :unrestricted
+ :create-queries :query-builder-and-native
+ :transforms :no}}
+ (is (partial= {:can_access_transforms false}
+ (user-permissions :rasta)))))
+ (testing "true when the user has the transforms permission on a database"
+ (mt/with-all-users-data-perms-graph! {(mt/id) {:view-data :unrestricted
+ :create-queries :query-builder-and-native
+ :transforms :yes}}
+ (is (partial= {:can_access_transforms true}
+ (user-permissions :rasta)))))))
+ (testing "can_access_transforms is true for superusers regardless of the transforms permission"
+ (is (partial= {:can_access_transforms true}
+ (user-permissions :crowberto))))))))
(deftest current-user-query-permissions-published-table-test
(testing "GET /api/user/current can_create_queries respects published tables"
diff --git a/enterprise/frontend/src/metabase-enterprise/feature_level_permissions/utils.tsx b/enterprise/frontend/src/metabase-enterprise/feature_level_permissions/utils.tsx
index 7bb75e1e0ab..fd7f7773047 100644
--- a/enterprise/frontend/src/metabase-enterprise/feature_level_permissions/utils.tsx
+++ b/enterprise/frontend/src/metabase-enterprise/feature_level_permissions/utils.tsx
@@ -63,12 +63,13 @@ export const getDataColumns = ({
});
if (showTransformPermissions) {
+ const transformsDescription = t`This lets users see, edit, and run transforms based on this database.`;
allSubjectsColumns.push({
name: t`Transforms`,
hint:
groupType === "analyst" || groupType === "admin"
- ? null
- : jt`Users must also be a member of the ${(
+ ? transformsDescription
+ : jt`${transformsDescription} Users must also be a member of the ${(
<Link
key="link"
to="/admin/people"
diff --git a/enterprise/frontend/src/metabase-enterprise/feature_level_permissions/utils.unit.spec.ts b/enterprise/frontend/src/metabase-enterprise/feature_level_permissions/utils.unit.spec.ts
index 98c57184fdc..12e9d896af7 100644
--- a/enterprise/frontend/src/metabase-enterprise/feature_level_permissions/utils.unit.spec.ts
+++ b/enterprise/frontend/src/metabase-enterprise/feature_level_permissions/utils.unit.spec.ts
@@ -26,10 +26,33 @@ describe("getDataColumns", () => {
},
{ name: "Manage table metadata" },
{ name: "Manage database" },
- { name: "Transforms", hint: null },
+ {
+ name: "Transforms",
+ hint: "This lets users see, edit, and run transforms based on this database.",
+ },
]);
});
+ it("explains the Transforms permission and notes the Data Analysts requirement for non-analyst groups", () => {
+ PLUGIN_TRANSFORMS.isEnabled = true;
+
+ const columns = getDataColumns({
+ subject: "schemas",
+ showTransformPermissions: true,
+ });
+ const transformsColumn = columns.find(
+ ({ name }) => name === "Transforms",
+ );
+
+ expect(transformsColumn?.hint).not.toBeNull();
+ // `jt` returns an array of nodes; the description is the leading string.
+ expect(transformsColumn?.hint).toEqual(
+ expect.arrayContaining([
+ "This lets users see, edit, and run transforms based on this database.",
+ ]),
+ );
+ });
+
it("returns 3 permissions when the transform token feature is disabled", () => {
expect(getDataColumns({ subject: "schemas" })).toStrictEqual([
{
diff --git a/frontend/src/metabase/data-studio/app/pages/DataStudioLayout/tests/enterprise.unit.spec.tsx b/frontend/src/metabase/data-studio/app/pages/DataStudioLayout/tests/enterprise.unit.spec.tsx
index a69a37ecf28..99f14b0cb1e 100644
--- a/frontend/src/metabase/data-studio/app/pages/DataStudioLayout/tests/enterprise.unit.spec.tsx
+++ b/frontend/src/metabase/data-studio/app/pages/DataStudioLayout/tests/enterprise.unit.spec.tsx
@@ -206,6 +206,46 @@ describe("DataStudioLayout", () => {
});
});
+ describe("transforms tab visibility", () => {
+ it("should show Transforms tab for admins", async () => {
+ setup({ ...DEFAULT_EE_SETTINGS, isAdmin: true });
+
+ await waitFor(() => {
+ expect(screen.getByTestId("data-studio-nav")).toBeInTheDocument();
+ });
+
+ expect(screen.getByLabelText("Transforms")).toBeInTheDocument();
+ });
+
+ it("should show Transforms tab for a non-admin with transforms permission", async () => {
+ setup({
+ ...DEFAULT_EE_SETTINGS,
+ isAdmin: false,
+ canAccessTransforms: true,
+ });
+
+ await waitFor(() => {
+ expect(screen.getByTestId("data-studio-nav")).toBeInTheDocument();
+ });
+
+ expect(screen.getByLabelText("Transforms")).toBeInTheDocument();
+ });
+
+ it("should hide Transforms tab for a non-admin without transforms permission", async () => {
+ setup({
+ ...DEFAULT_EE_SETTINGS,
+ isAdmin: false,
+ canAccessTransforms: false,
+ });
+
+ await waitFor(() => {
+ expect(screen.getByTestId("data-studio-nav")).toBeInTheDocument();
+ });
+
+ expect(screen.queryByLabelText("Transforms")).not.toBeInTheDocument();
+ });
+ });
+
describe("workspaces tab", () => {
it("admin sees the tab and it links to the workspaces index", async () => {
setup({ ...DEFAULT_EE_SETTINGS, isAdmin: true });
diff --git a/frontend/src/metabase/data-studio/app/pages/DataStudioLayout/tests/setup.tsx b/frontend/src/metabase/data-studio/app/pages/DataStudioLayout/tests/setup.tsx
index fb6a4e11893..50ce0625063 100644
--- a/frontend/src/metabase/data-studio/app/pages/DataStudioLayout/tests/setup.tsx
+++ b/frontend/src/metabase/data-studio/app/pages/DataStudioLayout/tests/setup.tsx
@@ -100,12 +100,14 @@ const setupNavbarEndpoints = (isOpened = true) => {
interface StoreStateOptions {
isAdmin?: boolean;
+ canAccessTransforms?: boolean;
remoteSyncSettings?: Partial<RemoteSyncSettings>;
tokenFeatures?: Partial<TokenFeatures>;
}
const createStoreState = ({
isAdmin = true,
+ canAccessTransforms = false,
remoteSyncSettings = {},
tokenFeatures,
}: StoreStateOptions = {}) => {
@@ -117,6 +119,7 @@ const createStoreState = ({
permissions: {
can_access_data_model: isAdmin,
can_access_db_details: false,
+ can_access_transforms: canAccessTransforms,
},
}),
settings: mockSettings({
@@ -130,6 +133,7 @@ interface SetupOpts {
remoteSyncEnabled?: boolean;
remoteSyncBranch?: string | null;
isAdmin?: boolean;
+ canAccessTransforms?: boolean;
currentWorkspace?: CurrentWorkspace | null;
hasDirtyChanges?: boolean;
hasTransformDirtyChanges?: boolean;
@@ -143,6 +147,7 @@ export const setup = ({
remoteSyncEnabled = true,
remoteSyncBranch = null,
isAdmin = true,
+ canAccessTransforms = false,
currentWorkspace = null,
hasDirtyChanges = false,
hasTransformDirtyChanges = false,
@@ -190,6 +195,7 @@ export const setup = ({
const state = createStoreState({
isAdmin,
+ canAccessTransforms,
remoteSyncSettings,
tokenFeatures,
});