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: support RESTRICT_ISSUE_CREATION_FOR_SQL_REVIEW policy in project level (#12457)
ecmadaoca078b431fcf
diff --git a/backend/legacyapi/policy.go b/backend/legacyapi/policy.goindex 16d5f95315..6cceb9149d 100644--- a/backend/legacyapi/policy.go+++ b/backend/legacyapi/policy.go@@ -92,7 +92,7 @@ var (PolicyTypeDisableCopyData: {PolicyResourceTypeEnvironment},PolicyTypeMaskingRule: {PolicyResourceTypeWorkspace},PolicyTypeMaskingException: {PolicyResourceTypeProject},- PolicyTypeRestrictIssueCreationForSQLReview: {PolicyResourceTypeWorkspace},+ PolicyTypeRestrictIssueCreationForSQLReview: {PolicyResourceTypeWorkspace, PolicyResourceTypeProject},})diff --git a/frontend/src/components/GeneralSetting/SecuritySetting.vue b/frontend/src/components/GeneralSetting/SecuritySetting.vueindex b75128564d..9deeb3c7e6 100644--- a/frontend/src/components/GeneralSetting/SecuritySetting.vue+++ b/frontend/src/components/GeneralSetting/SecuritySetting.vue@@ -11,6 +11,7 @@{{ $t("settings.general.workspace.only-admin-can-edit") }}</span></div>+<div class="flex-1 lg:px-4"><div class="mb-7 mt-4 lg:mt-0"><NTooltip placement="top-start" :disabled="allowEdit">@@ -164,9 +165,6 @@ const { isSaaSMode } = storeToRefs(actuatorStore);const hasWatermarkFeature = featureToRef("bb.feature.branding");const has2FAFeature = featureToRef("bb.feature.2fa");const hasDisallowSignupFeature = featureToRef("bb.feature.disallow-signup");-const hasRestrictIssueCreationFeature = featureToRef(- "bb.feature.access-control"-);const watermarkEnabled = computed((): boolean => {return (@@ -182,9 +180,10 @@ const require2FAEnabled = computed((): boolean => {});const restrictIssueCreationForSQLReview = computed((): boolean => {return (- policyV1Store.getPolicyByName(- "policies/RESTRICT_ISSUE_CREATION_FOR_SQL_REVIEW"- )?.restrictIssueCreationForSqlReviewPolicy?.disallow ?? false+ policyV1Store.getPolicyByParentAndType({+ parentPath: "",+ policyType: PolicyType.RESTRICT_ISSUE_CREATION_FOR_SQL_REVIEW,+ })?.restrictIssueCreationForSqlReviewPolicy?.disallow ?? false);});@@ -193,9 +192,10 @@ onMounted(async () => {});const prepareOrgPolicy = async () => {- await policyV1Store.getOrFetchPolicyByName(- "policies/RESTRICT_ISSUE_CREATION_FOR_SQL_REVIEW"- );+ await policyV1Store.getOrFetchPolicyByParentAndType({+ parentPath: "",+ policyType: PolicyType.RESTRICT_ISSUE_CREATION_FOR_SQL_REVIEW,+ });};const handleDisallowSignupToggle = async (on: boolean) => {@@ -255,10 +255,6 @@ const handleWatermarkToggle = async (on: boolean) => {};const handleRestrictIssueCreationForSQLReviewToggle = async (on: boolean) => {- if (!hasRestrictIssueCreationFeature.value && on) {- state.featureNameForModal = "bb.feature.access-control";- return;- }await policyV1Store.createPolicy("", {type: PolicyType.RESTRICT_ISSUE_CREATION_FOR_SQL_REVIEW,resourceType: PolicyResourceType.WORKSPACE,diff --git a/frontend/src/components/Project/ProjectGeneralSettingPanel.vue b/frontend/src/components/Project/ProjectGeneralSettingPanel.vueindex 4615f7ead6..01af3b8377 100644--- a/frontend/src/components/Project/ProjectGeneralSettingPanel.vue+++ b/frontend/src/components/Project/ProjectGeneralSettingPanel.vue@@ -61,6 +61,43 @@</div></div>+ <div class="flex flex-col">+ <div for="name" class="text-sm font-medium text-control-light">+ {{ $t("common.issue") }}+ </div>+ <div class="mt-2">+ <NTooltip placement="top-start" :disabled="allowEdit">+ <template #trigger>+ <label+ class="flex items-center gap-x-2"+ :class="[allowEdit ? 'cursor-pointer' : 'cursor-not-allowed']"+ >+ <NCheckbox+ :disabled="!allowEdit"+ :checked="restrictIssueCreationForSQLReview"+ :label="+ $t(+ 'settings.general.workspace.restrict-issue-creation-for-sql-review.title'+ )+ "+ @update:checked="handleRestrictIssueCreationForSQLReviewToggle"+ />+ </label>+ </template>+ <span class="text-sm text-gray-400 -translate-y-2">+ {{ $t("settings.general.workspace.only-admin-can-edit") }}+ </span>+ </NTooltip>+ <div class="mb-3 text-sm text-gray-400">+ {{+ $t(+ "settings.general.workspace.restrict-issue-creation-for-sql-review.description"+ )+ }}+ </div>+ </div>+ </div>+<div v-if="allowEdit" class="flex justify-end"><NButton type="primary" :disabled="!allowSave" @click.prevent="save">{{ $t("common.update") }}@@ -77,13 +114,22 @@<script lang="ts" setup>import { cloneDeep, isEmpty } from "lodash-es";-import { NTooltip } from "naive-ui";-import { computed, reactive } from "vue";+import { NTooltip, NCheckbox } from "naive-ui";+import { computed, reactive, watchEffect } from "vue";import { useI18n } from "vue-i18n";import ResourceIdField from "@/components/v2/Form/ResourceIdField.vue";-import { hasFeature, pushNotification, useProjectV1Store } from "@/store";+import {+ hasFeature,+ pushNotification,+ useProjectV1Store,+ usePolicyV1Store,+} from "@/store";import type { FeatureType } from "@/types";import { DEFAULT_PROJECT_ID } from "@/types";+import {+ PolicyResourceType,+ PolicyType,+} from "@/types/proto/v1/org_policy_service";import type { Project } from "@/types/proto/v1/project_service";import { TenantMode } from "@/types/proto/v1/project_service";import { extractProjectResourceName } from "@/utils";@@ -102,6 +148,14 @@ const props = defineProps<{const { t } = useI18n();const projectV1Store = useProjectV1Store();+const policyV1Store = usePolicyV1Store();++watchEffect(async () => {+ await policyV1Store.getOrFetchPolicyByParentAndType({+ parentPath: props.project.name,+ policyType: PolicyType.RESTRICT_ISSUE_CREATION_FOR_SQL_REVIEW,+ });+});const state = reactive<LocalState>({title: props.project.title,@@ -120,6 +174,31 @@ const allowSave = computed((): boolean => {);});+const restrictIssueCreationForSQLReview = computed((): boolean => {+ return (+ policyV1Store.getPolicyByParentAndType({+ parentPath: props.project.name,+ policyType: PolicyType.RESTRICT_ISSUE_CREATION_FOR_SQL_REVIEW,+ })?.restrictIssueCreationForSqlReviewPolicy?.disallow ?? false+ );+});++const handleRestrictIssueCreationForSQLReviewToggle = async (on: boolean) => {+ await policyV1Store.createPolicy(props.project.name, {+ type: PolicyType.RESTRICT_ISSUE_CREATION_FOR_SQL_REVIEW,+ resourceType: PolicyResourceType.PROJECT,+ restrictIssueCreationForSqlReviewPolicy: {+ disallow: on,+ },+ });++ pushNotification({+ module: "bytebase",+ style: "SUCCESS",+ title: t("settings.general.workspace.config-updated"),+ });+};+const save = () => {const projectPatch = cloneDeep(props.project);const updateMask: string[] = [];diff --git a/frontend/src/components/SQLCheck/SQLCheckPanel.vue b/frontend/src/components/SQLCheck/SQLCheckPanel.vueindex a0ee7f4eab..34229fefed 100644--- a/frontend/src/components/SQLCheck/SQLCheckPanel.vue+++ b/frontend/src/components/SQLCheck/SQLCheckPanel.vue@@ -38,9 +38,10 @@<script setup lang="ts">import { NButton } from "naive-ui";-import { computed, onMounted } from "vue";+import { computed, watchEffect, ref } from "vue";import { usePolicyV1Store } from "@/store";import type { ComposedDatabase } from "@/types";+import { PolicyType } from "@/types/proto/v1/org_policy_service";import {PlanCheckRun,PlanCheckRun_Result,@@ -64,28 +65,38 @@ defineEmits<{(event: "close"): void;}>();+const restrictIssueCreationForSqlReviewPolicy = ref(false);const policyV1Store = usePolicyV1Store();// disallow creating issues if advice statuses contains any error.const restrictIssueCreationForSQLReview = computed((): boolean => {return (- (policyV1Store.getPolicyByName(- "policies/RESTRICT_ISSUE_CREATION_FOR_SQL_REVIEW"- )?.restrictIssueCreationForSqlReviewPolicy?.disallow ??- false) &&+ restrictIssueCreationForSqlReviewPolicy.value &&advices.some((advice) => advice.status === Advice_Status.ERROR));});-onMounted(async () => {- await prepareOrgPolicy();-});+watchEffect(async () => {+ const workspaceLevelPolicy =+ await policyV1Store.getOrFetchPolicyByParentAndType({+ parentPath: "",+ policyType: PolicyType.RESTRICT_ISSUE_CREATION_FOR_SQL_REVIEW,+ });+ if (workspaceLevelPolicy?.restrictIssueCreationForSqlReviewPolicy?.disallow) {+ restrictIssueCreationForSqlReviewPolicy.value = true;+ return;+ }-const prepareOrgPolicy = async () => {- await policyV1Store.getOrFetchPolicyByName(- "policies/RESTRICT_ISSUE_CREATION_FOR_SQL_REVIEW"- );-};+ const projectLevelPolicy =+ await policyV1Store.getOrFetchPolicyByParentAndType({+ parentPath: database.project,+ policyType: PolicyType.RESTRICT_ISSUE_CREATION_FOR_SQL_REVIEW,+ });+ if (projectLevelPolicy?.restrictIssueCreationForSqlReviewPolicy?.disallow) {+ restrictIssueCreationForSqlReviewPolicy.value = true;+ return;+ }+});const environment = computed(() => {return database.effectiveEnvironmentEntity.name;