Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
refactor: introduce WORKSPACE_FEATURE_MATRIX (#3153)
Tianzhou (天舟)e70adc0713b7
diff --git a/frontend/src/types/plan.ts b/frontend/src/types/plan.tsindex 32b23c5cfd..b95e99ff2d 100644--- a/frontend/src/types/plan.ts+++ b/frontend/src/types/plan.ts@@ -67,7 +67,8 @@ export interface Plan {featureList: PlanFeature[];}-// A map from the a particular feature to the respective enablement of a particular plan+// A map from a particular feature to the respective enablement of a particular plan.+// The key is the feature type and the value is the [FREE, TEAM, ENTERPRISE] triplet.// Make sure this is consistent with the matrix in plan.go//// TODO: fetch the matrix from the backend instead of duplicating it here or use a JSON/YAML filediff --git a/frontend/src/utils/role.ts b/frontend/src/utils/role.tsindex 96b98467d3..2d77fa7dd2 100644--- a/frontend/src/utils/role.ts+++ b/frontend/src/utils/role.ts@@ -1,6 +1,28 @@import { ProjectRoleType, RoleType } from "../types";import { hasFeature } from "@/store";+export type WorkspacePermissionType = "bb.permission.workspace.manage-user";++// A map from a particular workspace permission to the respective enablement of a particular workspace role.+// The key is the workspace permission type and the value is the [DEVELOPER, DBA, OWNER] triplet.+export const WORKSPACE_FEATURE_MATRIX: Map<WorkspacePermissionType, boolean[]> =+ new Map([["bb.permission.workspace.manage-user", [false, false, true]]]);++// Returns true if the particular role has the particular permission.+export function hasWorkspacePermission(+ permission: WorkspacePermissionType,+ role: RoleType+): boolean {+ switch (role) {+ case "DEVELOPER":+ return WORKSPACE_FEATURE_MATRIX.get(permission)![0];+ case "DBA":+ return WORKSPACE_FEATURE_MATRIX.get(permission)![1];+ case "OWNER":+ return WORKSPACE_FEATURE_MATRIX.get(permission)![2];+ }+}+// Returns true if admin feature is NOT supported or the principal is OWNERexport function isOwner(role: RoleType): boolean {return !hasFeature("bb.feature.rbac") || role == "OWNER";diff --git a/frontend/src/views/ProfileDashboard.vue b/frontend/src/views/ProfileDashboard.vueindex 756e5b2630..3ae35eb2db 100644--- a/frontend/src/views/ProfileDashboard.vue+++ b/frontend/src/views/ProfileDashboard.vue@@ -178,7 +178,7 @@ import isEmpty from "lodash-es/isEmpty";import isEqual from "lodash-es/isEqual";import PrincipalAvatar from "../components/PrincipalAvatar.vue";import { PrincipalPatch } from "../types";-import { isOwner } from "../utils";+import { hasWorkspacePermission } from "../utils";import { featureToRef, useCurrentUser, usePrincipalStore } from "@/store";interface LocalState {@@ -248,7 +248,10 @@ export default defineComponent({const allowEdit = computed(() => {return (currentUser.value.id == principal.value.id ||- isOwner(currentUser.value.role)+ hasWorkspacePermission(+ "bb.permission.workspace.manage-user",+ currentUser.value.role+ ));});