Skip to content

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

feat: show the schema review in the env page (#1167)

ecmadao0f82668c559f
diff --git a/frontend/src/components/EnvironmentForm.vue b/frontend/src/components/EnvironmentForm.vue
index 1b36342dd4..49d9eb02e0 100644
--- a/frontend/src/components/EnvironmentForm.vue
+++ b/frontend/src/components/EnvironmentForm.vue
@@ -128,6 +128,33 @@
</div>
</div>
</div>
+ <div class="col-span-1" v-if="!create && isDev()">
+ <label class="textlabel">
+ {{ $t("schema-review-policy.title") }}
+ </label>
+ <div class="mt-3">
+ <button
+ v-if="schemaReviewPolicy"
+ type="button"
+ class="text-sm font-medium text-accent hover:underline"
+ @click.prevent="onSchemaReviewPolicyClick"
+ >
+ {{ schemaReviewPolicy.name }}
+ </button>
+ <button
+ v-else-if="hasPermission"
+ type="button"
+ class="btn-normal py-2 px-4 gap-x-1 items-center"
+ @click.prevent="onSchemaReviewPolicyClick"
+ >
+ <heroicons-solid:plus class="h-4 w-4" />
+ {{ $t("schema-review-policy.add-review") }}
+ </button>
+ <span v-else class="textinfolabel">
+ {{ $t("schema-review-policy.no-policy-set") }}
+ </span>
+ </div>
+ </div>
</div>
<!-- Create button group -->
<div v-if="create" class="flex justify-end pt-5">
@@ -201,16 +228,29 @@
</template>
<script lang="ts">
-import { computed, reactive, PropType, watch, defineComponent } from "vue";
+import {
+ computed,
+ reactive,
+ PropType,
+ watch,
+ watchEffect,
+ defineComponent,
+} from "vue";
import { cloneDeep, isEqual, isEmpty } from "lodash-es";
+import { useRouter } from "vue-router";
import {
Environment,
EnvironmentCreate,
EnvironmentPatch,
Policy,
+ DatabaseSchemaReviewPolicy,
} from "../types";
-import { isDBAOrOwner } from "../utils";
-import { useCurrentUser, useEnvironmentList } from "@/store";
+import { isDev, isDBAOrOwner, schemaReviewPolicySlug } from "../utils";
+import {
+ useCurrentUser,
+ useEnvironmentList,
+ useSchemaSystemStore,
+} from "@/store";
interface LocalState {
environment: Environment | EnvironmentCreate;
@@ -218,6 +258,8 @@ interface LocalState {
backupPolicy: Policy;
}
+const ROUTE_NAME = "setting.workspace.schema-review-policy";
+
export default defineComponent({
name: "EnvironmentForm",
props: {
@@ -246,6 +288,57 @@ export default defineComponent({
backupPolicy: cloneDeep(props.backupPolicy),
});
+ const router = useRouter();
+ const schemaSystemStore = useSchemaSystemStore();
+
+ const environmentId = computed(() => {
+ if (props.create) {
+ return;
+ }
+ return (props.environment as Environment).id;
+ });
+
+ const prepareSchemaReviewPolicy = () => {
+ if (!environmentId.value) {
+ return;
+ }
+ return schemaSystemStore.fetchReviewPolicyByEnvironmentId(
+ environmentId.value
+ );
+ };
+ watchEffect(prepareSchemaReviewPolicy);
+
+ const schemaReviewPolicy = computed(
+ (): DatabaseSchemaReviewPolicy | undefined => {
+ if (!environmentId.value) {
+ return;
+ }
+ return schemaSystemStore.getReviewPolicyByEnvironmentId(
+ environmentId.value
+ );
+ }
+ );
+
+ const onSchemaReviewPolicyClick = () => {
+ if (schemaReviewPolicy.value) {
+ router.push({
+ name: `${ROUTE_NAME}.detail`,
+ params: {
+ schemaReviewPolicySlug: schemaReviewPolicySlug(
+ schemaReviewPolicy.value
+ ),
+ },
+ });
+ } else {
+ router.push({
+ name: `${ROUTE_NAME}.create`,
+ query: {
+ environmentId: environmentId.value,
+ },
+ });
+ }
+ };
+
watch(
() => props.environment,
(cur: Environment | EnvironmentCreate) => {
@@ -271,19 +364,23 @@ export default defineComponent({
const environmentList = useEnvironmentList();
+ const hasPermission = computed(() => {
+ return isDBAOrOwner(currentUser.value.role);
+ });
+
const allowArchive = computed(() => {
return allowEdit.value && environmentList.value.length > 1;
});
const allowRestore = computed(() => {
- return isDBAOrOwner(currentUser.value.role);
+ return hasPermission.value;
});
const allowEdit = computed(() => {
return (
props.create ||
((state.environment as Environment).rowStatus == "NORMAL" &&
- isDBAOrOwner(currentUser.value.role))
+ hasPermission.value)
);
});
@@ -348,17 +445,21 @@ export default defineComponent({
};
return {
+ isDev,
state,
allowArchive,
allowRestore,
allowEdit,
valueChanged,
allowCreate,
+ hasPermission,
revertEnvironment,
createEnvironment,
updateEnvironment,
archiveEnvironment,
restoreEnvironment,
+ schemaReviewPolicy,
+ onSchemaReviewPolicyClick,
};
},
});
diff --git a/frontend/src/router/index.ts b/frontend/src/router/index.ts
index 0a1912e621..319274760d 100644
--- a/frontend/src/router/index.ts
+++ b/frontend/src/router/index.ts
@@ -411,9 +411,11 @@ const routes: Array<RouteRecordRaw> = [
meta: {
title: (route: RouteLocationNormalized) => {
const slug = route.params.schemaReviewPolicySlug as string;
- return useSchemaSystemStore().getReviewPolicyByEnvironmentId(
- idFromSlug(slug)
- ).name;
+ return (
+ useSchemaSystemStore().getReviewPolicyByEnvironmentId(
+ idFromSlug(slug)
+ )?.name ?? ""
+ );
},
},
component: () =>
diff --git a/frontend/src/store/modules/schemaSystem.ts b/frontend/src/store/modules/schemaSystem.ts
index b61fed17aa..703b6be71c 100644
--- a/frontend/src/store/modules/schemaSystem.ts
+++ b/frontend/src/store/modules/schemaSystem.ts
@@ -23,6 +23,10 @@ const convertToSchemaReviewPolicy = (
return;
}
const payload = policy.payload as SchemaReviewPolicyPayload;
+ if (!Array.isArray(payload.ruleList) || !payload.name) {
+ return;
+ }
+
const ruleList = payload.ruleList.map((r) => {
const rule: SchemaPolicyRule = {
type: r.type,
@@ -194,14 +198,13 @@ export const useSchemaSystemStore = defineStore("schemaSystem", {
},
getReviewPolicyByEnvironmentId(
environmentId: EnvironmentId
- ): DatabaseSchemaReviewPolicy {
+ ): DatabaseSchemaReviewPolicy | undefined {
if (environmentId === EMPTY_ID) {
return empty("SCHEMA_REVIEW") as DatabaseSchemaReviewPolicy;
}
- return (
- this.reviewPolicyList.find((g) => g.environment.id === environmentId) ||
- (unknown("SCHEMA_REVIEW") as DatabaseSchemaReviewPolicy)
+ return this.reviewPolicyList.find(
+ (g) => g.environment.id === environmentId
);
},
@@ -230,6 +233,9 @@ export const useSchemaSystemStore = defineStore("schemaSystem", {
type: "bb.policy.schema-review",
});
+ if (!policy) {
+ return;
+ }
const reviewPolicy = convertToSchemaReviewPolicy(policy);
if (reviewPolicy) {
this.setReviewPolicy(reviewPolicy);
diff --git a/frontend/src/views/SettingWorkspaceSchemaReview.vue b/frontend/src/views/SettingWorkspaceSchemaReview.vue
index 60bae5dfd4..9b6d35b86a 100644
--- a/frontend/src/views/SettingWorkspaceSchemaReview.vue
+++ b/frontend/src/views/SettingWorkspaceSchemaReview.vue
@@ -34,7 +34,7 @@ import {
useCurrentUser,
} from "@/store";
import { DatabaseSchemaReviewPolicy } from "@/types/schemaSystem";
-import { schemaReviewPolicySlug, isOwner, isDBA } from "@/utils";
+import { schemaReviewPolicySlug, isDBAOrOwner } from "@/utils";
const router = useRouter();
const store = useSchemaSystemStore();
@@ -47,7 +47,7 @@ watchEffect(() => {
});
const hasPermission = computed(() => {
- return isOwner(currentUser.value.role) || isDBA(currentUser.value.role);
+ return isDBAOrOwner(currentUser.value.role);
});
const goToCreationView = () => {
diff --git a/frontend/src/views/SettingWorkspaceSchemaReviewCreate.vue b/frontend/src/views/SettingWorkspaceSchemaReviewCreate.vue
index 88a4ba7094..78a2b342af 100644
--- a/frontend/src/views/SettingWorkspaceSchemaReviewCreate.vue
+++ b/frontend/src/views/SettingWorkspaceSchemaReviewCreate.vue
@@ -1,5 +1,24 @@
<template>
<div class="my-4 space-y-4 divide-y divide-block-border">
- <SchemaReviewCreation :selected-rule-list="[]" />
+ <SchemaReviewCreation
+ :selected-rule-list="[]"
+ :selected-environment="environment"
+ />
</div>
</template>
+
+<script lang="ts" setup>
+import { computed } from "vue";
+import { useEnvironmentStore } from "@/store";
+
+const url = new URL(window.location.href);
+const params = new URLSearchParams(url.search);
+const environmentId = params.get("environmentId") ?? "";
+
+const environment = computed(() => {
+ if (Number.isNaN(environmentId)) {
+ return;
+ }
+ return useEnvironmentStore().getEnvironmentById(parseInt(environmentId, 10));
+});
+</script>
diff --git a/frontend/src/views/SettingWorkspaceSchemaReviewDetail.vue b/frontend/src/views/SettingWorkspaceSchemaReviewDetail.vue
index 63b43fa5bf..6711757ce4 100644
--- a/frontend/src/views/SettingWorkspaceSchemaReviewDetail.vue
+++ b/frontend/src/views/SettingWorkspaceSchemaReviewDetail.vue
@@ -162,8 +162,9 @@
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, isDBAOrOwner } from "@/utils";
import {
+ unknown,
RuleType,
LEVEL_LIST,
RuleLevel,
@@ -213,12 +214,14 @@ const state = reactive<LocalState>({
});
const hasPermission = computed(() => {
- return isOwner(currentUser.value.role) || isDBA(currentUser.value.role);
+ return isDBAOrOwner(currentUser.value.role);
});
const reviewPolicy = computed((): DatabaseSchemaReviewPolicy => {
- return store.getReviewPolicyByEnvironmentId(
- idFromSlug(props.schemaReviewPolicySlug)
+ return (
+ store.getReviewPolicyByEnvironmentId(
+ idFromSlug(props.schemaReviewPolicySlug)
+ ) || (unknown("SCHEMA_REVIEW") as DatabaseSchemaReviewPolicy)
);
});