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: extract database resources select form from requesting querier (#7453)
boojack736b1cf89671
diff --git a/frontend/src/components/Issue/panel/RequestQueryPanel/SelectDatabaseResourceForm/index.vue b/frontend/src/components/Issue/panel/RequestQueryPanel/DatabaseResourceForm/DatabaseResourceSelector.vuesimilarity index 74%rename from frontend/src/components/Issue/panel/RequestQueryPanel/SelectDatabaseResourceForm/index.vuerename to frontend/src/components/Issue/panel/RequestQueryPanel/DatabaseResourceForm/DatabaseResourceSelector.vueindex 8fb383e8fd..b4172b7379 100644--- a/frontend/src/components/Issue/panel/RequestQueryPanel/SelectDatabaseResourceForm/index.vue+++ b/frontend/src/components/Issue/panel/RequestQueryPanel/DatabaseResourceForm/DatabaseResourceSelector.vue@@ -15,26 +15,26 @@</template><script setup lang="ts">-import { computed, h, onMounted, ref, watch } from "vue";import {NTransfer,TransferRenderSourceList,NTree,TreeOption,} from "naive-ui";+import { computed, h, ref, watch } from "vue";import {useDatabaseV1Store,useDBSchemaV1Store,useProjectV1Store,} from "@/store";+import { DatabaseResource } from "@/types";import {flattenTreeOptions,mapTreeOptions,DatabaseTreeOption,} from "./common";import Label from "./Label.vue";-import { DatabaseResource } from "@/types";const props = defineProps<{projectId: string;@@ -66,41 +66,57 @@ const selectedValueList = ref<string[]>(const databaseResourceMap = ref<Map<string, DatabaseResource>>(new Map());const loading = ref(false);-onMounted(async () => {- const project = await useProjectV1Store().getOrFetchProjectByUID(- props.projectId- );- const databaseList = await databaseStore.fetchDatabaseList({- parent: "instances/-",- filter: `project == "${project.name}"`,- });-- for (const database of databaseList) {- const databaseMetadata = await dbSchemaStore.getOrFetchDatabaseMetadata(- database.name+// Fetch database list when projectId changed.+watch(+ () => props.projectId,+ async () => {+ loading.value = true;+ const project = await useProjectV1Store().getOrFetchProjectByUID(+ props.projectId);- databaseResourceMap.value.set(`d-${database.uid}`, {- databaseName: database.name,+ const databaseList = await databaseStore.fetchDatabaseList({+ parent: "instances/-",+ filter: `project == "${project.name}"`,});- for (const schema of databaseMetadata.schemas) {- databaseResourceMap.value.set(`s-${database.uid}-${schema.name}`, {++ for (const database of databaseList) {+ const databaseMetadata = await dbSchemaStore.getOrFetchDatabaseMetadata(+ database.name+ );+ databaseResourceMap.value.set(`d-${database.uid}`, {databaseName: database.name,- schema: schema.name,});- for (const table of schema.tables) {- databaseResourceMap.value.set(- `t-${database.uid}-${schema.name}-${table.name}`,- {- databaseName: database.name,- schema: schema.name,- table: table.name,- }- );+ for (const schema of databaseMetadata.schemas) {+ databaseResourceMap.value.set(`s-${database.uid}-${schema.name}`, {+ databaseName: database.name,+ schema: schema.name,+ });+ for (const table of schema.tables) {+ databaseResourceMap.value.set(+ `t-${database.uid}-${schema.name}-${table.name}`,+ {+ databaseName: database.name,+ schema: schema.name,+ table: table.name,+ }+ );+ }}}+ loading.value = false;+ },+ {+ immediate: true,}- loading.value = false;-});+);++// Clear selectedValueList when projectId changed.+watch(+ () => props.projectId,+ () => {+ selectedValueList.value = [];+ }+);const databaseList = computed(() => {const project = useProjectV1Store().getProjectByUID(props.projectId);diff --git a/frontend/src/components/Issue/panel/RequestQueryPanel/SelectDatabaseResourceForm/Label.vue b/frontend/src/components/Issue/panel/RequestQueryPanel/DatabaseResourceForm/Label.vuesimilarity index 100%rename from frontend/src/components/Issue/panel/RequestQueryPanel/SelectDatabaseResourceForm/Label.vuerename to frontend/src/components/Issue/panel/RequestQueryPanel/DatabaseResourceForm/Label.vuediff --git a/frontend/src/components/Issue/panel/RequestQueryPanel/SelectDatabaseResourceForm/common.ts b/frontend/src/components/Issue/panel/RequestQueryPanel/DatabaseResourceForm/common.tssimilarity index 100%rename from frontend/src/components/Issue/panel/RequestQueryPanel/SelectDatabaseResourceForm/common.tsrename to frontend/src/components/Issue/panel/RequestQueryPanel/DatabaseResourceForm/common.tsdiff --git a/frontend/src/components/Issue/panel/RequestQueryPanel/DatabaseResourceForm/index.vue b/frontend/src/components/Issue/panel/RequestQueryPanel/DatabaseResourceForm/index.vuenew file mode 100644index 0000000000..f4c1cca0f8--- /dev/null+++ b/frontend/src/components/Issue/panel/RequestQueryPanel/DatabaseResourceForm/index.vue@@ -0,0 +1,106 @@+<template>+ <div class="w-full mb-2">+ <NRadioGroup+ v-model:value="state.allDatabases"+ class="w-full !flex flex-row justify-start items-center gap-4"+ >+ <NTooltip trigger="hover">+ <template #trigger>+ <NRadio+ :value="true"+ :label="$t('issue.grant-request.all-databases')"+ />+ </template>+ {{ $t("issue.grant-request.all-databases-tip") }}+ </NTooltip>+ <NRadio+ class="!leading-6"+ :value="false"+ :disabled="!project"+ :label="$t('issue.grant-request.manually-select')"+ />+ </NRadioGroup>+ </div>+ <div+ v-if="!state.allDatabases"+ class="w-full flex flex-row justify-start items-center"+ >+ <DatabaseResourceSelector+ v-if="project"+ :project-id="project.uid"+ :selected-database-resource-list="state.selectedDatabaseResourceList"+ @update="handleSelectedDatabaseResourceChanged"+ />+ </div>+</template>++<script lang="ts" setup>+import { computed, reactive, watch, watchEffect } from "vue";+import { useProjectV1Store } from "@/store";+import { DatabaseResource } from "@/types";+import { stringifyDatabaseResources } from "@/utils/issue/cel";+import DatabaseResourceSelector from "./DatabaseResourceSelector.vue";++interface LocalState {+ allDatabases: boolean;+ selectedDatabaseResourceList: DatabaseResource[];+}++const props = defineProps<{+ projectId?: string;+ databaseResources?: DatabaseResource[];+}>();++const emit = defineEmits<{+ (event: "update:condition", value?: string): void;+ (+ event: "update:database-resources",+ databaseResources: DatabaseResource[]+ ): void;+}>();++const projectStore = useProjectV1Store();+const state = reactive<LocalState>({+ allDatabases: (props.databaseResources || []).length === 0,+ selectedDatabaseResourceList: props.databaseResources || [],+});++const project = computed(() => {+ return props.projectId+ ? projectStore.getProjectByUID(props.projectId)+ : undefined;+});++// Prepare project entity.+watchEffect(async () => {+ if (!props.projectId) {+ return;+ }+ await projectStore.getOrFetchProjectByUID(props.projectId);+});++const handleSelectedDatabaseResourceChanged = (+ databaseResourceList: DatabaseResource[]+) => {+ state.selectedDatabaseResourceList = databaseResourceList;+};++watch(+ () => [state.allDatabases, state.selectedDatabaseResourceList],+ () => {+ if (state.allDatabases) {+ emit("update:condition", "");+ } else {+ if (state.selectedDatabaseResourceList.length === 0) {+ emit("update:condition", undefined);+ } else {+ const condition = stringifyDatabaseResources(+ state.selectedDatabaseResourceList+ );+ emit("update:condition", condition);+ }+ emit("update:database-resources", state.selectedDatabaseResourceList);+ }+ }+);+</script>diff --git a/frontend/src/components/Issue/panel/RequestQueryPanel/index.vue b/frontend/src/components/Issue/panel/RequestQueryPanel/index.vueindex c75d4b9312..2e9ee7b80e 100644--- a/frontend/src/components/Issue/panel/RequestQueryPanel/index.vue+++ b/frontend/src/components/Issue/panel/RequestQueryPanel/index.vue@@ -28,42 +28,12 @@{{ $t("common.databases") }}<RequiredStar /></span>- <div class="w-full mb-2">- <NRadioGroup- v-model:value="state.allDatabases"- class="w-full !flex flex-row justify-start items-center gap-4"- name="export-method"- >- <NTooltip trigger="hover">- <template #trigger>- <NRadio- :value="true"- :label="$t('issue.grant-request.all-databases')"- />- </template>- {{ $t("issue.grant-request.all-databases-tip") }}- </NTooltip>- <NRadio- class="!leading-6"- :value="false"- :disabled="!state.projectId"- :label="$t('issue.grant-request.manually-select')"- />- </NRadioGroup>- </div>- <div- v-if="!state.allDatabases"- class="w-full flex flex-row justify-start items-center"- >- <SelectDatabaseResourceForm- v-if="state.projectId"- :project-id="state.projectId"- :selected-database-resource-list="- state.selectedDatabaseResourceList- "- @update="handleSelectedDatabaseResourceChanged"- />- </div>+ <DatabaseResourceForm+ :project-id="state.projectId"+ :database-resources="state.databaseResources"+ @update:condition="state.databaseResourceCondition = $event"+ @update:database-resources="state.databaseResources = $event"+ /></div><div class="w-full flex flex-col justify-start items-start"><span class="flex items-start textlabel mb-4">@@ -105,16 +75,12 @@</template><script lang="ts" setup>-import {- NDrawer,- NDrawerContent,- NRadioGroup,- NRadio,- NInput,- NTooltip,-} from "naive-ui";+import dayjs from "dayjs";+import { head, isUndefined, uniq } from "lodash-es";+import { NDrawer, NDrawerContent, NInput } from "naive-ui";import { computed, reactive } from "vue";import { useI18n } from "vue-i18n";+import { useRouter } from "vue-router";import {ComposedDatabase,DatabaseResource,@@ -131,17 +97,13 @@ import {useProjectV1Store,} from "@/store";import RequiredStar from "@/components/RequiredStar.vue";-import { head, uniq } from "lodash-es";-import { useRouter } from "vue-router";-import dayjs from "dayjs";-import { stringifyDatabaseResources } from "@/utils/issue/cel";-import SelectDatabaseResourceForm from "./SelectDatabaseResourceForm/index.vue";+import DatabaseResourceForm from "./DatabaseResourceForm/index.vue";import ExpirationSelector from "@/components/ExpirationSelector.vue";interface LocalState {projectId?: string;- allDatabases: boolean;- selectedDatabaseResourceList: DatabaseResource[];+ databaseResourceCondition?: string;+ databaseResources: DatabaseResource[];expireDays: number;description: string;}@@ -155,20 +117,18 @@ defineEmits<{(event: "close"): void;}>();-const extractDatabaseResourceFromProps = (): Pick<+const extractDatabaseResourcesFromProps = (): Pick<LocalState,- "allDatabases" | "selectedDatabaseResourceList"+ "databaseResources"> => {const { database } = props;if (!database || database.uid === String(UNKNOWN_ID)) {return {- allDatabases: true,- selectedDatabaseResourceList: [],+ databaseResources: [],};}return {- allDatabases: false,- selectedDatabaseResourceList: [+ databaseResources: [{databaseName: database.name,},@@ -182,7 +142,7 @@ const databaseStore = useDatabaseV1Store();const currentUser = useCurrentUserV1();const state = reactive<LocalState>({projectId: props.projectId,- ...extractDatabaseResourceFromProps(),+ ...extractDatabaseResourcesFromProps(),expireDays: 7,description: "",});@@ -219,8 +179,11 @@ const allowCreate = computed(() => {return false;}- if (!state.allDatabases) {- return state.selectedDatabaseResourceList.length > 0;+ // If all database selected, the condition is an empty string.+ // If some databases selected, the condition is a string.+ // If no database selected, the condition is undefined.+ if (isUndefined(state.databaseResourceCondition)) {+ return false;}return true;});@@ -229,12 +192,6 @@ const handleProjectSelect = async (projectId: string) => {state.projectId = projectId;};-const handleSelectedDatabaseResourceChanged = (- databaseResourceList: DatabaseResource[]-) => {- state.selectedDatabaseResourceList = databaseResourceList;-};-const doCreateIssue = async () => {if (!allowCreate.value) {return;@@ -271,9 +228,8 @@ const doCreateIssue = async () => {.add(expireDays, "days").toISOString()}")`);- if (!state.allDatabases) {- const cel = stringifyDatabaseResources(state.selectedDatabaseResourceList);- expression.push(cel);+ if (state.databaseResourceCondition) {+ expression.push(state.databaseResourceCondition);}const celExpressionString = expression.join(" && ");@@ -297,11 +253,11 @@ const generateIssueName = () => {throw new Error("No project selected");}- if (state.allDatabases) {+ if (state.databaseResources.length === 0) {return `Request query for all database`;} else {const databaseNames = uniq(- state.selectedDatabaseResourceList.map(+ state.databaseResources.map((databaseResource) => databaseResource.databaseName));diff --git a/frontend/src/components/ProjectMember/ProjectMemberTable/ProjectMemberTable.vue b/frontend/src/components/ProjectMember/ProjectMemberTable/ProjectMemberTable.vueindex 50274b7649..b617dec4b8 100644--- a/frontend/src/components/ProjectMember/ProjectMemberTable/ProjectMemberTable.vue+++ b/frontend/src/components/ProjectMember/ProjectMemberTable/ProjectMemberTable.vue@@ -55,7 +55,10 @@<template v-if="isBindingExpired(binding)" #avatar><RoleExpiredTip /></template>- {{ displayRoleTitle(binding.role) }}+ <span>{{ displayRoleTitle(binding.role) }}</span>+ <span v-if="getBindingConditionTitle(binding)" class="ml-0.5">+ ({{ getBindingConditionTitle(binding) }})+ </span></NTag></div><div class="bb-grid-cell gap-x-2 justify-end">@@ -112,6 +115,7 @@ import ProjectMemberRolePanel from "./ProjectMemberRolePanel.vue";import { ComposedProjectMember } from "./types";import UserAvatar from "@/components/User/UserAvatar.vue";import { convertFromExpr } from "@/utils/issue/cel";+import { getBindingConditionTitle } from "../common/util";export type ProjectMemberRow = BBGridRow<ComposedProjectMember>;diff --git a/frontend/src/components/ProjectMember/common/util.ts b/frontend/src/components/ProjectMember/common/util.tsnew file mode 100644index 0000000000..4da60e3204--- /dev/null+++ b/frontend/src/components/ProjectMember/common/util.ts@@ -0,0 +1,5 @@+import { Binding } from "@/types/proto/v1/iam_policy";++export const getBindingConditionTitle = (binding: Binding): string => {+ return binding.condition?.title || "";+};