Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
feat: implement the CRUD in the frontend for the schema review policy (#1145)
ecmadao3218e87a4e4a
diff --git a/frontend/src/components/DatabaseBackupPanel.vue b/frontend/src/components/DatabaseBackupPanel.vueindex 40cbc421d3..8d5de64465 100644--- a/frontend/src/components/DatabaseBackupPanel.vue+++ b/frontend/src/components/DatabaseBackupPanel.vue@@ -148,7 +148,7 @@ import {BackupSettingUpsert,Database,NORMAL_POLL_INTERVAL,- PolicyBackupPlanPolicyPayload,+ BackupPlanPolicyPayload,POLL_JITTER,POST_CHANGE_POLL_INTERVAL,UNKNOWN_ID,@@ -300,7 +300,7 @@ export default defineComponent({"bb.policy.backup-plan");const payload = policy?.payload;- return (payload as PolicyBackupPlanPolicyPayload | undefined)?.schedule;+ return (payload as BackupPlanPolicyPayload | undefined)?.schedule;});const allowDisableAutoBackup = computed(() => {diff --git a/frontend/src/components/DatabaseSchemaReview/SchemaReviewConfig.vue b/frontend/src/components/DatabaseSchemaReview/SchemaReviewConfig.vueindex 74decc9c8e..035df5b10b 100644--- a/frontend/src/components/DatabaseSchemaReview/SchemaReviewConfig.vue+++ b/frontend/src/components/DatabaseSchemaReview/SchemaReviewConfig.vue@@ -53,7 +53,7 @@ import {RuleTemplate,RuleTemplatePayload,SchemaReviewPolicyTemplate,-} from "../../types/schemaSystem";+} from "@/types/schemaSystem";interface LocalState {activeRuleType: RuleType | null;diff --git a/frontend/src/components/DatabaseSchemaReview/SchemaReviewCreation.vue b/frontend/src/components/DatabaseSchemaReview/SchemaReviewCreation.vueindex 4f70016653..04873934ad 100644--- a/frontend/src/components/DatabaseSchemaReview/SchemaReviewCreation.vue+++ b/frontend/src/components/DatabaseSchemaReview/SchemaReviewCreation.vue@@ -72,7 +72,7 @@import { reactive, computed, withDefaults } from "vue";import { useI18n } from "vue-i18n";import { useRouter } from "vue-router";-import { BBStepTabItem } from "../../bbkit/types";+import { BBStepTabItem } from "@/bbkit/types";import {RuleType,ruleTemplateList,@@ -81,14 +81,14 @@ import {RuleTemplate,SchemaReviewPolicyTemplate,convertRuleTemplateToPolicyRule,-} from "../../types";+} from "@/types";import {useCurrentUser,pushNotification,useEnvironmentList,useSchemaSystemStore,} from "@/store";-import { isOwner, isDBA } from "../../utils";+import { isOwner, isDBA } from "@/utils";interface LocalState {currentStep: number;@@ -286,18 +286,23 @@ const tryFinishSetup = (allowChangeCallback: () => void) => {title: t("schema-review-policy.no-permission"),});}- const review = {+ const upsert = {name: state.name,- environmentId: state.selectedEnvironment?.id,ruleList: state.selectedRuleList.map((rule) =>convertRuleTemplateToPolicyRule(rule)),};if (props.reviewId) {- store.updateReviewPolicy(props.reviewId, review);+ store.updateReviewPolicy({+ id: props.reviewId,+ ...upsert,+ });} else {- store.addReviewPolicy(review);+ store.addReviewPolicy({+ ...upsert,+ environmentId: state.selectedEnvironment?.id,+ });}pushNotification({diff --git a/frontend/src/components/DatabaseSchemaReview/SchemaReviewInfo.vue b/frontend/src/components/DatabaseSchemaReview/SchemaReviewInfo.vueindex 0c1a1c4cf3..8adf10de12 100644--- a/frontend/src/components/DatabaseSchemaReview/SchemaReviewInfo.vue+++ b/frontend/src/components/DatabaseSchemaReview/SchemaReviewInfo.vue@@ -34,16 +34,11 @@"class="mb-5"/>- <div class="flex flex-wrap gap-x-3">+ <div class="flex flex-wrap gap-x-3" v-if="!isEdit"><divv-for="env in environmentList":key="env.id"- :class="[- 'flex items-center',- env.disabled- ? 'cursor-not-allowed text-gray-400'- : 'cursor-pointer text-gray-600',- ]"+ class="flex items-center"><inputtype="radio"@@ -64,6 +59,11 @@</label></div></div>+ <BBBadge+ v-else-if="isEdit && selectedEnvironment"+ :text="environmentName(selectedEnvironment)"+ :can-remove="false"+ /></div><div><div class="mt-5" v-if="isEdit">@@ -105,8 +105,8 @@<script lang="ts" setup>import { PropType, reactive, computed } from "vue";import { useSchemaSystemStore, useEnvironmentList } from "@/store";-import { Environment, SchemaReviewPolicyTemplate } from "../../types";-import { environmentName } from "../../utils";+import { Environment, SchemaReviewPolicyTemplate } from "@/types";+import { environmentName } from "@/utils";interface LocalEnvironment extends Environment {disabled: boolean;diff --git a/frontend/src/components/DatabaseSchemaReview/SchemaReviewPreview.vue b/frontend/src/components/DatabaseSchemaReview/SchemaReviewPreview.vueindex 476883f0dc..62b14cde9f 100644--- a/frontend/src/components/DatabaseSchemaReview/SchemaReviewPreview.vue+++ b/frontend/src/components/DatabaseSchemaReview/SchemaReviewPreview.vue@@ -110,8 +110,8 @@<script lang="ts" setup>import { computed } from "vue";-import { RuleTemplate, convertToCategoryList, Environment } from "../../types";-import { environmentName } from "../../utils";+import { RuleTemplate, convertToCategoryList, Environment } from "@/types";+import { environmentName } from "@/utils";const props = withDefaults(defineProps<{diff --git a/frontend/src/components/DatabaseSchemaReview/components/SchemaReviewCard.vue b/frontend/src/components/DatabaseSchemaReview/components/SchemaReviewCard.vueindex f7a5bb80aa..aa4807eea5 100644--- a/frontend/src/components/DatabaseSchemaReview/components/SchemaReviewCard.vue+++ b/frontend/src/components/DatabaseSchemaReview/components/SchemaReviewCard.vue@@ -3,15 +3,21 @@class="divide-y divide-block-border border border-block-border rounded-sm"><div class="flex py-2 px-4 justify-between">- <div class="flex flex-row space-x-2 items-center">+ <div class="flex flex-row space-x-3 items-center"><h3 class="text-lg leading-6 font-medium text-main">- {{ review.name }}+ {{ reviewPolicy.name }}</h3>+ <BBBadge+ v-if="reviewPolicy.rowStatus == 'ARCHIVED'"+ :text="$t('common.disable')"+ :can-remove="false"+ :style="'WARN'"+ /></div><buttontype="button"class="btn-normal py-2 px-4"- @click.prevent="emit('click', review)"+ @click.prevent="emit('click', reviewPolicy)">{{ $t("common.view") }}</button>@@ -24,8 +30,8 @@</dt><dd class="mt-1 flex gap-x-2 text-sm text-main col-span-2"><BBBadge- v-if="review.environmentId"- :text="envStore.getEnvironmentNameById(review.environmentId)"+ v-if="reviewPolicy.environment"+ :text="environmentName(reviewPolicy.environment)":can-remove="false"/><span class="text-yellow-700" v-else>@@ -42,7 +48,7 @@{{ $t("common.created-at") }}</dt><dd class="mt-1 flex text-sm text-main col-span-2">- {{ humanizeTs(review.createdTs) }}+ {{ humanizeTs(reviewPolicy.createdTs) }}</dd></div><div class="grid grid-cols-4 gap-4 px-4 py-2 items-center">@@ -50,7 +56,7 @@{{ $t("common.updated-at") }}</dt><dd class="mt-1 flex text-sm text-main col-span-2">- {{ humanizeTs(review.updatedTs) }}+ {{ humanizeTs(reviewPolicy.updatedTs) }}</dd></div><div class="grid grid-cols-4 gap-4 px-4 py-2 items-center">@@ -58,7 +64,7 @@{{ $t("common.creator") }}</dt><dd class="mt-1 flex text-sm text-main col-span-2">- {{ review.creator.name }}+ {{ reviewPolicy.creator.name }}</dd></div></dl>@@ -69,11 +75,12 @@<script lang="ts" setup>import { PropType } from "vue";import { useRouter } from "vue-router";-import { DatabaseSchemaReviewPolicy } from "../../../types/schemaSystem";+import { DatabaseSchemaReviewPolicy } from "@/types/schemaSystem";import { useEnvironmentStore } from "@/store";+import { environmentName } from "@/utils";const props = defineProps({- review: {+ reviewPolicy: {required: true,type: Object as PropType<DatabaseSchemaReviewPolicy>,},diff --git a/frontend/src/components/DatabaseSchemaReview/components/SchemaReviewCategoryTabFilter.vue b/frontend/src/components/DatabaseSchemaReview/components/SchemaReviewCategoryTabFilter.vueindex 6a93510769..3c2ccd3b8f 100644--- a/frontend/src/components/DatabaseSchemaReview/components/SchemaReviewCategoryTabFilter.vue+++ b/frontend/src/components/DatabaseSchemaReview/components/SchemaReviewCategoryTabFilter.vue@@ -13,9 +13,9 @@<script lang="ts" setup>import { computed, reactive, PropType, watch } from "vue";-import { BBTabFilterItem } from "../../../bbkit/types";+import { BBTabFilterItem } from "@/bbkit/types";import { useI18n } from "vue-i18n";-import { CategoryType } from "../../../types/schemaSystem";+import { CategoryType } from "@/types/schemaSystem";export interface CategoryFilterItem {id: CategoryType;diff --git a/frontend/src/components/DatabaseSchemaReview/components/SchemaReviewTemplates.vue b/frontend/src/components/DatabaseSchemaReview/components/SchemaReviewTemplates.vueindex 598a071eab..38879af8c6 100644--- a/frontend/src/components/DatabaseSchemaReview/components/SchemaReviewTemplates.vue+++ b/frontend/src/components/DatabaseSchemaReview/components/SchemaReviewTemplates.vue@@ -31,7 +31,7 @@<script lang="ts" setup>import { PropType } from "vue";-import { SchemaReviewPolicyTemplate } from "../../../types/schemaSystem";+import { SchemaReviewPolicyTemplate } from "@/types/schemaSystem";const props = defineProps({templateList: {diff --git a/frontend/src/components/DatabaseSchemaReview/components/SchemaRuleConfig.vue b/frontend/src/components/DatabaseSchemaReview/components/SchemaRuleConfig.vueindex 9ed527442e..cceb2fd620 100644--- a/frontend/src/components/DatabaseSchemaReview/components/SchemaRuleConfig.vue+++ b/frontend/src/components/DatabaseSchemaReview/components/SchemaRuleConfig.vue@@ -104,11 +104,12 @@<script lang="ts" setup>import { reactive, PropType, watch } from "vue";+import { pullAt } from "lodash-es";import {LEVEL_LIST,RuleTemplate,RuleTemplatePayload,-} from "../../../types/schemaSystem";+} from "@/types/schemaSystem";type PayloadValueList = (string | string[])[];interface LocalState {@@ -154,11 +155,7 @@ const removeFromList = (i: number, val: any) => {const values = state.payload[i] as string[];const index = values.indexOf(val);- if (index < 0) {- return;- }-- state.payload[i] = [...values.slice(0, index), ...values.slice(index + 1)];+ pullAt(state.payload[i], index);};const pushToList = (i: number, e: any) => {diff --git a/frontend/src/components/DatabaseSchemaReview/components/SchemaRuleLevelBadge.vue b/frontend/src/components/DatabaseSchemaReview/components/SchemaRuleLevelBadge.vueindex e826172f9b..5160c1de1e 100644--- a/frontend/src/components/DatabaseSchemaReview/components/SchemaRuleLevelBadge.vue+++ b/frontend/src/components/DatabaseSchemaReview/components/SchemaRuleLevelBadge.vue@@ -8,8 +8,8 @@<script lang="ts" setup>import { PropType, computed } from "vue";-import { RuleLevel } from "../../../types/schemaSystem";-import { BBAttentionStyle } from "../../../bbkit/types";+import { RuleLevel } from "@/types/schemaSystem";+import { BBAttentionStyle } from "@/bbkit/types";const props = defineProps({level: {diff --git a/frontend/src/router/index.ts b/frontend/src/router/index.tsindex 834e328a60..eef34a17e0 100644--- a/frontend/src/router/index.ts+++ b/frontend/src/router/index.ts@@ -395,7 +395,7 @@ const routes: Array<RouteRecordRaw> = [meta: {title: (route: RouteLocationNormalized) => {const slug = route.params.schemaReviewPolicySlug as string;- return useSchemaSystemStore().getReviewPolicyById(+ return useSchemaSystemStore().getReviewPolicyByEnvironmentId(idFromSlug(slug)).name;},@@ -1206,7 +1206,7 @@ router.beforeEach((to, from, next) => {if (schemaReviewPolicySlug) {useSchemaSystemStore()- .fetchReviewPolicyById(idFromSlug(schemaReviewPolicySlug))+ .fetchReviewPolicyByEnvironmentId(idFromSlug(schemaReviewPolicySlug)).then(() => {next();})diff --git a/frontend/src/store/modules/policy.ts b/frontend/src/store/modules/policy.tsindex 38ca36d76c..912e431032 100644--- a/frontend/src/store/modules/policy.ts+++ b/frontend/src/store/modules/policy.ts@@ -84,6 +84,13 @@ export const usePolicyStore = defineStore("policy", {);}},+ async fetchPolicyListByType(type: PolicyType): Promise<Policy[]> {+ const data: { data: ResourceObject[]; included: ResourceObject[] } = (+ await axios.get(`/api/policy?type=${type}`)+ ).data;++ return data.data.map((d) => convert(d, data.included));+ },async fetchPolicyByEnvironmentAndType({environmentId,type,@@ -115,7 +122,10 @@ export const usePolicyStore = defineStore("policy", {data: {type: "policyUpsert",attributes: {- payload: JSON.stringify(policyUpsert.payload),+ rowStatus: policyUpsert.rowStatus,+ payload: policyUpsert.payload+ ? JSON.stringify(policyUpsert.payload)+ : undefined,},},}@@ -127,5 +137,16 @@ export const usePolicyStore = defineStore("policy", {return policy;},+ async deletePolicyByEnvironmentAndType({+ environmentId,+ type,+ }: {+ environmentId: EnvironmentId;+ type: PolicyType;+ }) {+ await axios.delete(+ `/api/policy/environment/${environmentId}?type=${type}`+ );+ },},});diff --git a/frontend/src/store/modules/schemaSystem.ts b/frontend/src/store/modules/schemaSystem.tsindex 53a1aa24f5..b61fed17aa 100644--- a/frontend/src/store/modules/schemaSystem.ts+++ b/frontend/src/store/modules/schemaSystem.ts@@ -1,17 +1,51 @@-import axios from "axios";+import { pullAt } from "lodash-es";import {empty,unknown,- SchemaReviewPolicyId,+ Policy,+ PolicyId,+ EnvironmentId,+ RowStatus,EMPTY_ID,- UNKNOWN_ID,Environment,+ PolicyUpsert,+ SchemaPolicyRule,+ SchemaReviewPolicyPayload,DatabaseSchemaReviewPolicy,- DatabaseSchemaReviewPolicyCreate,- DatabaseSchemaReviewPolicyPatch,-} from "../../types";+} from "@/types";import { defineStore } from "pinia";-import { useCurrentUser } from "./auth";+import { usePolicyStore } from "./policy";++const convertToSchemaReviewPolicy = (+ policy: Policy+): DatabaseSchemaReviewPolicy | undefined => {+ if (policy.type !== "bb.policy.schema-review") {+ return;+ }+ const payload = policy.payload as SchemaReviewPolicyPayload;+ const ruleList = payload.ruleList.map((r) => {+ const rule: SchemaPolicyRule = {+ type: r.type,+ level: r.level,+ };+ if (r.payload && r.payload !== "{}") {+ rule.payload = JSON.parse(r.payload);+ }+ return rule;+ });++ return {+ id: policy.id,+ creator: policy.creator,+ createdTs: policy.createdTs,+ updater: policy.updater,+ updatedTs: policy.updatedTs,+ rowStatus: policy.rowStatus,+ environment: policy.environment,+ name: payload.name,+ ruleList,+ };+};interface SchemaSystemState {reviewPolicyList: DatabaseSchemaReviewPolicy[];@@ -22,9 +56,26 @@ export const useSchemaSystemStore = defineStore("schemaSystem", {reviewPolicyList: [],}),actions: {+ setReviewPolicy(reviewPolicy: DatabaseSchemaReviewPolicy) {+ const index = this.reviewPolicyList.findIndex(+ (r) => r.id === reviewPolicy.id+ );+ if (index < 0) {+ this.reviewPolicyList.push(reviewPolicy);+ } else {+ this.reviewPolicyList = [+ ...this.reviewPolicyList.slice(0, index),+ {+ ...this.reviewPolicyList[index],+ ...reviewPolicy,+ },+ ...this.reviewPolicyList.slice(index + 1),+ ];+ }+ },availableEnvironments(environmentList: Environment[],- reviewPolicyId: SchemaReviewPolicyId | undefined+ reviewPolicyId: PolicyId | undefined): Environment[] {const envMap = environmentList.reduce((map, env) => {map.set(env.id, env);@@ -32,81 +83,158 @@ export const useSchemaSystemStore = defineStore("schemaSystem", {}, new Map<number, Environment>());for (const reviewPolicy of this.reviewPolicyList) {- if (reviewPolicy.id === reviewPolicyId || !reviewPolicy.environmentId) {+ if (+ reviewPolicy.id === reviewPolicyId ||+ !reviewPolicy.environment.id+ ) {continue;}- if (envMap.has(reviewPolicy.environmentId)) {- envMap.delete(reviewPolicy.environmentId);+ if (envMap.has(reviewPolicy.environment.id)) {+ envMap.delete(reviewPolicy.environment.id);}}return [...envMap.values()];},- addReviewPolicy(review: DatabaseSchemaReviewPolicyCreate) {- // TODO: need update after backend is implemented- const user = useCurrentUser();- this.reviewPolicyList.push({- ...review,- id: this.reviewPolicyList.length + 1,- creator: user.value,- updater: user.value,- rowStatus: "NORMAL",- createdTs: new Date().getTime() / 1000,- updatedTs: new Date().getTime() / 1000,+ async addReviewPolicy({+ name,+ environmentId,+ ruleList,+ }: {+ name: string;+ environmentId: number;+ ruleList: SchemaPolicyRule[];+ }) {+ const payload: SchemaReviewPolicyPayload = {+ name,+ ruleList: ruleList.map((r) => ({+ ...r,+ payload: r.payload ? JSON.stringify(r.payload) : "{}",+ })),+ };++ const policyStore = usePolicyStore();+ const policy = await policyStore.upsertPolicyByEnvironmentAndType({+ environmentId,+ type: "bb.policy.schema-review",+ policyUpsert: { payload },});++ const reviewPolicy = convertToSchemaReviewPolicy(policy);+ if (!reviewPolicy) {+ throw new Error(`invalid policy ${JSON.stringify(policy)}`);+ }++ this.setReviewPolicy(reviewPolicy);},- removeReviewPolicy(id: SchemaReviewPolicyId) {- // TODO: need update after backend is implemented+ async removeReviewPolicy(id: PolicyId) {const index = this.reviewPolicyList.findIndex((g) => g.id === id);if (index < 0) {return;}- this.reviewPolicyList = [- ...this.reviewPolicyList.slice(0, index),- ...this.reviewPolicyList.slice(index + 1),- ];++ const targetPolicy = this.reviewPolicyList[index];+ const policyStore = usePolicyStore();+ await policyStore.deletePolicyByEnvironmentAndType({+ environmentId: targetPolicy.environment.id,+ type: "bb.policy.schema-review",+ });++ pullAt(this.reviewPolicyList, index);},- updateReviewPolicy(- id: SchemaReviewPolicyId,- review: DatabaseSchemaReviewPolicyPatch- ) {- // TODO: need update after backend is implemented+ async updateReviewPolicy({+ id,+ name,+ rowStatus,+ ruleList,+ }: {+ id: PolicyId;+ name?: string;+ rowStatus?: RowStatus;+ ruleList?: SchemaPolicyRule[];+ }) {const index = this.reviewPolicyList.findIndex((g) => g.id === id);if (index < 0) {return;}++ const targetPolicy = this.reviewPolicyList[index];++ const policyUpsert: PolicyUpsert = {};+ if (rowStatus) {+ policyUpsert.rowStatus = rowStatus;+ }+ if (name && ruleList) {+ const payload: SchemaReviewPolicyPayload = {+ name,+ ruleList: ruleList.map((r) => ({+ ...r,+ payload: r.payload ? JSON.stringify(r.payload) : "{}",+ })),+ };+ policyUpsert.payload = payload;+ }++ const policyStore = usePolicyStore();+ const policy = await policyStore.upsertPolicyByEnvironmentAndType({+ environmentId: targetPolicy.environment.id,+ type: "bb.policy.schema-review",+ policyUpsert,+ });++ const reviewPolicy = convertToSchemaReviewPolicy(policy);this.reviewPolicyList = [...this.reviewPolicyList.slice(0, index),{...this.reviewPolicyList[index],- ...review,+ ...reviewPolicy,},...this.reviewPolicyList.slice(index + 1),];},- getReviewPolicyById(id: SchemaReviewPolicyId): DatabaseSchemaReviewPolicy {- if (id === EMPTY_ID) {+ getReviewPolicyByEnvironmentId(+ environmentId: EnvironmentId+ ): DatabaseSchemaReviewPolicy {+ if (environmentId === EMPTY_ID) {return empty("SCHEMA_REVIEW") as DatabaseSchemaReviewPolicy;}return (- this.reviewPolicyList.find((g) => g.id === id) ||+ this.reviewPolicyList.find((g) => g.environment.id === environmentId) ||(unknown("SCHEMA_REVIEW") as DatabaseSchemaReviewPolicy));},async fetchReviewPolicyList(): Promise<DatabaseSchemaReviewPolicy[]> {- throw new Error("function haven't implement yet");+ const policyStore = usePolicyStore();+ const policyList = await policyStore.fetchPolicyListByType(+ "bb.policy.schema-review"+ );++ const reviewPolicyList = policyList.reduce((list, policy) => {+ const reviewPolicy = convertToSchemaReviewPolicy(policy);+ if (reviewPolicy) {+ list.push(reviewPolicy);+ }+ return list;+ }, [] as DatabaseSchemaReviewPolicy[]);+ this.reviewPolicyList = reviewPolicyList;+ return reviewPolicyList;},- async fetchReviewPolicyById(- id: SchemaReviewPolicyId- ): Promise<DatabaseSchemaReviewPolicy> {- // TODO: should remove this after the backend is implemented- const review = this.getReviewPolicyById(id);- if (review.id === UNKNOWN_ID || review.id === EMPTY_ID) {- throw new Error(`review ${id} not found`);+ async fetchReviewPolicyByEnvironmentId(+ environmentId: EnvironmentId+ ): Promise<DatabaseSchemaReviewPolicy | undefined> {+ const policyStore = usePolicyStore();+ const policy = await policyStore.fetchPolicyByEnvironmentAndType({+ environmentId: environmentId,+ type: "bb.policy.schema-review",+ });++ const reviewPolicy = convertToSchemaReviewPolicy(policy);+ if (reviewPolicy) {+ this.setReviewPolicy(reviewPolicy);}- return review;+ return reviewPolicy;},},});diff --git a/frontend/src/types/common.ts b/frontend/src/types/common.tsindex 61000776b7..9b270900b5 100644--- a/frontend/src/types/common.ts+++ b/frontend/src/types/common.ts@@ -326,6 +326,7 @@ const makeUnknown = (type: ResourceType) => {createdTs: 0,updater: UNKNOWN_PRINCIPAL,updatedTs: 0,+ rowStatus: "NORMAL",environment: UNKNOWN_ENVIRONMENT,type: "bb.policy.pipeline-approval",payload: {@@ -491,11 +492,13 @@ const makeUnknown = (type: ResourceType) => {const UNKNOWN_SCHEMA_REVIEW_POLICY: DatabaseSchemaReviewPolicy = {id: UNKNOWN_ID,- name: "",creator: UNKNOWN_PRINCIPAL,updater: UNKNOWN_PRINCIPAL,createdTs: 0,updatedTs: 0,+ rowStatus: "NORMAL",+ environment: UNKNOWN_ENVIRONMENT,+ name: "",ruleList: [],};@@ -709,6 +712,7 @@ const makeEmpty = (type: ResourceType) => {createdTs: 0,updater: EMPTY_PRINCIPAL,updatedTs: 0,+ rowStatus: "NORMAL",environment: EMPTY_ENVIRONMENT,type: "bb.policy.pipeline-approval",payload: {@@ -874,11 +878,13 @@ const makeEmpty = (type: ResourceType) => {const EMPTY_SCHEMA_REVIEW_POLICY: DatabaseSchemaReviewPolicy = {id: EMPTY_ID,- name: "",creator: EMPTY_PRINCIPAL,updater: EMPTY_PRINCIPAL,createdTs: 0,updatedTs: 0,+ rowStatus: "NORMAL",+ environment: EMPTY_ENVIRONMENT,+ name: "",ruleList: [],};diff --git a/frontend/src/types/id.ts b/frontend/src/types/id.tsindex 1966be8481..0cf41e7a41 100644--- a/frontend/src/types/id.ts+++ b/frontend/src/types/id.ts@@ -70,8 +70,6 @@ export type CommandRegisterId = string;export type SheetId = IdType;-export type SchemaReviewPolicyId = IdType;-// This references to the object id, which can be used as a container.// Currently, only issue can be used a container.// The type is used by Activity and Messagediff --git a/frontend/src/types/policy.ts b/frontend/src/types/policy.tsindex 2f4f2426d5..f63112b270 100644--- a/frontend/src/types/policy.ts+++ b/frontend/src/types/policy.ts@@ -1,8 +1,16 @@-import { Environment, PolicyId, Principal } from ".";+import {+ RowStatus,+ Environment,+ PolicyId,+ Principal,+ RuleType,+ RuleLevel,+} from ".";export type PolicyType =| "bb.policy.pipeline-approval"- | "bb.policy.backup-plan";+ | "bb.policy.backup-plan"+ | "bb.policy.schema-review";export type PipelineApprovalPolicyValue =| "MANUAL_APPROVAL_NEVER"@@ -17,15 +25,26 @@ export const DefaultApporvalPolicy: PipelineApprovalPolicyValue =export type BackupPlanPolicySchedule = "UNSET" | "DAILY" | "WEEKLY";-export type PolicyBackupPlanPolicyPayload = {+export type BackupPlanPolicyPayload = {schedule: BackupPlanPolicySchedule;};export const DefaultSchedulePolicy: BackupPlanPolicySchedule = "UNSET";+// SchemaReviewPolicyPayload is the payload for schema review policy in the backend.+export type SchemaReviewPolicyPayload = {+ name: string;+ ruleList: {+ type: RuleType;+ level: RuleLevel;+ payload: string;+ }[];+};+export type PolicyPayload =| PipelineApporvalPolicyPayload- | PolicyBackupPlanPolicyPayload;+ | BackupPlanPolicyPayload+ | SchemaReviewPolicyPayload;export type Policy = {id: PolicyId;@@ -35,6 +54,7 @@ export type Policy = {createdTs: number;updater: Principal;updatedTs: number;+ rowStatus: RowStatus;// Related fieldsenvironment: Environment;@@ -45,6 +65,9 @@ export type Policy = {};export type PolicyUpsert = {+ // Standard fields+ rowStatus?: RowStatus;+// Domain specific fieldspayload?: PolicyPayload;};diff --git a/frontend/src/types/schemaSystem.ts b/frontend/src/types/schemaSystem.tsindex 6b04285fb7..555d8ed5ea 100644--- a/frontend/src/types/schemaSystem.ts+++ b/frontend/src/types/schemaSystem.ts@@ -1,6 +1,7 @@-import { SchemaReviewPolicyId } from "./id";+import { PolicyId } from "./id";import { Principal } from "./principal";import { RowStatus } from "./common";+import { Environment } from "./environment";// The engine type for rule templateexport type SchemaRuleEngineType = "MYSQL" | "COMMON";@@ -92,7 +93,7 @@ export interface SchemaPolicyRule {// The API for schema review policy in backend.// TODO: just use the existed Policy entityexport interface DatabaseSchemaReviewPolicy {- id: SchemaReviewPolicyId;+ id: PolicyId;// Standard fieldscreator: Principal;@@ -104,34 +105,16 @@ export interface DatabaseSchemaReviewPolicy {// Domain specific fieldsname: string;ruleList: SchemaPolicyRule[];- environmentId: number;+ environment: Environment;}-// DatabaseSchemaReviewPolicyCreate is the API message for create review policy.-// TODO: just use the existed PolicyUpsert entity-export interface DatabaseSchemaReviewPolicyCreate {- // Domain specific fields- name: string;- ruleList: SchemaPolicyRule[];- environmentId: number;-}--// DatabaseSchemaReviewPolicyPatch is the API message for patch review policy.-// TODO: just use the existed PolicyUpsert entity-export type DatabaseSchemaReviewPolicyPatch = {- // Domain specific fields- name?: string;- ruleList?: SchemaPolicyRule[];- environmentId?: number;- rowStatus?: RowStatus;-};-// RuleTemplate is the rule template. Used by the frontendexport interface RuleTemplate {type: RuleType;category: CategoryType;engine: SchemaRuleEngineType;description: string;+ // TODO: rename componentList to RuleConfigComponentcomponentList: RuleTemplatePayload[];level: RuleLevel;}diff --git a/frontend/src/utils/slug.ts b/frontend/src/utils/slug.tsindex fb97abd1ba..3be9a2a8ce 100644--- a/frontend/src/utils/slug.ts+++ b/frontend/src/utils/slug.ts@@ -88,7 +88,7 @@ export function vcsSlug(vcs: VCS): string {export function schemaReviewPolicySlug(reviewPolicy: DatabaseSchemaReviewPolicy): string {- return [slug(reviewPolicy.name), reviewPolicy.id].join("-");+ return [slug(reviewPolicy.name), reviewPolicy.environment.id].join("-");}export function connectionSlug(database: Database): string {diff --git a/frontend/src/views/EnvironmentDashboard.vue b/frontend/src/views/EnvironmentDashboard.vueindex 9b1d598859..c170b10720 100644--- a/frontend/src/views/EnvironmentDashboard.vue+++ b/frontend/src/views/EnvironmentDashboard.vue@@ -89,7 +89,7 @@ import {DefaultApporvalPolicy,DefaultSchedulePolicy,PipelineApporvalPolicyPayload,- PolicyBackupPlanPolicyPayload,+ BackupPlanPolicyPayload,} from "../types";import { BBTabItem } from "../bbkit/types";import {@@ -242,7 +242,7 @@ export default defineComponent({return;}if (- (backupPolicy.payload as PolicyBackupPlanPolicyPayload).schedule !==+ (backupPolicy.payload as BackupPlanPolicyPayload).schedule !==DefaultSchedulePolicy &&!hasFeature("bb.feature.backup-policy")) {diff --git a/frontend/src/views/EnvironmentDetail.vue b/frontend/src/views/EnvironmentDetail.vueindex 2b4cae635c..a6fe4eb2dc 100644--- a/frontend/src/views/EnvironmentDetail.vue+++ b/frontend/src/views/EnvironmentDetail.vue@@ -32,7 +32,7 @@ import {DefaultApporvalPolicy,DefaultSchedulePolicy,PipelineApporvalPolicyPayload,- PolicyBackupPlanPolicyPayload,+ BackupPlanPolicyPayload,} from "../types";import { idFromSlug } from "../utils";import { hasFeature, useEnvironmentStore, usePolicyStore } from "@/store";@@ -151,7 +151,7 @@ export default defineComponent({}if (type === "bb.policy.backup-plan" &&- (policy.payload as PolicyBackupPlanPolicyPayload).schedule !==+ (policy.payload as BackupPlanPolicyPayload).schedule !==DefaultSchedulePolicy &&!hasFeature("bb.feature.backup-policy")) {diff --git a/frontend/src/views/SettingWorkspaceSchemaReview.vue b/frontend/src/views/SettingWorkspaceSchemaReview.vueindex e7bef82f5b..60bae5dfd4 100644--- a/frontend/src/views/SettingWorkspaceSchemaReview.vue+++ b/frontend/src/views/SettingWorkspaceSchemaReview.vue@@ -15,7 +15,7 @@</div></div><template v-for="review in store.reviewPolicyList" :key="review.id">- <SchemaReviewCard :review="review" @click="onClick" />+ <SchemaReviewCard :review-policy="review" @click="onClick" /></template></div><template v-else>@@ -25,6 +25,7 @@</template><script lang="ts" setup>+import { computed, watchEffect } from "vue";import { useRouter } from "vue-router";import { useI18n } from "vue-i18n";import {@@ -32,9 +33,8 @@ import {useSchemaSystemStore,useCurrentUser,} from "@/store";-import { DatabaseSchemaReviewPolicy } from "../types/schemaSystem";-import { schemaReviewPolicySlug, isOwner, isDBA } from "../utils";-import { computed } from "vue";+import { DatabaseSchemaReviewPolicy } from "@/types/schemaSystem";+import { schemaReviewPolicySlug, isOwner, isDBA } from "@/utils";const router = useRouter();const store = useSchemaSystemStore();@@ -42,6 +42,10 @@ const ROUTE_NAME = "setting.workspace.schema-review-policy";const currentUser = useCurrentUser();const { t } = useI18n();+watchEffect(() => {+ store.fetchReviewPolicyList();+});+const hasPermission = computed(() => {return isOwner(currentUser.value.role) || isDBA(currentUser.value.role);});diff --git a/frontend/src/views/SettingWorkspaceSchemaReviewDetail.vue b/frontend/src/views/SettingWorkspaceSchemaReviewDetail.vueindex d9dc491561..63b43fa5bf 100644--- a/frontend/src/views/SettingWorkspaceSchemaReviewDetail.vue+++ b/frontend/src/views/SettingWorkspaceSchemaReviewDetail.vue@@ -4,15 +4,24 @@v-if="state.editMode":review-id="reviewPolicy.id":name="reviewPolicy.name"- :selected-environment="environment"+ :selected-environment="reviewPolicy.environment":selected-rule-list="selectedRuleList"@cancel="state.editMode = false"/><div class="my-5" v-else><div class="flex flex-col items-center justify-center md:flex-row">- <h1 class="text-xl md:text-3xl font-semibold flex-1">- {{ reviewPolicy.name }}- </h1>+ <div class="flex-1 flex space-x-3 items-center justify-start">+ <h1 class="text-xl md:text-3xl font-semibold">+ {{ reviewPolicy.name }}+ </h1>+ <div v-if="reviewPolicy.rowStatus == 'ARCHIVED'">+ <BBBadge+ :text="$t('common.disable')"+ :can-remove="false"+ :style="'WARN'"+ />+ </div>+ </div><buttonv-if="hasPermission"type="button"@@ -22,9 +31,12 @@{{ $t("common.edit") }}</button></div>- <div class="flex flex-wrap gap-x-3 my-5" v-if="environment">+ <div class="flex flex-wrap gap-x-3 my-5" v-if="reviewPolicy.environment"><span class="font-semibold">{{ $t("common.environment") }}</span>- <BBBadge :text="environment.name" :can-remove="false" />+ <BBBadge+ :text="environmentName(reviewPolicy.environment)"+ :can-remove="false"+ /></div><BBAttentionv-else@@ -150,7 +162,7 @@import { computed, reactive } from "vue";import { useI18n } from "vue-i18n";import { useRouter } from "vue-router";-import { idFromSlug, environmentName, isOwner, isDBA } from "../utils";+import { idFromSlug, environmentName, isOwner, isDBA } from "@/utils";import {RuleType,LEVEL_LIST,@@ -160,13 +172,11 @@ import {SchemaRuleEngineType,convertToCategoryList,ruleTemplateList,- Environment,convertPolicyRuleToRuleTemplate,-} from "../types";+} from "@/types";import {useCurrentUser,pushNotification,- useEnvironmentStore,useSchemaSystemStore,} from "@/store";import { CategoryFilterItem } from "../components/DatabaseSchemaReview/components/SchemaReviewCategoryTabFilter.vue";@@ -188,7 +198,6 @@ interface LocalState {const { t } = useI18n();const store = useSchemaSystemStore();-const envStore = useEnvironmentStore();const router = useRouter();const currentUser = useCurrentUser();const ROUTE_NAME = "setting.workspace.schema-review-policy";@@ -208,18 +217,9 @@ const hasPermission = computed(() => {});const reviewPolicy = computed((): DatabaseSchemaReviewPolicy => {- return store.getReviewPolicyById(idFromSlug(props.schemaReviewPolicySlug));-});--const environment = computed((): Environment | undefined => {- if (!reviewPolicy.value.environmentId) {- return;- }- const env = envStore.getEnvironmentById(reviewPolicy.value.environmentId);- return {- ...env,- name: environmentName(env),- };+ return store.getReviewPolicyByEnvironmentId(+ idFromSlug(props.schemaReviewPolicySlug)+ );});const ruleMap = ruleTemplateList.reduce((map, rule) => {@@ -346,13 +346,15 @@ const onEdit = () => {};const onArchive = () => {- store.updateReviewPolicy(reviewPolicy.value.id, {+ store.updateReviewPolicy({+ id: reviewPolicy.value.id,rowStatus: "ARCHIVED",});};const onRestore = () => {- store.updateReviewPolicy(reviewPolicy.value.id, {+ store.updateReviewPolicy({+ id: reviewPolicy.value.id,rowStatus: "NORMAL",});};