Skip to content

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

fix: update sql review policy (#11540)

ecmadaoe443e1a56c70
diff --git a/frontend/src/store/modules/sqlReview.ts b/frontend/src/store/modules/sqlReview.ts
index 61cdc4acce..c7e5024f5d 100644
--- a/frontend/src/store/modules/sqlReview.ts
+++ b/frontend/src/store/modules/sqlReview.ts
@@ -220,13 +220,6 @@ export const useSQLReviewStore = defineStore("sqlReview", {
): SQLReviewPolicy | undefined {
return this.reviewPolicyList.find((g) => g.environment.name === name);
},
- getReviewPolicyByEnvironmentUID(
- environmentId: string
- ): SQLReviewPolicy | undefined {
- return this.getReviewPolicyByEnvironmentName(
- `${environmentNamePrefix}${environmentId}`
- );
- },
async fetchReviewPolicyList(): Promise<SQLReviewPolicy[]> {
const policyStore = usePolicyV1Store();
@@ -268,13 +261,6 @@ export const useSQLReviewStore = defineStore("sqlReview", {
}
return reviewPolicy;
},
- async getOrFetchReviewPolicyByEnvironmentUID(
- uid: string
- ): Promise<SQLReviewPolicy | undefined> {
- return this.getOrFetchReviewPolicyByEnvironmentName(
- `${environmentNamePrefix}${uid}`
- );
- },
},
});
diff --git a/frontend/src/types/sqlReview.ts b/frontend/src/types/sqlReview.ts
index 1a0df0af1b..cc2098a47a 100644
--- a/frontend/src/types/sqlReview.ts
+++ b/frontend/src/types/sqlReview.ts
@@ -394,6 +394,9 @@ export const convertPolicyRuleToRuleTemplate = (
const templateComponent = componentList.find(
(c) => c.payload.type === "TEMPLATE"
);
+ const stringArrayComponent = componentList.find(
+ (c) => c.payload.type === "STRING_ARRAY"
+ );
switch (ruleTemplate.type) {
case "statement.query.minimum-plan-level":
@@ -552,8 +555,12 @@ export const convertPolicyRuleToRuleTemplate = (
case "index.type-allow-list":
case "system.charset.allowlist":
case "system.collation.allowlist":
- case "system.function.disallowed-list": {
- const stringArrayComponent = componentList[0];
+ case "system.function.disallowed-list":
+ case "table.disallow-dml":
+ case "table.disallow-ddl": {
+ if (!stringArrayComponent) {
+ throw new Error(`Invalid rule ${ruleTemplate.type}`);
+ }
const stringArrayPayload = {
...stringArrayComponent.payload,
value: (payload as StringArrayLimitPayload).list,
@@ -733,7 +740,9 @@ const mergeIndividualConfigAsRule = (
case "index.type-allow-list":
case "system.charset.allowlist":
case "system.collation.allowlist":
- case "system.function.disallowed-list": {
+ case "system.function.disallowed-list":
+ case "table.disallow-dml":
+ case "table.disallow-ddl": {
if (!stringArrayPayload) {
throw new Error(`Invalid rule ${template.type}`);
}
diff --git a/frontend/src/views/SettingWorkspaceSQLReviewDetail.vue b/frontend/src/views/SettingWorkspaceSQLReviewDetail.vue
index f46ad9b402..80422802c1 100644
--- a/frontend/src/views/SettingWorkspaceSQLReviewDetail.vue
+++ b/frontend/src/views/SettingWorkspaceSQLReviewDetail.vue
@@ -133,9 +133,9 @@
</template>
<script lang="ts" setup>
-import { computedAsync, useTitle } from "@vueuse/core";
+import { useTitle } from "@vueuse/core";
import { cloneDeep, groupBy } from "lodash-es";
-import { computed, reactive, toRef, watch } from "vue";
+import { computed, reactive, toRef, watch, watchEffect } from "vue";
import { useI18n } from "vue-i18n";
import { useRouter } from "vue-router";
import { BBTextField } from "@/bbkit";
@@ -152,6 +152,7 @@ import {
pushNotification,
useCurrentUserV1,
useSQLReviewStore,
+ useEnvironmentV1Store,
useSubscriptionV1Store,
} from "@/store";
import type { RuleTemplate, SchemaPolicyRule } from "@/types";
@@ -187,6 +188,7 @@ const { t } = useI18n();
const store = useSQLReviewStore();
const router = useRouter();
const currentUserV1 = useCurrentUserV1();
+const environmentV1Store = useEnvironmentV1Store();
const subscriptionStore = useSubscriptionV1Store();
const state = reactive<LocalState>({
@@ -205,12 +207,21 @@ const hasPermission = computed(() => {
return hasWorkspacePermissionV2(currentUserV1.value, "bb.policies.update");
});
-const reviewPolicy = computedAsync(async () => {
+const environment = computed(() => {
const environmentUID = idFromSlug(props.sqlReviewPolicySlug);
- const policy =
- await store.getOrFetchReviewPolicyByEnvironmentUID(environmentUID);
- return policy ?? unknown("SQL_REVIEW");
-}, unknown("SQL_REVIEW"));
+ return environmentV1Store.getEnvironmentByUID(environmentUID);
+});
+
+watchEffect(async () => {
+ await store.getOrFetchReviewPolicyByEnvironmentName(environment.value.name);
+});
+
+const reviewPolicy = computed(() => {
+ return (
+ store.getReviewPolicyByEnvironmentName(environment.value.name) ??
+ unknown("SQL_REVIEW")
+ );
+});
const ruleListOfPolicy = computed((): RuleTemplate[] => {
if (!reviewPolicy.value) {
@@ -267,6 +278,14 @@ const {
filteredRuleList,
} = useSQLRuleFilter(toRef(state, "ruleList"));
+const pushUpdatedNotify = () => {
+ pushNotification({
+ module: "bytebase",
+ style: "SUCCESS",
+ title: t("sql-review.policy-updated"),
+ });
+};
+
const changeName = async (name: string) => {
state.editingTitle = false;
const policy = reviewPolicy.value;
@@ -282,11 +301,7 @@ const changeName = async (name: string) => {
id: policy.id,
...upsert,
});
- pushNotification({
- module: "bytebase",
- style: "SUCCESS",
- title: t("sql-review.policy-updated"),
- });
+ pushUpdatedNotify();
};
const markChange = (rule: RuleTemplate, overrides: Partial<RuleTemplate>) => {
@@ -341,11 +356,7 @@ const onApplyChanges = async () => {
ruleList,
});
state.rulesUpdated = false;
- pushNotification({
- module: "bytebase",
- style: "SUCCESS",
- title: t("sql-review.policy-updated"),
- });
+ pushUpdatedNotify();
} finally {
state.updating = false;
}
@@ -357,18 +368,20 @@ const onEdit = () => {
filterParams.selectedCategory = undefined;
};
-const onArchive = () => {
- store.updateReviewPolicy({
+const onArchive = async () => {
+ await store.updateReviewPolicy({
id: reviewPolicy.value.id,
enforce: false,
});
+ pushUpdatedNotify();
};
-const onRestore = () => {
- store.updateReviewPolicy({
+const onRestore = async () => {
+ await store.updateReviewPolicy({
id: reviewPolicy.value.id,
enforce: true,
});
+ pushUpdatedNotify();
};
const onRemove = () => {