Skip to content

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

feat: add database resources selector in adding project member panel (#7469)

boojack7b01ec9927b8
diff --git a/frontend/src/components/Issue/panel/RequestExportPanel/ExportResourceForm/index.vue b/frontend/src/components/Issue/panel/RequestExportPanel/ExportResourceForm/index.vue
index 10550b4b02..a1cf761366 100644
--- a/frontend/src/components/Issue/panel/RequestExportPanel/ExportResourceForm/index.vue
+++ b/frontend/src/components/Issue/panel/RequestExportPanel/ExportResourceForm/index.vue
@@ -44,7 +44,8 @@
</template>
<script lang="ts" setup>
-import { computed, reactive, watch, watchEffect } from "vue";
+import { NRadioGroup, NRadio, NTooltip } from "naive-ui";
+import { computed, reactive, watch } from "vue";
import { useDatabaseV1Store, useProjectV1Store } from "@/store";
import {
DatabaseResource,
@@ -55,6 +56,7 @@ import {
import { Engine } from "@/types/proto/v1/common";
import { stringifyDatabaseResources } from "@/utils/issue/cel";
import DatabaseResourceSelector from "./DatabaseResourceSelector.vue";
+import MonacoEditor from "@/components/MonacoEditor/MonacoEditor.vue";
const props = defineProps<{
projectId?: string;
@@ -107,14 +109,6 @@ const dialect = computed((): SQLDialect => {
return dialectOfEngineV1(db?.instanceEntity.engine ?? Engine.MYSQL);
});
-// Prepare project entity.
-watchEffect(async () => {
- if (!props.projectId) {
- return;
- }
- await projectStore.getOrFetchProjectByUID(props.projectId);
-});
-
watch(
() => [state.exportMethod, state.statement, state.databaseResources],
() => {
@@ -138,6 +132,9 @@ watch(
}
emit("update:database-resources", state.databaseResources);
}
+ },
+ {
+ immediate: true,
}
);
diff --git a/frontend/src/components/Issue/panel/RequestQueryPanel/DatabaseResourceForm/DatabaseResourceSelector.vue b/frontend/src/components/Issue/panel/RequestQueryPanel/DatabaseResourceForm/DatabaseResourceSelector.vue
index 2f86569ca1..800c643952 100644
--- a/frontend/src/components/Issue/panel/RequestQueryPanel/DatabaseResourceForm/DatabaseResourceSelector.vue
+++ b/frontend/src/components/Issue/panel/RequestQueryPanel/DatabaseResourceForm/DatabaseResourceSelector.vue
@@ -1,9 +1,9 @@
<template>
- <div class="w-[60rem] space-y-2">
+ <div class="w-full space-y-2">
<NTransfer
v-if="!loading"
v-model:value="selectedValueList"
- style="height: calc(100vh - 380px)"
+ style="height: 512px"
:options="sourceTransferOptions"
:render-source-list="renderSourceList"
:render-target-list="renderTargetList"
diff --git a/frontend/src/components/Issue/panel/RequestQueryPanel/DatabaseResourceForm/index.vue b/frontend/src/components/Issue/panel/RequestQueryPanel/DatabaseResourceForm/index.vue
index 8323516de7..9a63b0c45f 100644
--- a/frontend/src/components/Issue/panel/RequestQueryPanel/DatabaseResourceForm/index.vue
+++ b/frontend/src/components/Issue/panel/RequestQueryPanel/DatabaseResourceForm/index.vue
@@ -35,7 +35,8 @@
</template>
<script lang="ts" setup>
-import { computed, reactive, watch, watchEffect } from "vue";
+import { NRadioGroup, NRadio, NTooltip } from "naive-ui";
+import { computed, reactive, watch } from "vue";
import { useProjectV1Store } from "@/store";
import { DatabaseResource } from "@/types";
import { stringifyDatabaseResources } from "@/utils/issue/cel";
@@ -71,14 +72,6 @@ const project = computed(() => {
: undefined;
});
-// Prepare project entity.
-watchEffect(async () => {
- if (!props.projectId) {
- return;
- }
- await projectStore.getOrFetchProjectByUID(props.projectId);
-});
-
const handleSelectedDatabaseResourceChanged = (
databaseResourceList: DatabaseResource[]
) => {
@@ -99,6 +92,9 @@ watch(
}
emit("update:database-resources", state.databaseResources);
}
+ },
+ {
+ immediate: true,
}
);
</script>
diff --git a/frontend/src/components/ProjectMember/AddProjectMember/AddProjectMemberForm.vue b/frontend/src/components/ProjectMember/AddProjectMember/AddProjectMemberForm.vue
index 49091a1503..94ffa20a77 100644
--- a/frontend/src/components/ProjectMember/AddProjectMember/AddProjectMemberForm.vue
+++ b/frontend/src/components/ProjectMember/AddProjectMember/AddProjectMemberForm.vue
@@ -22,6 +22,53 @@
<span>{{ $t("project.members.assign-role") }}</span>
<ProjectMemberRoleSelect v-model:role="state.role" class="mt-2" />
</div>
+
+ <div v-if="state.role === 'roles/QUERIER'" class="w-full">
+ <span class="block mb-2">{{ $t("common.databases") }}</span>
+ <QuerierDatabaseResourceForm
+ :project-id="project.uid"
+ :database-resources="state.databaseResources"
+ @update:condition="state.databaseResourceCondition = $event"
+ @update:database-resources="state.databaseResources = $event"
+ />
+ </div>
+ <template v-if="state.role === 'roles/EXPORTER'">
+ <div class="w-full">
+ <span class="block mb-2">{{ $t("common.database") }}</span>
+ <DatabaseSelect
+ class="!w-full"
+ :project="project.uid"
+ :database="state.databaseId"
+ @update:database="state.databaseId = $event"
+ />
+ </div>
+ <div class="w-full">
+ <span class="block mb-2">{{
+ $t("issue.grant-request.export-method")
+ }}</span>
+ <ExporterDatabaseResourceForm
+ class="w-full"
+ :project-id="project.uid"
+ :database-id="state.databaseId"
+ :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="mb-2">
+ {{ $t("issue.grant-request.export-rows") }}
+ </span>
+ <input
+ v-model="state.maxRowCount"
+ required
+ type="number"
+ class="textfield"
+ placeholder="Max row count"
+ />
+ </div>
+ </template>
+
<div class="w-full">
<span>{{ $t("common.expiration") }}</span>
<ExpirationSelector
@@ -38,14 +85,17 @@
/* eslint-disable vue/no-mutating-props */
import dayjs from "dayjs";
-import { computed, reactive, watch } from "vue";
+import { computed, nextTick, reactive, watch } from "vue";
import { useI18n } from "vue-i18n";
import { useUserStore } from "@/store";
-import { ComposedProject } from "@/types";
+import { ComposedProject, DatabaseResource } from "@/types";
import { Binding } from "@/types/proto/v1/iam_policy";
import { Expr } from "@/types/proto/google/type/expr";
import ProjectMemberRoleSelect from "@/components/v2/Select/ProjectMemberRoleSelect.vue";
import ExpirationSelector from "@/components/ExpirationSelector.vue";
+import QuerierDatabaseResourceForm from "@/components/Issue/panel/RequestQueryPanel/DatabaseResourceForm/index.vue";
+import ExporterDatabaseResourceForm from "@/components/Issue/panel/RequestExportPanel/ExportResourceForm/index.vue";
+import { DatabaseSelect } from "@/components/v2";
const props = defineProps<{
project: ComposedProject;
@@ -61,6 +111,12 @@ interface LocalState {
userUidList: string[];
role?: string;
expireDays: number;
+ // Querier and exporter options.
+ databaseResourceCondition?: string;
+ databaseResources?: DatabaseResource[];
+ // Exporter options.
+ maxRowCount: number;
+ databaseId?: string;
}
const { t } = useI18n();
@@ -68,38 +124,76 @@ const userStore = useUserStore();
const state = reactive<LocalState>({
userUidList: [],
expireDays: 7,
+ // Exporter options.
+ maxRowCount: 1000,
});
-const expireDaysOptions = computed(() => [
- {
- value: 7,
- label: t("common.date.days", { days: 7 }),
- },
- {
- value: 30,
- label: t("common.date.days", { days: 30 }),
- },
- {
- value: 60,
- label: t("common.date.days", { days: 60 }),
- },
- {
- value: 90,
- label: t("common.date.days", { days: 90 }),
- },
- {
- value: 180,
- label: t("common.date.months", { months: 6 }),
- },
- {
- value: 365,
- label: t("common.date.years", { years: 1 }),
+const expireDaysOptions = computed(() => {
+ if (state.role === "roles/EXPORTER") {
+ return [
+ {
+ value: 1,
+ label: t("common.date.days", { days: 1 }),
+ },
+ {
+ value: 3,
+ label: t("common.date.days", { days: 3 }),
+ },
+ {
+ value: 7,
+ label: t("common.date.days", { days: 7 }),
+ },
+ {
+ value: 15,
+ label: t("common.date.days", { days: 15 }),
+ },
+ ];
+ }
+ return [
+ {
+ value: 7,
+ label: t("common.date.days", { days: 7 }),
+ },
+ {
+ value: 30,
+ label: t("common.date.days", { days: 30 }),
+ },
+ {
+ value: 60,
+ label: t("common.date.days", { days: 60 }),
+ },
+ {
+ value: 90,
+ label: t("common.date.days", { days: 90 }),
+ },
+ {
+ value: 180,
+ label: t("common.date.months", { months: 6 }),
+ },
+ {
+ value: 365,
+ label: t("common.date.years", { years: 1 }),
+ },
+ {
+ value: 0,
+ label: t("project.members.never-expires"),
+ },
+ ];
+});
+
+watch(
+ () => state.role,
+ () => {
+ state.databaseResourceCondition = undefined;
+ state.databaseResources = undefined;
+ nextTick(() => {
+ state.expireDays = expireDaysOptions.value[0].value;
+ });
},
{
- value: 0,
- label: t("project.members.never-expires"),
- },
-]);
+ immediate: true,
+ }
+);
watch(
() => state,
@@ -113,14 +207,30 @@ watch(
if (state.role) {
props.binding.role = state.role;
}
- if (state.expireDays === 0) {
- props.binding.condition = undefined;
- } else {
- const days = state.expireDays;
+ const expression: string[] = [];
+ if (state.expireDays > 0) {
+ expression.push(
+ `request.time < timestamp("${dayjs()
+ .add(state.expireDays, "days")
+ .toISOString()}")`
+ );
+ }
+ if (state.role === "roles/QUERIER") {
+ if (state.databaseResourceCondition) {
+ expression.push(state.databaseResourceCondition);
+ }
+ }
+ if (state.role === "roles/EXPORTER") {
+ if (state.databaseResourceCondition) {
+ expression.push(state.databaseResourceCondition);
+ }
+ if (state.maxRowCount) {
+ expression.push(`request.rows_limit <= ${state.maxRowCount}`);
+ }
+ }
+ if (expression.length > 0) {
props.binding.condition = Expr.create({
- expression: `request.time < timestamp("${dayjs()
- .add(days, "days")
- .toISOString()}")`,
+ expression: expression.join(" && "),
});
}
},
diff --git a/frontend/src/components/ProjectMember/AddProjectMember/AddProjectMembersPanel.vue b/frontend/src/components/ProjectMember/AddProjectMember/AddProjectMembersPanel.vue
index d4cc38f3ab..5d56ac8d88 100644
--- a/frontend/src/components/ProjectMember/AddProjectMember/AddProjectMembersPanel.vue
+++ b/frontend/src/components/ProjectMember/AddProjectMember/AddProjectMembersPanel.vue
@@ -8,7 +8,7 @@
<NDrawerContent
:title="$t('project.members.add-member')"
:closable="true"
- class="w-[30rem] max-w-[100vw] relative"
+ class="w-[50rem] max-w-[100vw] relative"
>
<div
v-for="(binding, index) in state.bindings"
@@ -47,8 +47,8 @@
import { NDrawer, NDrawerContent, NButton } from "naive-ui";
import { ComposedProject } from "@/types";
import { Binding } from "@/types/proto/v1/iam_policy";
-import { computed, onMounted } from "vue";
-import { reactive } from "vue";
+import { computed, reactive } from "vue";
+import { useI18n } from "vue-i18n";
import AddProjectMemberForm from "./AddProjectMemberForm.vue";
import { cloneDeep } from "lodash-es";
import {
@@ -56,7 +56,6 @@ import {
useProjectIamPolicy,
useProjectIamPolicyStore,
} from "@/store";
-import { useI18n } from "vue-i18n";
const props = defineProps<{
project: ComposedProject;
@@ -72,7 +71,7 @@ interface LocalState {
const { t } = useI18n();
const state = reactive<LocalState>({
- bindings: [],
+ bindings: [Binding.fromPartial({})],
});
const projectResourceName = computed(() => props.project.name);
const { policy: iamPolicy } = useProjectIamPolicy(projectResourceName);
@@ -83,15 +82,12 @@ const filteredBindings = computed(() => {
const allowConfirm = computed(() => {
for (const binding of filteredBindings.value) {
+ // TODO: check the cel condition expression is valid for querier and exporter.
if (binding.members.length === 0 || binding.role === "") return false;
}
return true;
});
-onMounted(() => {
- state.bindings = [Binding.fromPartial({})];
-});
-
const handleAddMore = () => {
state.bindings.push(Binding.fromPartial({}));
};
diff --git a/frontend/src/components/v2/Select/DatabaseSelect.vue b/frontend/src/components/v2/Select/DatabaseSelect.vue
index b24eed4466..d36b9f88ee 100644
--- a/frontend/src/components/v2/Select/DatabaseSelect.vue
+++ b/frontend/src/components/v2/Select/DatabaseSelect.vue
@@ -7,6 +7,7 @@
:filter="filterByDatabaseName"
:filterable="true"
style="width: 12rem"
+ v-bind="$attrs"
@update:value="$emit('update:database', $event)"
/>
</template>