Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
chore: only show quick actions for database related page (#9019)
ecmadao2b8dcf47e070
diff --git a/frontend/src/components/Project/ProjectSidebar.vue b/frontend/src/components/Project/ProjectSidebar.vueindex eeae30ff4d..fd4580793e 100644--- a/frontend/src/components/Project/ProjectSidebar.vue+++ b/frontend/src/components/Project/ProjectSidebar.vue@@ -59,7 +59,7 @@ interface ProjectSidebarItem {}[];}-const defaultHash: ProjectHash = "databases";+const defaultHash: ProjectHash = "issues";interface LocalState {selectedHash: ProjectHash;diff --git a/frontend/src/layouts/BodyLayout.vue b/frontend/src/layouts/BodyLayout.vueindex 759f21d2d2..880c5104d6 100644--- a/frontend/src/layouts/BodyLayout.vue+++ b/frontend/src/layouts/BodyLayout.vue@@ -270,14 +270,14 @@ import {useCurrentUserV1,useSubscriptionV1Store,} from "@/store";+import { QuickActionType, RoleType } from "@/types";import { PlanType } from "@/types/proto/v1/subscription_service";import { hasWorkspacePermissionV1 } from "@/utils";+import { getQuickActionList } from "@/utils";import DashboardHeader from "@/views/DashboardHeader.vue";import Breadcrumb from "../components/Breadcrumb.vue";import QuickActionPanel from "../components/QuickActionPanel.vue";import Quickstart from "../components/Quickstart.vue";-import { QuickActionType } from "../types";-import { isDBA, isDeveloper, isOwner } from "../utils";interface LocalState {showMobileOverlay: boolean;@@ -311,49 +311,14 @@ const canUpgrade = computed(() => {return actuatorStore.hasNewRelease;});-const currentUserV1 = useCurrentUserV1();-const quickActionList = computed(() => {- const role = currentUserV1.value.userRole;const quickActionListFunc =router.currentRoute.value.meta.quickActionListByRole;const listByRole = quickActionListFunc? quickActionListFunc(router.currentRoute.value)- : new Map();- const list: QuickActionType[] = [];-- // We write this way because for free version, the user wears the three role hat,- // and we want to display all quick actions relevant to those three roles without duplication.- if (isOwner(role)) {- for (const item of listByRole.get("OWNER") || []) {- list.push(item);- }- }-- if (isDBA(role)) {- for (const item of listByRole.get("DBA") || []) {- if (- !list.find((myItem: QuickActionType) => {- return item == myItem;- })- ) {- list.push(item);- }- }- }+ : new Map<RoleType, QuickActionType[]>();- if (isDeveloper(role)) {- for (const item of listByRole.get("DEVELOPER") || []) {- if (- !list.find((myItem: QuickActionType) => {- return item == myItem;- })- ) {- list.push(item);- }- }- }- return list;+ return getQuickActionList(listByRole);});const showBreadcrumb = computed(() => {diff --git a/frontend/src/router/index.ts b/frontend/src/router/index.tsindex a8b6b97c18..f34863ea7e 100644--- a/frontend/src/router/index.ts+++ b/frontend/src/router/index.ts@@ -44,18 +44,14 @@ import {} from "@/store";import {DEFAULT_PROJECT_ID,- DEFAULT_PROJECT_V1_NAME,QuickActionType,unknownUser,UNKNOWN_ID,} from "@/types";-import { State } from "@/types/proto/v1/common";import {- hasPermissionInProjectV1,hasWorkspacePermissionV1,idFromSlug,sheetNameFromSlug,- isOwnerOfProjectV1,uidFromSlug,} from "@/utils";import DashboardSidebar from "@/views/DashboardSidebar.vue";@@ -707,77 +703,6 @@ const routes: Array<RouteRecordRaw> = [content: () => import("../layouts/ProjectLayout.vue"),leftSidebar: ProjectSidebar,},- meta: {- quickActionListByRole: (route) => {- const slug = route.params.projectSlug as string;- const project = useProjectV1Store().getProjectByUID(- String(idFromSlug(slug))- );-- if (project.state === State.ACTIVE) {- const DBA_AND_OWNER_QUICK_ACTION_LIST: QuickActionType[] = [- "quickaction.bb.database.schema.update",- "quickaction.bb.database.data.update",- "quickaction.bb.database.create",- "quickaction.bb.project.database.transfer",- "quickaction.bb.project.database.transfer-out",- ];- const DEVELOPER_QUICK_ACTION_LIST: QuickActionType[] = [];-- const currentUserV1 = useCurrentUserV1();- if (- project.name !== DEFAULT_PROJECT_V1_NAME &&- hasPermissionInProjectV1(- project.iamPolicy,- currentUserV1.value,- "bb.permission.project.change-database"- )- ) {- // Default project (Unassigned databases) are not allowed- // to be changed.- DEVELOPER_QUICK_ACTION_LIST.push(- "quickaction.bb.database.schema.update",- "quickaction.bb.database.data.update",- "quickaction.bb.database.create"- );- }- if (- hasPermissionInProjectV1(- project.iamPolicy,- currentUserV1.value,- "bb.permission.project.transfer-database"- )- ) {- DEVELOPER_QUICK_ACTION_LIST.push(- "quickaction.bb.project.database.transfer",- "quickaction.bb.project.database.transfer-out"- );- }- if (- !isOwnerOfProjectV1(project.iamPolicy, currentUserV1.value)- ) {- DEVELOPER_QUICK_ACTION_LIST.push(- "quickaction.bb.issue.grant.request.querier",- "quickaction.bb.issue.grant.request.exporter"- );- }-- if (hasFeature("bb.feature.dba-workflow")) {- pull(- DEVELOPER_QUICK_ACTION_LIST,- "quickaction.bb.database.create"- );- }-- return new Map([- ["OWNER", DBA_AND_OWNER_QUICK_ACTION_LIST],- ["DBA", DBA_AND_OWNER_QUICK_ACTION_LIST],- ["DEVELOPER", DEVELOPER_QUICK_ACTION_LIST],- ]);- }- return new Map();- },- },props: { content: true },children: [{diff --git a/frontend/src/utils/index.ts b/frontend/src/utils/index.tsindex 1d58d001fa..187bbe6d12 100644--- a/frontend/src/utils/index.ts+++ b/frontend/src/utils/index.ts@@ -17,7 +17,6 @@ export * from "./label";export * from "./string";export * from "./tab";export * from "./task";-export * from "./sheet";export * from "./pev2";export * from "./web-storage";export * from "./dom";@@ -30,5 +29,6 @@ export * from "./workspaceApprovalSetting";export * from "./projectIamPolicy";export * from "./slowQuery";export * from "./resource-composer";+export * from "./quickAction";export * from "./v1";diff --git a/frontend/src/utils/quickAction.ts b/frontend/src/utils/quickAction.tsnew file mode 100644index 0000000000..a312a6a7b0--- /dev/null+++ b/frontend/src/utils/quickAction.ts@@ -0,0 +1,45 @@+import { useCurrentUserV1 } from "@/store";+import { QuickActionType, RoleType } from "@/types";+import { isDBA, isDeveloper, isOwner } from "@/utils";++export const getQuickActionList = (+ map: Map<RoleType, QuickActionType[]>+): QuickActionType[] => {+ const currentUserV1 = useCurrentUserV1();+ const role = currentUserV1.value.userRole;++ const list: QuickActionType[] = [];++ // We write this way because for free version, the user wears the three role hat,+ // and we want to display all quick actions relevant to those three roles without duplication.+ if (isOwner(role)) {+ for (const item of map.get("OWNER") || []) {+ list.push(item);+ }+ }++ if (isDBA(role)) {+ for (const item of map.get("DBA") || []) {+ if (+ !list.find((myItem: QuickActionType) => {+ return item == myItem;+ })+ ) {+ list.push(item);+ }+ }+ }++ if (isDeveloper(role)) {+ for (const item of map.get("DEVELOPER") || []) {+ if (+ !list.find((myItem: QuickActionType) => {+ return item == myItem;+ })+ ) {+ list.push(item);+ }+ }+ }+ return list;+};diff --git a/frontend/src/views/ProjectDetail.vue b/frontend/src/views/ProjectDetail.vueindex f0f7a9bff4..2e5972ab3f 100644--- a/frontend/src/views/ProjectDetail.vue+++ b/frontend/src/views/ProjectDetail.vue@@ -1,4 +1,7 @@<template>+ <div v-if="quickActionList.length > 0" class="flex-1 pb-2">+ <QuickActionPanel :quick-action-list="quickActionList" />+ </div><template v-if="hash === 'issues'"><ProjectIssuesPanel id="issues" :project="project" /></template>@@ -63,6 +66,7 @@</template><script lang="ts" setup>+import { pull } from "lodash-es";import { computed } from "vue";import { useRoute } from "vue-router";import AnomalyCenterDashboard from "@/components/AnomalyCenter/AnomalyCenterDashboard.vue";@@ -84,9 +88,18 @@ import {useSearchDatabaseV1List,useDatabaseV1Store,useProjectV1Store,+ useCurrentUserV1,+ hasFeature,} from "@/store";-import { DEFAULT_PROJECT_V1_NAME } from "@/types";-import { idFromSlug, sortDatabaseV1List } from "@/utils";+import { QuickActionType, DEFAULT_PROJECT_V1_NAME, RoleType } from "@/types";+import { State } from "@/types/proto/v1/common";+import {+ idFromSlug,+ sortDatabaseV1List,+ isOwnerOfProjectV1,+ hasPermissionInProjectV1,+ getQuickActionList,+} from "@/utils";const props = defineProps({projectWebhookSlug: {@@ -127,4 +140,82 @@ const databaseV1List = computed(() => {const list = useDatabaseV1Store().databaseListByProject(project.value.name);return sortDatabaseV1List(list);});++const quickActionMapByRole = computed(() => {+ if (project.value.state === State.ACTIVE) {+ const DBA_AND_OWNER_QUICK_ACTION_LIST: QuickActionType[] = [+ "quickaction.bb.database.schema.update",+ "quickaction.bb.database.data.update",+ "quickaction.bb.database.create",+ "quickaction.bb.project.database.transfer",+ "quickaction.bb.project.database.transfer-out",+ ];+ const DEVELOPER_QUICK_ACTION_LIST: QuickActionType[] = [];++ const currentUserV1 = useCurrentUserV1();+ if (+ project.value.name !== DEFAULT_PROJECT_V1_NAME &&+ hasPermissionInProjectV1(+ project.value.iamPolicy,+ currentUserV1.value,+ "bb.permission.project.change-database"+ )+ ) {+ // Default project (Unassigned databases) are not allowed+ // to be changed.+ DEVELOPER_QUICK_ACTION_LIST.push(+ "quickaction.bb.database.schema.update",+ "quickaction.bb.database.data.update",+ "quickaction.bb.database.create"+ );+ }+ if (+ hasPermissionInProjectV1(+ project.value.iamPolicy,+ currentUserV1.value,+ "bb.permission.project.transfer-database"+ )+ ) {+ DEVELOPER_QUICK_ACTION_LIST.push(+ "quickaction.bb.project.database.transfer",+ "quickaction.bb.project.database.transfer-out"+ );+ }+ if (!isOwnerOfProjectV1(project.value.iamPolicy, currentUserV1.value)) {+ DEVELOPER_QUICK_ACTION_LIST.push(+ "quickaction.bb.issue.grant.request.querier",+ "quickaction.bb.issue.grant.request.exporter"+ );+ }++ if (hasFeature("bb.feature.dba-workflow")) {+ pull(DEVELOPER_QUICK_ACTION_LIST, "quickaction.bb.database.create");+ }++ return new Map([+ ["OWNER", DBA_AND_OWNER_QUICK_ACTION_LIST],+ ["DBA", DBA_AND_OWNER_QUICK_ACTION_LIST],+ ["DEVELOPER", DEVELOPER_QUICK_ACTION_LIST],+ ]) as Map<RoleType, QuickActionType[]>;+ }++ return new Map<RoleType, QuickActionType[]>();+});++const isDatabaseHash = computed(() => {+ return (+ hash.value === "databases" ||+ hash.value === "database-groups" ||+ hash.value === "change-history" ||+ hash.value === "slow-query" ||+ hash.value === "anomalies"+ );+});++const quickActionList = computed(() => {+ if (!isDatabaseHash.value) {+ return [];+ }+ return getQuickActionList(quickActionMapByRole.value);+});</script>