Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

chore: no protection (#13191)

Danny Xu77f9891e0377
diff --git a/frontend/src/components/Project/CreateProjectBranchProtectionRulePanel.vue b/frontend/src/components/Project/CreateProjectBranchProtectionRulePanel.vue
deleted file mode 100644
index cb4b6ea63c..0000000000
--- a/frontend/src/components/Project/CreateProjectBranchProtectionRulePanel.vue
+++ /dev/null
@@ -1,265 +0,0 @@
-<template>
- <Drawer
- :show="true"
- width="auto"
- @update:show="(show: boolean) => !show && $emit('close')"
- >
- <DrawerContent
- :title="$t('project.settings.branch-protection-rules.self')"
- :closable="true"
- class="w-[50rem] max-w-[100vw] relative"
- >
- <div>
- <p>
- {{
- $t(
- "project.settings.branch-protection-rules.branch-name-pattern.self"
- )
- }}
- </p>
- <p class="text-sm textinfolabel mb-2">
- {{
- $t(
- "project.settings.branch-protection-rules.branch-name-pattern.description"
- )
- }}
- </p>
- <NInput v-model:value="state.protectionRule.nameFilter" />
- </div>
- <div class="mt-2">
- <NCheckbox
- :checked="state.protectionRule.branchSource === BranchSource.DATABASE"
- @update:checked="toggleApplyToMainBranches"
- >
- {{
- $t(
- "project.settings.branch-protection-rules.only-apply-to-main-branches"
- )
- }}
- </NCheckbox>
- </div>
- <div class="mt-2">
- <p class="text-sm">
- {{
- $t(
- "project.settings.branch-protection-rules.applies-to-n-branches",
- { n: matchedBranchList.length }
- )
- }}
- </p>
- <div
- class="w-full flex flex-row justify-start items-center flex-wrap gap-2 mt-2"
- >
- <NTag
- v-for="branch in matchedBranchList"
- :key="branch.name"
- type="success"
- round
- >
- {{ branch.branchId }}
- </NTag>
- </div>
- </div>
- <NDivider class="!my-4" />
- <div class="space-y-2">
- <NCheckbox v-model:checked="state.disallowAllRoles">{{
- $t(
- "project.settings.branch-protection-rules.only-allow-specified-roles-to-create-branch"
- )
- }}</NCheckbox>
- <NSelect
- v-if="state.disallowAllRoles"
- v-model:value="state.selectedRoles"
- multiple
- :options="roleOptions"
- />
- </div>
- <template #footer>
- <div class="w-full flex flex-row justify-between items-center">
- <div>
- <DeleteConfirmButton v-if="!isCreating" @confirm="handleDelete" />
- </div>
- <div class="flex items-center justify-end gap-x-2">
- <NButton @click="$emit('close')">{{ $t("common.cancel") }}</NButton>
- <NButton
- type="primary"
- :disabled="!allowConfirm"
- @click="handleConfirm"
- >
- {{ isCreating ? $t("common.add") : $t("common.update") }}
- </NButton>
- </div>
- </div>
- </template>
- </DrawerContent>
- </Drawer>
-</template>
-
-<script lang="ts" setup>
-import { cloneDeep } from "lodash-es";
-import { NButton, NCheckbox, NInput, NDivider, NSelect, NTag } from "naive-ui";
-import { v4 as uuidv4 } from "uuid";
-import { computed, reactive, watch } from "vue";
-import { Drawer, DrawerContent } from "@/components/v2";
-import {
- useRoleStore,
- useCurrentUserV1,
- useBranchListByProject,
-} from "@/store";
-import {
- getProjectAndBranchId,
- projectNamePrefix,
- protectionRulesSuffix,
-} from "@/store/modules/v1/common";
-import {
- useProjectBranchProtectionRules,
- useProjectProtectionRulesStore,
-} from "@/store/modules/v1/projectProtectionRoles";
-import type { ComposedProject } from "@/types";
-import { PresetRoleType } from "@/types";
-import {
- ProtectionRule,
- ProtectionRule_BranchSource as BranchSource,
- ProtectionRule_Target,
-} from "@/types/proto/v1/project_service";
-import { displayRoleTitle } from "@/utils";
-import { hasProjectPermissionV2 } from "@/utils";
-import { wildcardToRegex } from "../Branch/utils";
-import { DeleteConfirmButton } from "../v2/Button";
-
-const props = defineProps<{
- project: ComposedProject;
- protectionRule?: ProtectionRule;
-}>();
-
-interface LocalState {
- protectionRule: ProtectionRule;
- disallowAllRoles: boolean;
- selectedRoles: string[];
-}
-
-const emit = defineEmits<{
- (event: "close"): void;
-}>();
-
-const { branchList } = useBranchListByProject(
- computed(() => props.project.name)
-);
-const protectionRuleStore = useProjectProtectionRulesStore();
-const branchProtectionRules = useProjectBranchProtectionRules(
- props.project.name
-);
-const state = reactive<LocalState>({
- protectionRule:
- props.protectionRule ||
- ProtectionRule.fromPartial({
- id: uuidv4(),
- target: ProtectionRule_Target.BRANCH,
- }),
- disallowAllRoles:
- !!props.protectionRule && props.protectionRule?.allowedRoles.length !== 0,
- selectedRoles: props.protectionRule?.allowedRoles || [],
-});
-
-const branches = computed(() => {
- return branchList.value.filter((branch) => {
- const [projectName] = getProjectAndBranchId(branch.name);
- return projectNamePrefix + projectName === props.project.name;
- });
-});
-
-const matchedBranchList = computed(() => {
- const branchList =
- state.protectionRule.branchSource === BranchSource.DATABASE
- ? branches.value.filter((br) => !br.parentBranch)
- : branches.value;
- if (state.protectionRule.nameFilter === "") {
- return branchList;
- }
- return branchList.filter((branch) => {
- return wildcardToRegex(state.protectionRule.nameFilter).test(
- branch.branchId
- );
- });
-});
-
-const isCreating = computed(() => {
- return props.protectionRule === undefined;
-});
-
-const allowConfirm = computed(() => {
- return hasProjectPermissionV2(
- props.project,
- useCurrentUserV1().value,
- "bb.projects.update"
- );
-});
-
-const roleList = computed(() => {
- const roleList = useRoleStore().roleList;
- return roleList;
-});
-
-const roleOptions = computed(() => {
- return roleList.value.map((role) => {
- // Only allow to select roles that are not OWNER.
- const disabled = role.name === PresetRoleType.PROJECT_OWNER;
- return {
- label: displayRoleTitle(role.name),
- value: role.name,
- disabled,
- };
- });
-});
-
-watch(
- () => [state.disallowAllRoles],
- () => {
- if (state.disallowAllRoles) {
- if (!state.selectedRoles.includes(PresetRoleType.PROJECT_OWNER)) {
- state.selectedRoles.unshift(PresetRoleType.PROJECT_OWNER);
- }
- }
- }
-);
-
-const toggleApplyToMainBranches = (on: boolean) => {
- state.protectionRule.branchSource = on
- ? BranchSource.DATABASE
- : BranchSource.BRANCH_SOURCE_UNSPECIFIED;
-};
-
-const handleConfirm = async () => {
- if (!allowConfirm.value) {
- return;
- }
-
- const rules = cloneDeep(branchProtectionRules.value);
- const rule = ProtectionRule.fromPartial({
- ...state.protectionRule,
- // If disallowAllRoles is false, `allowedRoles` should be an empty array.
- allowedRoles: state.disallowAllRoles ? state.selectedRoles : [],
- });
- if (isCreating.value) {
- rules.push(rule);
- } else {
- const index = rules.findIndex((item) => item.id === rule.id);
- rules[index] = rule;
- }
-
- await protectionRuleStore.updateProjectProtectionRules({
- name: props.project.name + protectionRulesSuffix,
- rules: rules,
- });
- emit("close");
-};
-
-const handleDelete = async () => {
- const rules = cloneDeep(branchProtectionRules.value);
- await protectionRuleStore.updateProjectProtectionRules({
- name: props.project.name + protectionRulesSuffix,
- rules: rules.filter((rule) => rule.id !== state.protectionRule.id),
- });
- emit("close");
-};
-</script>
diff --git a/frontend/src/components/Project/Settings/ProjectBranchProtectionRulesSettingPanel.vue b/frontend/src/components/Project/Settings/ProjectBranchProtectionRulesSettingPanel.vue
deleted file mode 100644
index 57907a81bf..0000000000
--- a/frontend/src/components/Project/Settings/ProjectBranchProtectionRulesSettingPanel.vue
+++ /dev/null
@@ -1,88 +0,0 @@
-<template>
- <div class="w-full flex flex-col justify-start items-start pt-6">
- <div class="w-full flex flex-row justify-between items-center mb-4">
- <h3 class="text-lg font-medium leading-7 text-main">
- {{ $t("project.settings.branch-protection-rules.self") }}
- </h3>
- <div>
- <NButton :disabled="!allowEdit" @click="handleCreateRule">{{
- $t("project.settings.branch-protection-rules.add-rule")
- }}</NButton>
- </div>
- </div>
- <div
- v-for="rule in branchProtectionRules"
- :key="rule.id"
- class="w-full flex flex-row justify-between items-center px-3 py-2 border border-b-0 last:border-b"
- >
- <NTag type="success" round>
- <template v-if="rule.nameFilter">{{ rule.nameFilter }}</template>
- <span v-else class="text-control-placeholder">
- {{ $t("common.all") }}
- </span>
- </NTag>
- <div class="flex flex-row justify-end items-center">
- <NButton text :disabled="!allowEdit" @click="handleEditRule(rule)">
- <template #icon>
- <PenLine />
- </template>
- </NButton>
- </div>
- </div>
- <div v-if="branchProtectionRules.length === 0" class="w-full">
- <p class="textinfolabel">
- {{
- $t(
- "project.settings.branch-protection-rules.no-protection-rule-configured"
- )
- }}
- </p>
- </div>
- </div>
-
- <CreateProjectBranchProtectionRulePanel
- v-if="createRulePanelContext.show"
- :project="project"
- :allow-edit="allowEdit"
- :protection-rule="createRulePanelContext.rule"
- @close="createRulePanelContext.show = false"
- />
-</template>
-
-<script lang="ts" setup>
-import { PenLine } from "lucide-vue-next";
-import { NButton, NTag } from "naive-ui";
-import { ref } from "vue";
-import { useProjectBranchProtectionRules } from "@/store/modules/v1/projectProtectionRoles";
-import type { ComposedProject } from "@/types";
-import type { ProtectionRule } from "@/types/proto/v1/project_service";
-import CreateProjectBranchProtectionRulePanel from "../CreateProjectBranchProtectionRulePanel.vue";
-
-const props = defineProps<{
- project: ComposedProject;
- allowEdit?: boolean;
-}>();
-
-const branchProtectionRules = useProjectBranchProtectionRules(
- props.project.name
-);
-const createRulePanelContext = ref<{
- show: boolean;
- rule?: ProtectionRule;
-}>({
- show: false,
-});
-
-const handleCreateRule = () => {
- createRulePanelContext.value = {
- show: true,
- };
-};
-
-const handleEditRule = (rule: ProtectionRule) => {
- createRulePanelContext.value = {
- show: true,
- rule: rule,
- };
-};
-</script>
diff --git a/frontend/src/components/Project/Settings/index.ts b/frontend/src/components/Project/Settings/index.ts
index b3c2d479ee..e19dccafae 100644
--- a/frontend/src/components/Project/Settings/index.ts
+++ b/frontend/src/components/Project/Settings/index.ts
@@ -1,10 +1,8 @@
-import ProjectBranchProtectionRulesSettingPanel from "./ProjectBranchProtectionRulesSettingPanel.vue";
import ProjectGeneralSettingPanel from "./ProjectGeneralSettingPanel.vue";
import ProjectIssueRelatedSettingPanel from "./ProjectIssueRelatedSettingPanel.vue";
import ProjectSecuritySettingPanel from "./ProjectSecuritySettingPanel.vue";
export {
- ProjectBranchProtectionRulesSettingPanel,
ProjectGeneralSettingPanel,
ProjectSecuritySettingPanel,
ProjectIssueRelatedSettingPanel,