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: update branch permission (#10345)
ecmadaoec441d8c25dc
diff --git a/frontend/src/components/Branch/BranchCreateView.vue b/frontend/src/components/Branch/BranchCreateView.vueindex bdfaf2beae..c2c7263f94 100644--- a/frontend/src/components/Branch/BranchCreateView.vue+++ b/frontend/src/components/Branch/BranchCreateView.vue@@ -50,7 +50,7 @@<BaselineSchemaSelectorv-if="source === 'BASELINE'"v-model:database-id="databaseId"- :project-id="projectId"+ :project-id="project.uid":loading="isPreparingBranch"/></div>@@ -93,12 +93,13 @@ import { PROJECT_V1_ROUTE_BRANCH_DETAIL } from "@/router/dashboard/projectV1";import {pushNotification,useDatabaseV1Store,- useProjectV1Store,+ useCurrentUserV1,} from "@/store";import { useBranchStore } from "@/store/modules/branch";-import { UNKNOWN_ID } from "@/types";+import { UNKNOWN_ID, ComposedProject } from "@/types";import { Branch } from "@/types/proto/v1/branch_service";import { DatabaseMetadataView } from "@/types/proto/v1/database_service";+import { hasProjectPermissionV2 } from "@/utils";import BaselineSchemaSelector from "./BaselineSchemaSelector.vue";import BranchSelector from "./BranchSelector.vue";import { validateBranchName } from "./utils";@@ -110,21 +111,16 @@ type BranchData = {parent: string | undefined;};-const props = defineProps({- projectId: {- type: String,- default: undefined,- },-});+const props = defineProps<{+ project: ComposedProject;+}>();const DEBOUNCE_RATE = 100;const { t } = useI18n();const router = useRouter();const databaseStore = useDatabaseV1Store();-const projectStore = useProjectV1Store();const branchStore = useBranchStore();const source = ref<Source>("PARENT");-const projectId = ref(props.projectId);const databaseId = ref<string>();const parentBranchName = ref<string>();const isCreating = ref(false);@@ -133,11 +129,6 @@ const isPreparingBranch = ref(false);const EMPTY_BRANCH = Branch.fromPartial({});-const project = computed(() => {- const project = projectStore.getProjectByUID(projectId.value || "");- return project;-});-const debouncedDatabaseId = useDebounce(databaseId, DEBOUNCE_RATE);const debouncedParentBranchName = useDebounce(parentBranchName, DEBOUNCE_RATE);@@ -147,7 +138,7 @@ const filterParentBranch = (branch: Branch) => {};const nextFakeBranchName = () => {- return `${project.value.name}/branches/-${uniqueId()}`;+ return `${props.project.name}/branches/-${uniqueId()}`;};const prepareBranchFromParentBranch = async (parent: string) => {@@ -244,6 +235,15 @@ watch();const allowConfirm = computed(() => {+ if (+ !hasProjectPermissionV2(+ props.project,+ useCurrentUserV1().value,+ "bb.branches.create"+ )+ ) {+ return false;+ }return branchId.value && branchData.value && !isCreating.value;});@@ -271,7 +271,7 @@ const handleConfirm = async () => {isCreating.value = true;if (!parent) {await branchStore.createBranch(- project.value.name,+ props.project.name,branchId.value,Branch.fromPartial({baselineDatabase,@@ -279,7 +279,7 @@ const handleConfirm = async () => {);} else {await branchStore.createBranch(- project.value.name,+ props.project.name,branchId.value,Branch.fromPartial({parentBranch: parent,diff --git a/frontend/src/components/Branch/BranchDetailView.vue b/frontend/src/components/Branch/BranchDetailView.vueindex cf3f5f690f..1d6cb256bb 100644--- a/frontend/src/components/Branch/BranchDetailView.vue+++ b/frontend/src/components/Branch/BranchDetailView.vue@@ -14,12 +14,12 @@<div class="w-full flex flex-row justify-between items-center"><div class="w-full flex flex-row justify-start items-center gap-x-2"><NInput- v-if="!readonly"+ v-if="allowEdit"v-model:value="state.branchId"class="!w-auto":passively-activated="true":style="branchIdInputStyle"- :readonly="readonly || !state.isEditingBranchId"+ :readonly="!allowEdit || !state.isEditingBranchId":placeholder="'feature/add-billing'"@focus="state.isEditingBranchId = true"@blur="handleBranchIdInputBlur"@@ -43,7 +43,7 @@<div><div class="w-full flex flex-row justify-between items-center"><div- v-if="!readonly"+ v-if="allowEdit"class="flex flex-row justify-end items-center space-x-2"><template v-if="!state.isEditing">@@ -99,7 +99,7 @@/></div><!-- Don't show delete button in view mode. -->- <div v-if="!readonly">+ <div v-if="allowDelete"><BBButtonConfirm:style="'DELETE'":button-text="$t('database.delete-this-branch')"@@ -139,13 +139,19 @@ import {PROJECT_V1_ROUTE_BRANCH_ROLLOUT,PROJECT_V1_ROUTE_BRANCH_REBASE,} from "@/router/dashboard/projectV1";-import { pushNotification, useDatabaseV1Store } from "@/store";+import {+ extractUserEmail,+ pushNotification,+ useDatabaseV1Store,+ useCurrentUserV1,+} from "@/store";import { useBranchStore } from "@/store/modules/branch";import { getProjectAndBranchId } from "@/store/modules/v1/common";-import { ComposedProject } from "@/types";+import { ComposedProject, ProjectPermission } from "@/types";import { Branch } from "@/types/proto/v1/branch_service";import { DatabaseMetadata } from "@/types/proto/v1/database_service";import { defer } from "@/utils";+import { hasProjectPermissionV2 } from "@/utils";import { getErrorCode } from "@/utils/grpcweb";import { provideSQLCheckContext } from "../SQLCheck";import { generateDiffDDL } from "../SchemaEditorLite";@@ -167,7 +173,6 @@ const props = defineProps<{project: ComposedProject;cleanBranch: Branch;dirtyBranch: Branch;- readonly?: boolean;}>();const emit = defineEmits<{(event: "update:branch-id", id: string): void;@@ -195,6 +200,23 @@ const selectTargetDatabasesContext = ref<{show: false,});+const currentUser = useCurrentUserV1();++const checkPermission = (permission: ProjectPermission): boolean => {+ return (+ hasProjectPermissionV2(props.project, currentUser.value, permission) ||+ extractUserEmail(props.cleanBranch.creator) === currentUser.value.email+ );+};++const allowEdit = computed(() => {+ return checkPermission("bb.branches.update");+});++const allowDelete = computed(() => {+ return checkPermission("bb.branches.delete");+});+const parentBranch = asyncComputed(async () => {const branch = props.dirtyBranch;// Show parent branch when the current branch is a personal draft and it's not the new created one.diff --git a/frontend/src/components/Project/ProjectSidebarV1.vue b/frontend/src/components/Project/ProjectSidebarV1.vueindex 7a8547ddba..51ffce6520 100644--- a/frontend/src/components/Project/ProjectSidebarV1.vue+++ b/frontend/src/components/Project/ProjectSidebarV1.vue@@ -52,7 +52,7 @@ import projectV1Routes, {} from "@/router/dashboard/projectV1";import { useCurrentUserV1 } from "@/store";import { getProjectName } from "@/store/modules/v1/common";-import { DEFAULT_PROJECT_V1_NAME } from "@/types";+import { DEFAULT_PROJECT_V1_NAME, ProjectPermission } from "@/types";import { TenantMode } from "@/types/proto/v1/project_service";import { hasProjectPermissionV2 } from "@/utils";import { useProjectDatabaseActions } from "../KBar/useDatabaseActions";@@ -97,15 +97,43 @@ const isTenantProject = computed((): boolean => {return project.value.tenantMode === TenantMode.TENANT_MODE_ENABLED;});-const flattenProjectV1Routes = computed(() => {- return projectV1Routes.reduce((list, projectV1Route) => {- if (!projectV1Route.children || projectV1Route.children.length === 0) {- list.push(projectV1Route);- } else {- list.push(...projectV1Route.children);+const getFlattenProjectV1Routes = (+ routes: RouteRecordRaw[],+ permissions: ProjectPermission[] = []+): {+ name: string;+ permissions: ProjectPermission[];+}[] => {+ return routes.reduce((list, projectV1Route) => {+ const requiredProjectPermissionListFunc =+ projectV1Route.meta?.requiredProjectPermissionList;+ let requiredPermissionList = requiredProjectPermissionListFunc+ ? requiredProjectPermissionListFunc()+ : [];+ if (requiredPermissionList.length === 0) {+ requiredPermissionList = permissions;+ }++ if (projectV1Route.name && projectV1Route.name.toString() !== "") {+ list.push({+ name: projectV1Route.name.toString(),+ permissions: requiredPermissionList,+ });+ }+ if (projectV1Route.children) {+ list.push(+ ...getFlattenProjectV1Routes(+ projectV1Route.children,+ requiredPermissionList+ )+ );}return list;- }, [] as RouteRecordRaw[]);+ }, [] as { name: string; permissions: ProjectPermission[] }[]);+};++const flattenProjectV1Routes = computed(() => {+ return getFlattenProjectV1Routes(projectV1Routes);});const filterprojectSidebarByPermissions = (@@ -116,13 +144,7 @@ const filterprojectSidebarByPermissions = (const routeConfig = flattenProjectV1Routes.value.find((projectV1Route) => projectV1Route.name === item.path);- const getPermissionListFunc =- routeConfig?.meta?.requiredProjectPermissionList;- const requiredPermissions = getPermissionListFunc- ? getPermissionListFunc()- : [];-- return requiredPermissions.every((permission) =>+ return (routeConfig?.permissions ?? []).every((permission) =>hasProjectPermissionV2(project.value, currentUser.value, permission));})diff --git a/frontend/src/components/ProjectBranchesPanel.vue b/frontend/src/components/ProjectBranchesPanel.vueindex 89a2d726e3..dda80770bb 100644--- a/frontend/src/components/ProjectBranchesPanel.vue+++ b/frontend/src/components/ProjectBranchesPanel.vue@@ -6,7 +6,7 @@:autofocus="true":placeholder="$t('common.filter-by-name')"/>- <NButton type="primary" @click="handleCreateBranch">+ <NButton v-if="allowCreate" type="primary" @click="handleCreateBranch"><PlusIcon class="w-4 h-auto mr-0.5" /><span>{{ $t("database.new-branch") }}</span></NButton>@@ -46,6 +46,7 @@ import { useCurrentUserV1 } from "@/store";import { useBranchListByProject } from "@/store/modules/branch";import { userNamePrefix } from "@/store/modules/v1/common";import { ComposedProject } from "@/types";+import { hasProjectPermissionV2 } from "@/utils";const props = defineProps<{project: ComposedProject;@@ -67,6 +68,13 @@ const { branchList, ready } = useBranchListByProject(const state = reactive<LocalState>({searchKeyword: "",});+const allowCreate = computed(() => {+ return hasProjectPermissionV2(+ props.project,+ currentUser.value,+ "bb.branches.create"+ );+});const filteredBranches = computed(() => {return orderBy(branchList.value, "updateTime", "desc").filter((branch) => {diff --git a/frontend/src/router/dashboard/projectV1.ts b/frontend/src/router/dashboard/projectV1.tsindex 40f1f3536a..b3c3b277eb 100644--- a/frontend/src/router/dashboard/projectV1.ts+++ b/frontend/src/router/dashboard/projectV1.ts@@ -156,7 +156,8 @@ const projectV1Routes: RouteRecordRaw[] = [overrideTitle: true,requiredProjectPermissionList: () => ["bb.projects.get",- "bb.branches.update",+ "bb.branches.get",+ "bb.issues.create",],},component: () => import("@/views/branch/BranchRollout.vue"),@@ -169,6 +170,7 @@ const projectV1Routes: RouteRecordRaw[] = [title: () => t("branch.merge-rebase.merge-branch"),requiredProjectPermissionList: () => ["bb.projects.get",+ "bb.branches.get","bb.branches.update",],},@@ -182,6 +184,7 @@ const projectV1Routes: RouteRecordRaw[] = [title: () => t("branch.merge-rebase.rebase-branch"),requiredProjectPermissionList: () => ["bb.projects.get",+ "bb.branches.get","bb.branches.update",],},diff --git a/frontend/src/views/branch/BranchDetail.vue b/frontend/src/views/branch/BranchDetail.vueindex 29751a66ed..4ff4c31887 100644--- a/frontend/src/views/branch/BranchDetail.vue+++ b/frontend/src/views/branch/BranchDetail.vue@@ -1,16 +1,14 @@<template><template v-if="ready"><template v-if="isCreating">- <BranchCreateView :project-id="project?.uid" v-bind="$attrs" />+ <BranchCreateView :project="project" v-bind="$attrs" /></template><template v-else-if="branch"><BranchDetailView- v-if="project":key="detailViewKey":project="project":clean-branch="branch.clean":dirty-branch="branch.dirty"- :readonly="!allowEdit"v-bind="$attrs"@update:branch-id="handleUpdateBranchId"/>@@ -30,11 +28,10 @@ import { useRouter } from "vue-router";import BranchCreateView from "@/components/Branch/BranchCreateView.vue";import BranchDetailView from "@/components/Branch/BranchDetailView.vue";import { PROJECT_V1_ROUTE_BRANCH_DETAIL } from "@/router/dashboard/projectV1";-import { extractUserEmail, useCurrentUserV1, useProjectV1Store } from "@/store";+import { useProjectV1Store } from "@/store";import { useBranchStore } from "@/store/modules/branch";import { projectNamePrefix } from "@/store/modules/v1/common";import { Branch } from "@/types/proto/v1/branch_service";-import { isOwnerOfProjectV1 } from "@/utils";const props = defineProps<{projectId: string;@@ -43,7 +40,6 @@ const props = defineProps<{const { t } = useI18n();const router = useRouter();-const me = useCurrentUserV1();const projectStore = useProjectV1Store();const branchStore = useBranchStore();const branchFullName = ref<string>("");@@ -53,21 +49,10 @@ const detailViewKey = ref(uniqueId());const isCreating = computed(() => props.branchName === "new");const branch = ref<{ clean: Branch; dirty: Branch }>();const project = computed(() => {- if (props.projectId === "-") {- return;- }return projectStore.getProjectByName(`${projectNamePrefix}${props.projectId}`);});-const allowEdit = computed(() => {- if (!project.value) return false;- if (!branch.value) return false;- if (isOwnerOfProjectV1(project.value.iamPolicy, me.value)) {- return true;- }- return extractUserEmail(branch.value.clean.creator) === me.value.email;-});const handleUpdateBranchId = (id: string) => {if (!branch.value) return;