Skip to content
Snippets Groups Projects
Unverified Commit edcd2ff7 authored by Sloan Sparger's avatar Sloan Sparger Committed by GitHub
Browse files

Fix "Manage database" perms incorrectly show up on the schema-level permissions page (#43601)

parent fa8c7a23
No related branches found
No related tags found
No related merge requests found
......@@ -22,13 +22,13 @@ import type {
RawGroupRouteParams,
PermissionSectionConfig,
EntityId,
PermissionSubject,
} from "../../types";
import { DataPermissionValue, DataPermission } from "../../types";
import {
getTableEntityId,
getSchemaEntityId,
getDatabaseEntityId,
getPermissionSubject,
} from "../../utils/data-entity-id";
import { hasPermissionValueInEntityGraphs } from "../../utils/graph";
......@@ -189,15 +189,16 @@ export const getDatabasesPermissionEditor = createSelector(
databaseId != null &&
metadata.database(databaseId)?.getSchemas().length === 1;
let entities: EntityWithPermissions[] = [];
const database = metadata?.database(databaseId);
let entities: EntityWithPermissions[] = [];
let permissionSubject: PermissionSubject | null = null;
if (database && (schemaName != null || hasSingleSchema)) {
const schema: Schema = hasSingleSchema
? database.getSchemas()[0]
: (database.schema(schemaName) as Schema);
permissionSubject = "fields";
entities = schema
.getTables()
.sort((a, b) => a.display_name.localeCompare(b.display_name))
......@@ -241,9 +242,11 @@ export const getDatabasesPermissionEditor = createSelector(
};
});
if (maybeDbEntities) {
permissionSubject = "tables";
entities = maybeDbEntities;
}
} else if (groupId != null) {
permissionSubject = "schemas";
entities = metadata
.databasesList({ savedQuestions: false })
.map(database => {
......@@ -266,18 +269,15 @@ export const getDatabasesPermissionEditor = createSelector(
});
}
const permissionSubject = getPermissionSubject(
{ databaseId, schemaName },
hasSingleSchema,
);
const showViewDataColumn = hasViewDataOptions(entities);
const columns = _.compact([
{ name: getEditorEntityName(params, hasSingleSchema) },
showViewDataColumn && { name: t`View data` },
{ name: t`Create queries` },
...PLUGIN_FEATURE_LEVEL_PERMISSIONS.getDataColumns(permissionSubject),
...(permissionSubject
? PLUGIN_FEATURE_LEVEL_PERMISSIONS.getDataColumns(permissionSubject)
: []),
]);
const breadcrumbs = getDatabasesEditorBreadcrumbs(params, metadata, group);
......@@ -364,6 +364,9 @@ export const getGroupsDataPermissionEditor: GetGroupsDataPermissionEditorSelecto
throw new Error("No default group found");
}
const permissionSubject =
tableId != null ? "fields" : schemaName != null ? "tables" : "schemas";
const entities = sortedGroups.map(group => {
const isAdmin = isAdminGroup(group);
let groupPermissions;
......@@ -419,8 +422,6 @@ export const getGroupsDataPermissionEditor: GetGroupsDataPermissionEditorSelecto
};
});
const permissionSubject = getPermissionSubject(params);
const showViewDataColumn = hasViewDataOptions(entities);
const columns = _.compact([
......
......@@ -4,7 +4,7 @@ import type Schema from "metabase-lib/v1/metadata/Schema";
import type Table from "metabase-lib/v1/metadata/Table";
import type { ConcreteTableId } from "metabase-types/api";
import type { EntityId, PermissionSubject } from "../types";
import type { EntityId } from "../types";
export const getDatabaseEntityId = (databaseEntity: Database) => ({
databaseId: databaseEntity.id,
......@@ -29,18 +29,3 @@ export const isDatabaseEntityId = (entityId: Partial<EntityId>) =>
entityId.databaseId != null &&
!isSchemaEntityId(entityId) &&
!isTableEntityId(entityId);
export const getPermissionSubject = (
entityId: Partial<EntityId>,
hasSingleSchema?: boolean,
): PermissionSubject => {
if (isTableEntityId(entityId)) {
return "fields";
}
if (isSchemaEntityId(entityId) || hasSingleSchema) {
return "tables";
}
return "schemas";
};
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment