Skip to content

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

chore: optimize sql review binding resource (#12805)

ecmadaoeae4e4024d1a
diff --git a/frontend/src/components/SQLReview/components/SQLReviewAttachResourcesPanel.vue b/frontend/src/components/SQLReview/components/SQLReviewAttachResourcesPanel.vue
index 9e4d003533..0243303c7f 100644
--- a/frontend/src/components/SQLReview/components/SQLReviewAttachResourcesPanel.vue
+++ b/frontend/src/components/SQLReview/components/SQLReviewAttachResourcesPanel.vue
@@ -57,11 +57,7 @@
<NButton @click="$emit('close')">
{{ $t("common.cancel") }}
</NButton>
- <NButton
- :disabled="!hasPermission"
- type="primary"
- @click="upsertReviewResource"
- >
+ <NButton :disabled="!hasPermission" type="primary" @click="onConfirm">
{{ $t("common.confirm") }}
</NButton>
</div>
@@ -70,8 +66,9 @@
</Drawer>
</template>
-<script setup lang="ts">
-import { NDivider } from "naive-ui";
+<script setup lang="tsx">
+import { cloneDeep } from "lodash-es";
+import { NDivider, useDialog } from "naive-ui";
import { watch, ref, computed } from "vue";
import { useI18n } from "vue-i18n";
import {
@@ -87,6 +84,7 @@ import {
} from "@/store/modules/v1/common";
import type { SQLReviewPolicy } from "@/types";
import { hasWorkspacePermissionV2 } from "@/utils";
+import SQLReviewAttachedResource from "./SQLReviewAttachedResource.vue";
const props = defineProps<{
show: boolean;
@@ -101,6 +99,7 @@ const me = useCurrentUserV1();
const resources = ref<string[]>([]);
const sqlReviewStore = useSQLReviewStore();
const { t } = useI18n();
+const $dialog = useDialog();
watch(
() => props.review.resources,
@@ -131,6 +130,67 @@ const onResourcesChange = (
resources.value = [...newResources, ...otherResources];
};
+const resourcesBindingWithOtherPolicy = computed(() => {
+ const map = new Map<string, string[]>();
+ for (const resource of resources.value) {
+ const config = sqlReviewStore.getReviewPolicyByResouce(resource);
+ if (config && config.id !== props.review.id) {
+ if (!map.has(config.id)) {
+ map.set(config.id, []);
+ }
+ map.get(config.id)?.push(resource);
+ }
+ }
+ return map;
+});
+
+const onConfirm = async () => {
+ if (resourcesBindingWithOtherPolicy.value.size === 0) {
+ await upsertReviewResource();
+ } else {
+ $dialog.warning({
+ title: t("common.warning"),
+ style: "z-index: 100000",
+ negativeText: t("common.cancel"),
+ positiveText: t("common.continue-anyway"),
+ content: () => {
+ const resources = [
+ ...resourcesBindingWithOtherPolicy.value.values(),
+ ].reduce((list, resources) => {
+ list.push(...resources);
+ return list;
+ }, []);
+ return (
+ <div class="space-y-2">
+ <p>
+ {t("sql-review.attach-resource.override-warning", {
+ button: t("common.continue-anyway"),
+ })}
+ </p>
+ <ul class="list-disc ml-4 textinfolabel">
+ {resources.map((resource) => (
+ <li>
+ <SQLReviewAttachedResource
+ resource={resource}
+ link={false}
+ showPrefix={true}
+ />
+ </li>
+ ))}
+ </ul>
+ </div>
+ );
+ },
+ onPositiveClick: () => {
+ const map = cloneDeep(resourcesBindingWithOtherPolicy.value);
+ upsertReviewResource().then(() => {
+ sqlReviewStore.removeResourceForReview(map);
+ });
+ },
+ });
+ }
+};
+
const upsertReviewResource = async () => {
await sqlReviewStore.upsertReviewConfigTag({
oldResources: props.review.resources,
diff --git a/frontend/src/components/v2/Model/DatabaseV1Table/cells/ProjectNameCell.vue b/frontend/src/components/v2/Model/DatabaseV1Table/cells/ProjectNameCell.vue
index 68fa1f651a..508368a20b 100644
--- a/frontend/src/components/v2/Model/DatabaseV1Table/cells/ProjectNameCell.vue
+++ b/frontend/src/components/v2/Model/DatabaseV1Table/cells/ProjectNameCell.vue
@@ -7,9 +7,9 @@
:keyword="keyword"
/>
- <span v-if="suffix">
+ <slot name="suffix">
{{ suffix }}
- </span>
+ </slot>
<NTooltip v-if="project.workflow === Workflow.VCS">
<template #trigger>
diff --git a/frontend/src/components/v2/Model/EnvironmentV1Name.vue b/frontend/src/components/v2/Model/EnvironmentV1Name.vue
index a5c90ff585..46f0944eb0 100644
--- a/frontend/src/components/v2/Model/EnvironmentV1Name.vue
+++ b/frontend/src/components/v2/Model/EnvironmentV1Name.vue
@@ -8,7 +8,9 @@
<span class="line-clamp-1 select-none" :class="textClass">
{{ prefix }}
{{ environmentV1Name(environment) }}
- {{ suffix }}
+ <slot name="suffix">
+ {{ suffix }}
+ </slot>
</span>
<ProductionEnvironmentV1Icon
v-if="showIcon"
diff --git a/frontend/src/components/v2/Select/EnvironmentSelect.vue b/frontend/src/components/v2/Select/EnvironmentSelect.vue
index a90580ee86..56a027784a 100644
--- a/frontend/src/components/v2/Select/EnvironmentSelect.vue
+++ b/frontend/src/components/v2/Select/EnvironmentSelect.vue
@@ -16,7 +16,7 @@
<script lang="tsx" setup>
import type { SelectOption } from "naive-ui";
import { NSelect } from "naive-ui";
-import { computed, h, watchEffect } from "vue";
+import { computed, watchEffect } from "vue";
import { useEnvironmentV1Store, useProjectV1Store } from "@/store";
import { State } from "@/types/proto/v1/common";
import type { Environment } from "@/types/proto/v1/environment_service";
@@ -119,12 +119,22 @@ const options = computed(() => {
const renderLabel = (option: SelectOption) => {
const { environment } = option as EnvironmentSelectOption;
- return h(EnvironmentV1Name, {
- environment,
- showIcon: props.showProductionIcon,
- link: false,
- suffix: props.renderSuffix(environment.name),
- });
+
+ return (
+ <EnvironmentV1Name
+ environment={environment}
+ showIcon={props.showProductionIcon}
+ link={false}
+ >
+ {{
+ suffix: () => (
+ <span class="opacity-60 ml-1">
+ {props.renderSuffix(environment.name)}
+ </span>
+ ),
+ }}
+ </EnvironmentV1Name>
+ );
};
const filterByName = (pattern: string, option: SelectOption) => {
diff --git a/frontend/src/components/v2/Select/ProjectSelect.vue b/frontend/src/components/v2/Select/ProjectSelect.vue
index d4f7de34f7..c3bbbcc132 100644
--- a/frontend/src/components/v2/Select/ProjectSelect.vue
+++ b/frontend/src/components/v2/Select/ProjectSelect.vue
@@ -229,7 +229,13 @@ const renderLabel = (option: SelectOption) => {
project={project}
mode="ALL_SHORT"
suffix={props.renderSuffix(project.name)}
- />
+ >
+ {{
+ suffix: () => (
+ <span class="opacity-60">{props.renderSuffix(project.name)}</span>
+ ),
+ }}
+ </ProjectNameCell>
);
};
</script>
diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.json
index bd2063ef53..e639642347 100644
--- a/frontend/src/locales/en-US.json
+++ b/frontend/src/locales/en-US.json
@@ -2832,9 +2832,10 @@
"no-linked-resources": "No attached resources",
"change-resources": "Change attached resources",
"self": "Attach to resources",
- "label": "You can apply the review policy to environments or projects. One resource can only link one policy. The database will use the SQL review policy attached to the project, otherwise fallback to the environment policy.",
+ "label": "You can apply the review policy to environments or projects, this will affect all databases belong to the resource. The database will use the SQL review policy attached to the project, otherwise fallback to the environment policy.",
"label-environment": "The SQL review policy will effect all databases belongs to the selected environment.",
- "label-project": "The SQL review policy will effect all databases belongs to the selected project. The SQL review policy for environment will be ignored."
+ "label-project": "The SQL review policy will effect all databases belongs to the selected project. The SQL review policy for environment will be ignored.",
+ "override-warning": "Following resources already bound with other SQL review policies. Click \"{button}\" will override the config."
},
"create": {
"breadcrumb": "Create SQL review policy",
diff --git a/frontend/src/locales/es-ES.json b/frontend/src/locales/es-ES.json
index e400a465d4..0470015bf4 100644
--- a/frontend/src/locales/es-ES.json
+++ b/frontend/src/locales/es-ES.json
@@ -2834,7 +2834,8 @@
"self": "Adjuntar a recursos",
"label": "Puede aplicar la política de revisión a entornos o proyectos. Un recurso sólo puede vincular una política. La base de datos utilizará la política de revisión de SQL adjunta al proyecto; de lo contrario, recurrirá a la política de entorno.",
"label-environment": "La política de revisión de SQL afectará a todas las bases de datos que pertenecen al entorno seleccionado.",
- "label-project": "La política de revisión de SQL afectará a todas las bases de datos que pertenecen al proyecto seleccionado. Se ignorará la política de revisión de SQL para el entorno."
+ "label-project": "La política de revisión de SQL afectará a todas las bases de datos que pertenecen al proyecto seleccionado. Se ignorará la política de revisión de SQL para el entorno.",
+ "override-warning": "Siguiendo los recursos ya vinculados con otras políticas de revisión de SQL. Haga clic en \"{button}\" para anular la configuración."
},
"create": {
"breadcrumb": "Crear política de revisión SQL",
diff --git a/frontend/src/locales/ja-JP.json b/frontend/src/locales/ja-JP.json
index adf958737d..5e343eebff 100644
--- a/frontend/src/locales/ja-JP.json
+++ b/frontend/src/locales/ja-JP.json
@@ -2832,9 +2832,10 @@
"no-linked-resources": "リソースのバインドはありません",
"change-resources": "バインドされたリソースを変更する",
"self": "リソースにバインドする",
- "label": "監査ポリシーを環境またはプロジェクトに適用します。リソースは 1 つのポリシーにのみ関連付けることができます。データベースはプロジェクトに添付された SQL 監査ポリシーを使用します。それ以外の場合は、環境ポリシーにフォールバックします。",
+ "label": "監査ポリシーは環境リソースまたはプロジェクト リソースにバインドする必要があり、対応するリソースの下にあるすべてのデータベースに影響します。データベースがプロジェクト レベルと環境レベルの両方のポリシーの影響を受ける場合、プロジェクト レベルのポリシーのみが有効になります。",
"label-environment": "SQL 監査ポリシーは、選択した環境に属するすべてのデータベースに影響します。",
- "label-project": "SQL 監査ポリシーは、選択したプロジェクト内のすべてのデータベースに影響します。環境の SQL 監査ポリシーは無視されます。"
+ "label-project": "SQL 監査ポリシーは、選択したプロジェクト内のすべてのデータベースに影響します。環境の SQL 監査ポリシーは無視されます。",
+ "override-warning": "次のリソースは、他の SQL 監査ポリシーにバインドされています。 \"{button}\" をクリックすると設定が上書きされます。"
},
"create": {
"breadcrumb": "監査ポリシーを作成する",
diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.json
index 4f18b241b6..c37f4eb48e 100644
--- a/frontend/src/locales/zh-CN.json
+++ b/frontend/src/locales/zh-CN.json
@@ -2832,9 +2832,10 @@
"no-linked-resources": "没有绑定的资源",
"change-resources": "更改绑定的资源",
"self": "绑定到资源",
- "label": "将审核策略应用到环境或项目上。一个资源只能关联一个策略。数据库将使用附加到项目的 SQL 审核策略,否则将回退到环境策略。",
+ "label": "审核策略需要绑定到环境资源或项目资源上,并影响对应资源下所有数据库。若一个数据库同时受到项目级别与环境级别策略影响,则只有项目级别策略生效。",
"label-environment": "SQL 审查策略将影响属于所选环境的所有数据库。",
- "label-project": "SQL 审核策略将影响所选项目下的所有数据库。环境的 SQL 审核策略将被忽略。"
+ "label-project": "SQL 审核策略将影响所选项目下的所有数据库。环境的 SQL 审核策略将被忽略。",
+ "override-warning": "以下资源已与其他 SQL 审核策略绑定。点击“{button}”将覆盖配置。"
},
"create": {
"breadcrumb": "创建审核策略",
@@ -3629,4 +3630,4 @@
"self": "最后更新"
}
}
-}
\ No newline at end of file
+}
diff --git a/frontend/src/store/modules/sqlReview.ts b/frontend/src/store/modules/sqlReview.ts
index 3819a7eb29..ac0f6a2b41 100644
--- a/frontend/src/store/modules/sqlReview.ts
+++ b/frontend/src/store/modules/sqlReview.ts
@@ -109,6 +109,19 @@ export const useSQLReviewStore = defineStore("sqlReview", {
];
}
},
+ removeResourceForReview(map: Map<string, string[]>) {
+ for (const [configId, resources] of map.entries()) {
+ const reviewPolicy = this.reviewPolicyList.find(
+ (r) => r.id === configId
+ );
+ if (!reviewPolicy) {
+ continue;
+ }
+ reviewPolicy.resources = reviewPolicy.resources.filter(
+ (resource) => !resources.includes(resource)
+ );
+ }
+ },
async upsertReviewConfigTag({
oldResources,
newResources,