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(branching): permission control (#12099)
Liu Jia5ebaacb7068
diff --git a/frontend/src/components/Branch/BranchCreateView.vue b/frontend/src/components/Branch/BranchCreateView.vueindex d386ce559b..b45c7ea04c 100644--- a/frontend/src/components/Branch/BranchCreateView.vue+++ b/frontend/src/components/Branch/BranchCreateView.vue@@ -29,9 +29,21 @@<NRadio value="PARENT">{{ $t("branch.source.parent-branch") }}</NRadio>- <NRadio value="BASELINE">- {{ $t("branch.source.baseline-version") }}- </NRadio>+ <NTooltip :disabled="allowCreateBranchFromDatabase">+ <template #trigger>+ <NRadio+ :disabled="!allowCreateBranchFromDatabase"+ value="BASELINE"+ >+ {{ $t("branch.source.baseline-version") }}+ </NRadio>+ </template>+ <template #default>+ <div class="whitespace-nowrap">+ {{ $t("common.permission-denied") }}+ </div>+ </template>+ </NTooltip></NRadioGroup></div><div v-if="source === 'PARENT'" class="contents">@@ -100,7 +112,7 @@ import type { ComposedProject } from "@/types";import { UNKNOWN_ID } from "@/types";import { Branch } from "@/types/proto/v1/branch_service";import { DatabaseMetadataView } from "@/types/proto/v1/database_service";-import { hasProjectPermissionV2 } from "@/utils";+import { hasProjectPermissionV2, isOwnerOfProjectV1 } from "@/utils";import BaselineSchemaSelector from "./BaselineSchemaSelector.vue";import BranchSelector from "./BranchSelector.vue";import { validateBranchName } from "./utils";@@ -121,6 +133,7 @@ const { t } = useI18n();const router = useRouter();const databaseStore = useDatabaseV1Store();const branchStore = useBranchStore();+const me = useCurrentUserV1();const source = ref<Source>("PARENT");const databaseId = ref<string>();const parentBranchName = ref<string>();@@ -130,6 +143,10 @@ const isPreparingBranch = ref(false);const EMPTY_BRANCH = Branch.fromPartial({});+const allowCreateBranchFromDatabase = computed(() => {+ return isOwnerOfProjectV1(props.project.iamPolicy, me.value);+});+const debouncedDatabaseId = useDebounce(databaseId, DEBOUNCE_RATE);const debouncedParentBranchName = useDebounce(parentBranchName, DEBOUNCE_RATE);diff --git a/frontend/src/components/Branch/BranchDetailView.vue b/frontend/src/components/Branch/BranchDetailView.vueindex 5015350606..5556894c26 100644--- a/frontend/src/components/Branch/BranchDetailView.vue+++ b/frontend/src/components/Branch/BranchDetailView.vue@@ -54,7 +54,10 @@>{{ $t("branch.merge-rebase.merge-branch") }}</NButton>- <NButton @click="handleGotoRebaseBranch">+ <NButton+ v-if="showRebaseBranchButton"+ @click="handleGotoRebaseBranch"+ >{{ $t("branch.merge-rebase.rebase-branch") }}</NButton><NButton@@ -172,6 +175,7 @@ import {defer,extractProjectResourceName,hasProjectPermissionV2,+ isOwnerOfProjectV1,} from "@/utils";import { getErrorCode } from "@/utils/grpcweb";import { provideSQLCheckContext } from "../SQLCheck";@@ -259,12 +263,29 @@ const database = computedAsync(() => {const showMergeBranchButton = computed(() => {// main branches (parent-less branches) cannot be merged.- return !!parentBranch.value;+ if (!parentBranch.value) {+ return false;+ }+ // The branch's creator and project owners can merge feature branches into main branches.+ return allowEdit.value;+});++const showRebaseBranchButton = computed(() => {+ // For main branches: only project owners are allowed+ if (!parentBranch.value) {+ return isOwnerOfProjectV1(props.project.iamPolicy, currentUser.value);+ }++ // For feature branches: project owners and branch creator+ return allowEdit.value;});// Only show apply to database button when the branch is main branch.const showApplyBranchButton = computed(() => {- return !parentBranch.value;+ return (+ !parentBranch.value &&+ isOwnerOfProjectV1(props.project.iamPolicy, currentUser.value)+ );});const rebuildMetadataEdit = () => {diff --git a/frontend/src/components/Branch/BranchMergeView/BranchMergeView.vue b/frontend/src/components/Branch/BranchMergeView/BranchMergeView.vueindex f3d31a8247..4b17648ebd 100644--- a/frontend/src/components/Branch/BranchMergeView/BranchMergeView.vue+++ b/frontend/src/components/Branch/BranchMergeView/BranchMergeView.vue@@ -6,6 +6,7 @@:project="project":head-branch="headBranch":target-branch="targetBranch"+ :parent-branch-only="parentBranchOnly"@update:head-branch-name="handleUpdateHeadBranch"@update:target-branch-name="state.targetBranchName = $event || null"/>@@ -62,9 +63,10 @@ import { computed, reactive, ref, watch } from "vue";import { useI18n } from "vue-i18n";import MaskSpinner from "@/components/misc/MaskSpinner.vue";import { branchServiceClient } from "@/grpcweb";-import { pushNotification, useBranchStore } from "@/store";+import { pushNotification, useBranchStore, useCurrentUserV1 } from "@/store";import type { ComposedProject } from "@/types";import { Branch } from "@/types/proto/v1/branch_service";+import { isOwnerOfProjectV1 } from "@/utils";import { extractGrpcErrorMessage, getErrorCode } from "@/utils/grpcweb";import BranchComparison from "../common/BranchComparison.vue";import MergeBranchButton from "./MergeBranchButton.vue";@@ -98,6 +100,7 @@ const state = reactive<LocalState>({});const { t } = useI18n();const branchStore = useBranchStore();+const me = useCurrentUserV1();const isLoadingHeadBranch = ref(false);const isLoadingTargetBranch = ref(false);const isValidating = ref(false);@@ -134,6 +137,20 @@ const targetBranch = computedAsync(});+const parentBranchOnly = computed(() => {+ const head = headBranch.value;+ if (!head) {+ return false; // not ready yet+ }+ if (!head.parentBranch) {+ return false; // parent-less (main) branches+ }+ if (isOwnerOfProjectV1(props.project.iamPolicy, me.value)) {+ return false; // project owners are not limited+ }+ return true;+});+const validationState = computedAsync(async (): Promise<MergeBranchValidationState | undefined> => {const head = headBranch.value;diff --git a/frontend/src/components/Branch/BranchMergeView/MergeBranchSelect.vue b/frontend/src/components/Branch/BranchMergeView/MergeBranchSelect.vueindex 4a2f4d75be..9f0a46c991 100644--- a/frontend/src/components/Branch/BranchMergeView/MergeBranchSelect.vue+++ b/frontend/src/components/Branch/BranchMergeView/MergeBranchSelect.vue@@ -1,16 +1,22 @@<template><div- class="w-full grid grid-cols-4 items-center text-sm gap-x-2"+ class="w-full grid grid-cols-3 items-end text-sm gap-x-2"style="grid-template-columns: 1fr auto 1fr auto">- <BranchSelector- class="!w-full text-center"- :clearable="false"- :project="project"- :branch="targetBranch?.name"- :filter="targetBranchFilter"- @update:branch="$emit('update:target-branch-name', $event)"- />+ <div class="flex flex-col">+ <div v-if="parentBranchOnly">+ {{ $t("schema-designer.parent-branch") }}+ </div>+ <BranchSelector+ class="!w-full text-center"+ :disabled="parentBranchOnly"+ :clearable="false"+ :project="project"+ :branch="targetBranch?.name"+ :filter="targetBranchFilter"+ @update:branch="$emit('update:target-branch-name', $event)"+ />+ </div><div class="flex flex-row justify-center px-2"><MoveLeftIcon :size="40" stroke-width="1" /></div>@@ -34,6 +40,7 @@ const props = defineProps<{project: ComposedProject;targetBranch: Branch | undefined;headBranch: Branch | undefined;+ parentBranchOnly: boolean | undefined;}>();defineEmits<{diff --git a/frontend/src/components/Branch/BranchRebaseView/BranchRebaseView.vue b/frontend/src/components/Branch/BranchRebaseView/BranchRebaseView.vueindex d9aaa7ba03..57852a29c9 100644--- a/frontend/src/components/Branch/BranchRebaseView/BranchRebaseView.vue+++ b/frontend/src/components/Branch/BranchRebaseView/BranchRebaseView.vue@@ -8,6 +8,7 @@:head-branch="headBranch":source-branch="sourceBranch":source-database="sourceDatabase"+ :parent-branch-only="parentBranchOnly"@update:source-type="state.sourceType = $event"@update:head-branch-name="handleUpdateHeadBranch"@update:source-branch-name="state.sourceBranchName = $event || null"@@ -73,11 +74,16 @@ import { useI18n } from "vue-i18n";import { useRoute } from "vue-router";import MaskSpinner from "@/components/misc/MaskSpinner.vue";import { branchServiceClient } from "@/grpcweb";-import { pushNotification, useBranchStore, useDatabaseV1Store } from "@/store";+import {+ pushNotification,+ useBranchStore,+ useCurrentUserV1,+ useDatabaseV1Store,+} from "@/store";import type { ComposedProject } from "@/types";import { UNKNOWN_ID } from "@/types";import type { Branch } from "@/types/proto/v1/branch_service";-import { defer } from "@/utils";+import { defer, isOwnerOfProjectV1 } from "@/utils";import RebaseBranchSelect from "./RebaseBranchSelect.vue";import RebaseBranchValidationStateView from "./RebaseBranchValidationStateView.vue";import ResolveConflict from "./ResolveConflict.vue";@@ -113,6 +119,7 @@ const route = useRoute();const $dialog = useDialog();const resolveConflictRef = ref<InstanceType<typeof ResolveConflict>>();const branchStore = useBranchStore();+const me = useCurrentUserV1();const isLoadingHeadBranch = ref(false);const isLoadingSourceBranch = ref(false);const isValidating = ref(false);@@ -168,6 +175,20 @@ const sourceBranchOrDatabase = computed(() => {return sourceDatabase.value;});+const parentBranchOnly = computed(() => {+ const head = headBranch.value;+ if (!head) {+ return false; // not ready yet+ }+ if (!head.parentBranch) {+ return false; // parent-less (main) branches+ }+ if (isOwnerOfProjectV1(props.project.iamPolicy, me.value)) {+ return false; // project owners are not limited+ }+ return true;+});+const validationState = computedAsync(async (): Promise<RebaseBranchValidationState | undefined> => {const head = headBranch.value;diff --git a/frontend/src/components/Branch/BranchRebaseView/RebaseBranchSelect.vue b/frontend/src/components/Branch/BranchRebaseView/RebaseBranchSelect.vueindex f7d6645e68..0f868f39a4 100644--- a/frontend/src/components/Branch/BranchRebaseView/RebaseBranchSelect.vue+++ b/frontend/src/components/Branch/BranchRebaseView/RebaseBranchSelect.vue@@ -16,6 +16,7 @@</div><div class="flex flex-col"><NRadioGroup+ v-if="!parentBranchOnly":value="sourceType"class="space-x-2"@update:value="$emit('update:source-type', $event as RebaseSourceType)"@@ -23,9 +24,14 @@<NRadio value="BRANCH">{{ $t("common.branch") }}</NRadio><NRadio value="DATABASE">{{ $t("common.database") }}</NRadio></NRadioGroup>+ <div v-if="parentBranchOnly">+ {{ $t("schema-designer.parent-branch") }}+ </div>+<BranchSelectorv-if="sourceType === 'BRANCH'"class="!w-full text-center"+ :disabled="parentBranchOnly":clearable="false":project="project":branch="sourceBranch?.name"@@ -62,6 +68,7 @@ const props = defineProps<{headBranch: Branch | undefined;sourceBranch: Branch | undefined;sourceDatabase: ComposedDatabase | undefined;+ parentBranchOnly: boolean | undefined;isLoadingSourceBranch?: boolean;isLoadingHeadBranch?: boolean;}>();diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.jsonindex cceef6ca11..be12304952 100644--- a/frontend/src/locales/en-US.json+++ b/frontend/src/locales/en-US.json@@ -273,7 +273,8 @@"project-member": "Project member","leave-without-saving": "Leave without saving?","configure-now": "Configure now",- "connection": "Connection"+ "connection": "Connection",+ "permission-denied": "Permission denied"},"error-page": {"go-back-home": "Go back home"diff --git a/frontend/src/locales/es-ES.json b/frontend/src/locales/es-ES.jsonindex f68da8a7e5..895a054450 100644--- a/frontend/src/locales/es-ES.json+++ b/frontend/src/locales/es-ES.json@@ -273,7 +273,8 @@"project-member": "Miembro del proyecto","leave-without-saving": "¿Salir sin ahorrar?","configure-now": "Configurar ahora",- "connection": "Conexión"+ "connection": "Conexión",+ "permission-denied": "Permiso denegado"},"error-page": {"go-back-home": "Volver al inicio"@@ -3527,4 +3528,4 @@"self": "Última actualización"}}-}\ No newline at end of file+}diff --git a/frontend/src/locales/ja-JP.json b/frontend/src/locales/ja-JP.jsonindex b993ad845b..7e8276ceca 100644--- a/frontend/src/locales/ja-JP.json+++ b/frontend/src/locales/ja-JP.json@@ -273,7 +273,8 @@"project-member": "プロジェクトメンバー","leave-without-saving": "変更を保存していませんか?","configure-now": "今すぐ設定する",- "connection": "接続する"+ "connection": "接続する",+ "permission-denied": "許可が拒否されました"},"error-page": {"go-back-home": "ホームページに戻る"@@ -3527,4 +3528,4 @@"self": "最後の更新"}}-}\ No newline at end of file+}diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.jsonindex 89868be104..d19fe4343e 100644--- a/frontend/src/locales/zh-CN.json+++ b/frontend/src/locales/zh-CN.json@@ -273,7 +273,8 @@"project-member": "项目成员","leave-without-saving": "不保存变动?","configure-now": "现在配置",- "connection": "连接"+ "connection": "连接",+ "permission-denied": "您没有权限执行此操作"},"error-page": {"go-back-home": "回到主页"@@ -3527,4 +3528,4 @@"self": "最后更新"}}-}\ No newline at end of file+}diff --git a/frontend/src/router/dashboard/projectV1.ts b/frontend/src/router/dashboard/projectV1.tsindex 4fc83d26b2..87b0fec965 100644--- a/frontend/src/router/dashboard/projectV1.ts+++ b/frontend/src/router/dashboard/projectV1.ts@@ -163,7 +163,6 @@ const projectV1Routes: RouteRecordRaw[] = [requiredProjectPermissionList: () => ["bb.projects.get","bb.branches.get",- "bb.branches.update",],},component: () => import("@/views/branch/BranchMerge.vue"),@@ -177,7 +176,6 @@ const projectV1Routes: RouteRecordRaw[] = [requiredProjectPermissionList: () => ["bb.projects.get","bb.branches.get",- "bb.branches.update",],},component: () => import("@/views/branch/BranchRebase.vue"),