Skip to content

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

chore: optimize database resource selector (#14150)

ecmadao9cdb19b1f4dc
diff --git a/frontend/src/components/GrantRequestPanel/DatabaseResourceForm/DatabaseResourceSelector.vue b/frontend/src/components/GrantRequestPanel/DatabaseResourceForm/DatabaseResourceSelector.vue
index 3f7a48ff35..19ced986df 100644
--- a/frontend/src/components/GrantRequestPanel/DatabaseResourceForm/DatabaseResourceSelector.vue
+++ b/frontend/src/components/GrantRequestPanel/DatabaseResourceForm/DatabaseResourceSelector.vue
@@ -43,11 +43,15 @@ import {
const props = defineProps<{
projectName: string;
+ includeCloumn: boolean;
databaseResources: DatabaseResource[];
}>();
const emit = defineEmits<{
- (e: "update", databaseResourceList: DatabaseResource[]): void;
+ (
+ e: "update:databaseResources",
+ databaseResourceList: DatabaseResource[]
+ ): void;
}>();
const databaseStore = useDatabaseV1Store();
@@ -79,23 +83,49 @@ onMounted(async () => {
});
})
);
+
defaultExpandedKeys.value = selectedValueList.value
.map((key) => {
- if (key.includes("/tables/")) {
- const schemaName = key.split("/tables/")[0];
- const databaseName = schemaName.split("/schemas/")[0];
- return [databaseName, schemaName];
- } else if (key.includes("/schemas/")) {
- const databaseName = key.split("/schemas/")[0];
- return [databaseName];
- } else {
- return [];
- }
+ const pathes = parseKeyToPathes(key);
+ // key: {db}/schemas/{schema}
+ // expaned: [{db}]
+ //
+ // key: {db}/schemas/{schema}/tables/{table}
+ // expaned: [{db}, {db}/schemas/{schema}]
+ //
+ // key: {db}/schemas/{schema}/tables/{table}/columns/{column}
+ // expaned: [{db}, {db}/schemas/{schema}, {db}/schemas/{schema}/tables/{table}]
+ pathes.pop();
+ return pathes;
})
.flat();
loading.value = false;
});
+const parseKeyToPathes = (key: string): string[] => {
+ if (!key) {
+ return [];
+ }
+
+ const sections = key.split("/");
+ const nodePrefx = new Set(["schemas", "tables", "columns"]);
+ const resp: string[] = [];
+ const tmp: string[] = [];
+
+ for (const section of sections) {
+ if (nodePrefx.has(section)) {
+ resp.push(tmp.join("/"));
+ }
+ tmp.push(section);
+ }
+
+ if (tmp.length > 0) {
+ resp.push(tmp.join("/"));
+ }
+
+ return resp;
+};
+
const databaseList = computed(() => {
const list = orderBy(
databaseStore.databaseListByProject(project.value.name),
@@ -111,7 +141,10 @@ const databaseList = computed(() => {
});
const sourceTreeOptions = computed(() => {
- return mapTreeOptions(databaseList.value);
+ return mapTreeOptions({
+ databaseList: databaseList.value,
+ includeCloumn: props.includeCloumn,
+ });
});
const sourceTransferOptions = computed(() => {
@@ -147,7 +180,10 @@ const renderSourceList: TransferRenderSourceList = ({ onCheck, pattern }) => {
view: DatabaseMetadataView.DATABASE_METADATA_VIEW_BASIC,
});
const database = databaseStore.getDatabaseByName(treeNode.value);
- const children = getSchemaOrTableTreeOptions(database);
+ const children = getSchemaOrTableTreeOptions({
+ database,
+ includeCloumn: props.includeCloumn,
+ });
if (children && children.length > 0) {
treeNode.children = children;
treeNode.isLeaf = false;
@@ -166,28 +202,26 @@ const targetTreeOptions = computed(() => {
if (selectedValueList.value.length === 0) {
return [];
}
- const nodes = mapTreeOptions(databaseList.value, selectedValueList.value);
+
+ const nodes = mapTreeOptions({
+ databaseList: databaseList.value,
+ filterValueList: selectedValueList.value,
+ includeCloumn: props.includeCloumn,
+ });
+
for (const databaseNode of nodes) {
if (!databaseNode.children || databaseNode.children.length === 0) {
databaseNode.isLeaf = true;
- continue;
- } else {
- for (const childNode of databaseNode.children) {
- if (!childNode.children || childNode.children.length === 0) {
- childNode.isLeaf = true;
- }
- }
}
}
return nodes;
});
-const renderTargetList: TransferRenderSourceList = ({ onCheck }) => {
+const renderTargetList: TransferRenderSourceList = () => {
return h(NTree, {
keyField: "value",
- checkable: true,
+ checkable: false,
selectable: false,
- checkOnClick: true,
defaultExpandAll: true,
data: targetTreeOptions.value,
blockLine: true,
@@ -200,27 +234,37 @@ const renderTargetList: TransferRenderSourceList = ({ onCheck }) => {
},
showIrrelevantNodes: false,
checkedKeys: selectedValueList.value,
- onUpdateCheckedKeys: (checkedKeys: string[]) => {
- onCheck(checkedKeys);
- },
});
};
-watch(selectedValueList, () => {
+watch(selectedValueList, (selectedValueList) => {
+ const orderedList = orderBy(selectedValueList, (item) => item.length, "asc");
+ const filteredKeyList: string[] = [];
+ for (const key of orderedList) {
+ const parentExisted = filteredKeyList.some((parent) =>
+ key.startsWith(`${parent}/`)
+ );
+ if (!parentExisted) {
+ filteredKeyList.push(key);
+ }
+ }
+
emit(
- "update",
- selectedValueList.value.map((key) => {
+ "update:databaseResources",
+ filteredKeyList.map((key) => {
const [databaseName, schemaAndTable] = key.split("/schemas/");
const databaseResource: DatabaseResource = {
databaseName,
};
if (schemaAndTable) {
- const [schema, table] = schemaAndTable.split("/tables/");
- if (table) {
- databaseResource.schema = schema;
+ const [schema, tableAndColumn] = schemaAndTable.split("/tables/");
+ databaseResource.schema = schema;
+ if (tableAndColumn) {
+ const [table, column] = tableAndColumn.split("/columns/");
databaseResource.table = table;
- } else {
- databaseResource.schema = schema;
+ if (column) {
+ databaseResource.column = column;
+ }
}
}
return databaseResource;
diff --git a/frontend/src/components/GrantRequestPanel/DatabaseResourceForm/common.ts b/frontend/src/components/GrantRequestPanel/DatabaseResourceForm/common.ts
index cd0dba9d85..e5f43b2b94 100644
--- a/frontend/src/components/GrantRequestPanel/DatabaseResourceForm/common.ts
+++ b/frontend/src/components/GrantRequestPanel/DatabaseResourceForm/common.ts
@@ -1,19 +1,27 @@
-import { flatten } from "lodash-es";
+import { flatten, isUndefined } from "lodash-es";
import type { TransferOption, TreeOption } from "naive-ui";
import { useDBSchemaV1Store } from "@/store";
import type { ComposedDatabase } from "@/types";
+import type { TableMetadata } from "@/types/proto/v1/database_service";
import { hasSchemaProperty } from "@/utils";
-export interface DatabaseTreeOption<L = "database" | "schema" | "table">
- extends TreeOption {
+export interface DatabaseTreeOption<
+ L = "database" | "schema" | "table" | "column",
+> extends TreeOption {
level: L;
value: string;
+ children?: DatabaseTreeOption[];
}
-export const mapTreeOptions = (
- databaseList: ComposedDatabase[],
- filterValueList?: string[]
-) => {
+export const mapTreeOptions = ({
+ databaseList,
+ filterValueList,
+ includeCloumn,
+}: {
+ databaseList: ComposedDatabase[];
+ filterValueList?: string[];
+ includeCloumn: boolean;
+}) => {
const databaseNodes: DatabaseTreeOption<"database">[] = [];
const filteredDatabaseList = filterValueList
? databaseList.filter((database) =>
@@ -28,31 +36,77 @@ export const mapTreeOptions = (
value: database.name,
label: database.databaseName,
isLeaf: false,
+ children: getSchemaOrTableTreeOptions({
+ database,
+ filterValueList,
+ includeCloumn,
+ }),
};
- databaseNodes.push(databaseNode);
-
- const childrenNodes = getSchemaOrTableTreeOptions(
- database,
- filterValueList
- );
- if (!childrenNodes) {
- continue;
+ if (!isUndefined(databaseNode.children)) {
+ databaseNode.isLeaf = databaseNode.children.length === 0;
}
- if (childrenNodes.length > 0) {
- databaseNode.children = childrenNodes;
- databaseNode.isLeaf = false;
- } else {
- databaseNode.isLeaf = true;
- }
+ databaseNodes.push(databaseNode);
}
return databaseNodes;
};
-export const getSchemaOrTableTreeOptions = (
- database: ComposedDatabase,
- filterValueList?: string[]
-) => {
+const getTableTreeOptions = ({
+ prefix,
+ tableList,
+ filterValueList,
+ includeCloumn,
+}: {
+ prefix: string;
+ tableList: TableMetadata[];
+ filterValueList?: string[];
+ includeCloumn: boolean;
+}): DatabaseTreeOption<"table">[] => {
+ const tableNodes = tableList.map((table): DatabaseTreeOption<"table"> => {
+ const option: DatabaseTreeOption<"table"> = {
+ level: "table",
+ value: `${prefix}/tables/${table.name}`,
+ label: table.name,
+ isLeaf: true,
+ };
+ if (includeCloumn) {
+ option.children = table.columns.map(
+ (column): DatabaseTreeOption<"column"> => ({
+ level: "column",
+ value: `${option.value}/columns/${column.name}`,
+ label: column.name,
+ isLeaf: true,
+ })
+ );
+ if (filterValueList) {
+ option.children = option.children.filter((node) =>
+ filterValueList.includes(node.value)
+ );
+ }
+ }
+ if (option.children && option.children.length > 0) {
+ option.isLeaf = false;
+ }
+ return option;
+ });
+ return filterValueList
+ ? tableNodes.filter((node) =>
+ filterValueList.some(
+ (value) => value.split("/columns/")[0] === node.value
+ )
+ )
+ : tableNodes;
+};
+
+export const getSchemaOrTableTreeOptions = ({
+ database,
+ filterValueList,
+ includeCloumn,
+}: {
+ database: ComposedDatabase;
+ filterValueList?: string[];
+ includeCloumn: boolean;
+}) => {
const dbSchemaStore = useDBSchemaV1Store();
const databaseMetadata = dbSchemaStore.getDatabaseMetadataWithoutDefault(
database.name
@@ -63,24 +117,21 @@ export const getSchemaOrTableTreeOptions = (
if (hasSchemaProperty(database.instanceResource.engine)) {
const schemaNodes = databaseMetadata.schemas.map(
(schema): DatabaseTreeOption<"schema"> => {
+ const value = `${database.name}/schemas/${schema.name}`;
const schemaNode: DatabaseTreeOption<"schema"> = {
level: "schema",
- value: `${database.name}/schemas/${schema.name}`,
+ value,
label: schema.name,
+ children: getTableTreeOptions({
+ prefix: value,
+ tableList: schema.tables,
+ filterValueList,
+ includeCloumn,
+ }),
+ isLeaf: true,
};
- const tableNodes = schema.tables.map(
- (table): DatabaseTreeOption<"table"> => {
- return {
- level: "table",
- value: `${schemaNode.value}/tables/${table.name}`,
- label: table.name,
- };
- }
- );
- if (tableNodes.length > 0) {
- schemaNode.children = filterValueList
- ? tableNodes.filter((node) => filterValueList.includes(node.value))
- : tableNodes;
+ if (schemaNode.children && schemaNode.children.length > 0) {
+ schemaNode.isLeaf = false;
}
return schemaNode;
}
@@ -93,18 +144,14 @@ export const getSchemaOrTableTreeOptions = (
)
: schemaNodes;
} else {
- const tableNodes = flatten(
- databaseMetadata.schemas.map((schema) => schema.tables)
- ).map((table): DatabaseTreeOption<"table"> => {
- return {
- level: "table",
- value: `${database.name}/schemas//tables/${table.name}`,
- label: table.name,
- };
+ return getTableTreeOptions({
+ prefix: `${database.name}/schemas/`,
+ tableList: flatten(
+ databaseMetadata.schemas.map((schema) => schema.tables)
+ ),
+ filterValueList,
+ includeCloumn,
});
- return filterValueList
- ? tableNodes.filter((node) => filterValueList.includes(node.value))
- : tableNodes;
}
};
diff --git a/frontend/src/components/GrantRequestPanel/DatabaseResourceForm/index.vue b/frontend/src/components/GrantRequestPanel/DatabaseResourceForm/index.vue
index b4295143c2..72eb36c5b2 100644
--- a/frontend/src/components/GrantRequestPanel/DatabaseResourceForm/index.vue
+++ b/frontend/src/components/GrantRequestPanel/DatabaseResourceForm/index.vue
@@ -15,7 +15,7 @@
</NTooltip>
<NRadio class="!leading-6" :value="false" :disabled="!project">
<div class="flex items-center space-x-2">
- <FeatureBadge feature="bb.feature.access-control" />
+ <FeatureBadge :feature="requiredFeature" />
<span>{{ $t("issue.grant-request.manually-select") }}</span>
</div>
</NRadio>
@@ -27,14 +27,14 @@
>
<DatabaseResourceSelector
v-if="project"
+ v-model:database-resources="state.databaseResources"
:project-name="project.name"
- :database-resources="state.databaseResources"
- @update="handleSelectedDatabaseResourceChanged"
+ :include-cloumn="includeCloumn"
/>
</div>
<FeatureModal
:open="state.showFeatureModal"
- :feature="'bb.feature.access-control'"
+ :feature="requiredFeature"
@cancel="state.showFeatureModal = false"
/>
</template>
@@ -43,9 +43,8 @@
import { NRadioGroup, NRadio, NTooltip } from "naive-ui";
import { computed, onMounted, reactive, watch } from "vue";
import { FeatureBadge, FeatureModal } from "@/components/FeatureGuard";
-import { useProjectByName, featureToRef } from "@/store";
-import type { DatabaseResource } from "@/types";
-import { stringifyDatabaseResources } from "@/utils/issue/cel";
+import { useProjectByName, hasFeature } from "@/store";
+import type { DatabaseResource, FeatureType } from "@/types";
import DatabaseResourceSelector from "./DatabaseResourceSelector.vue";
interface LocalState {
@@ -56,14 +55,15 @@ interface LocalState {
const props = defineProps<{
projectName: string;
+ requiredFeature: FeatureType;
+ includeCloumn: boolean;
databaseResources?: DatabaseResource[];
}>();
const emit = defineEmits<{
- (event: "update:condition", value?: string): void;
(
event: "update:database-resources",
- databaseResources: DatabaseResource[]
+ databaseResources?: DatabaseResource[]
): void;
}>();
@@ -74,13 +74,7 @@ const state = reactive<LocalState>({
});
const { project } = useProjectByName(computed(() => props.projectName));
-const hasAccessControlFeature = featureToRef("bb.feature.access-control");
-
-const handleSelectedDatabaseResourceChanged = (
- databaseResourceList: DatabaseResource[]
-) => {
- state.databaseResources = databaseResourceList;
-};
+const hasRequiredFeature = computed(() => hasFeature(props.requiredFeature));
onMounted(() => {
if (props.databaseResources && props.databaseResources.length > 0) {
@@ -92,19 +86,13 @@ watch(
() => [state.allDatabases, state.databaseResources],
() => {
if (state.allDatabases) {
- emit("update:condition", "");
+ emit("update:database-resources", undefined);
} else {
- if (!hasAccessControlFeature.value) {
+ if (!hasRequiredFeature.value) {
state.showFeatureModal = true;
state.allDatabases = true;
return;
}
- if (state.databaseResources.length === 0) {
- emit("update:condition", undefined);
- } else {
- const condition = stringifyDatabaseResources(state.databaseResources);
- emit("update:condition", condition);
- }
emit("update:database-resources", state.databaseResources);
}
},
diff --git a/frontend/src/components/GrantRequestPanel/GrantRequestPanel.vue b/frontend/src/components/GrantRequestPanel/GrantRequestPanel.vue
index 2cd54accf0..451c423f37 100644
--- a/frontend/src/components/GrantRequestPanel/GrantRequestPanel.vue
+++ b/frontend/src/components/GrantRequestPanel/GrantRequestPanel.vue
@@ -21,10 +21,10 @@
<RequiredStar />
</span>
<DatabaseResourceForm
+ v-model:database-resources="state.databaseResources"
:project-name="props.projectName"
- :database-resources="state.databaseResources"
- @update:condition="state.databaseResourceCondition = $event"
- @update:database-resources="state.databaseResources = $event"
+ :include-cloumn="false"
+ :required-feature="'bb.feature.access-control'"
/>
</div>
<div
@@ -98,11 +98,11 @@ import {
Issue_Type,
} from "@/types/proto/v1/issue_service";
import { generateIssueTitle } from "@/utils";
+import { stringifyDatabaseResources } from "@/utils/issue/cel";
import DatabaseResourceForm from "./DatabaseResourceForm/index.vue";
import MaxRowCountSelect from "./MaxRowCountSelect.vue";
interface LocalState {
- databaseResourceCondition?: string;
databaseResources: DatabaseResource[];
expireDays: number;
description: string;
@@ -157,7 +157,10 @@ const allowCreate = computed(() => {
// 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)) {
+ if (
+ !isUndefined(state.databaseResources) &&
+ state.databaseResources.length === 0
+ ) {
return false;
}
return true;
@@ -186,8 +189,8 @@ const doCreateIssue = async () => {
props.projectName
);
const expression: string[] = [];
- if (state.databaseResourceCondition) {
- expression.push(state.databaseResourceCondition);
+ if (state.databaseResources) {
+ expression.push(stringifyDatabaseResources(state.databaseResources));
}
const expireDays = state.expireDays;
if (expireDays > 0) {
diff --git a/frontend/src/components/Project/useProjectSidebar.ts b/frontend/src/components/Project/useProjectSidebar.ts
index 0537a94e53..91507e2468 100644
--- a/frontend/src/components/Project/useProjectSidebar.ts
+++ b/frontend/src/components/Project/useProjectSidebar.ts
@@ -34,6 +34,7 @@ import projectV1Routes, {
PROJECT_V1_ROUTE_AUDIT_LOGS,
PROJECT_V1_ROUTE_REVIEW_CENTER,
PROJECT_V1_ROUTE_RELEASES,
+ PROJECT_V1_ROUTE_MASKING_ACCESS,
} from "@/router/dashboard/projectV1";
import { useAppFeature } from "@/store";
import type { ComposedProject, MaybeRef, Permission } from "@/types";
@@ -139,6 +140,12 @@ export const useProjectSidebar = (
path: PROJECT_V1_ROUTE_DATABASES,
type: "div",
},
+ {
+ title: t("project.masking-access.self"),
+ path: PROJECT_V1_ROUTE_MASKING_ACCESS,
+ type: "div",
+ hide: !isDev(),
+ },
{
title: t("common.groups"),
path: PROJECT_V1_ROUTE_DATABASE_GROUPS,
diff --git a/frontend/src/components/ProjectMember/AddProjectMember/AddProjectMemberForm.vue b/frontend/src/components/ProjectMember/AddProjectMember/AddProjectMemberForm.vue
index 7727abdbd9..62ca1c715c 100644
--- a/frontend/src/components/ProjectMember/AddProjectMember/AddProjectMemberForm.vue
+++ b/frontend/src/components/ProjectMember/AddProjectMember/AddProjectMemberForm.vue
@@ -39,12 +39,15 @@
"
class="w-full"
>
- <span class="block mb-2">{{ $t("common.databases") }}</span>
+ <div class="flex items-center gap-x-1 mb-2">
+ <span>{{ $t("common.databases") }}</span>
+ <span class="text-red-600">*</span>
+ </div>
<QuerierDatabaseResourceForm
+ v-model:database-resources="state.databaseResources"
:project-name="project.name"
- :database-resources="state.databaseResources"
- @update:condition="state.databaseResourceCondition = $event"
- @update:database-resources="state.databaseResources = $event"
+ :required-feature="'bb.feature.access-control'"
+ :include-cloumn="false"
/>
</div>
<template v-if="state.role === PresetRoleType.PROJECT_EXPORTER">
@@ -70,7 +73,7 @@
<script lang="ts" setup>
/* eslint-disable vue/no-mutating-props */
import dayjs from "dayjs";
-import { head } from "lodash-es";
+import { head, isUndefined } from "lodash-es";
import { NInput, NButton } from "naive-ui";
import { computed, reactive, watch } from "vue";
import ExpirationSelector from "@/components/ExpirationSelector.vue";
@@ -84,6 +87,7 @@ import { PresetRoleType } from "@/types";
import { Expr } from "@/types/proto/google/type/expr";
import type { Binding } from "@/types/proto/v1/iam_policy";
import { displayRoleTitle, extractDatabaseResourceName } from "@/utils";
+import { stringifyDatabaseResources } from "@/utils/issue/cel";
const props = defineProps<{
project: ComposedProject;
@@ -101,7 +105,6 @@ interface LocalState {
reason: string;
expireDays: number;
// Querier and exporter options.
- databaseResourceCondition?: string;
databaseResources?: DatabaseResource[];
// Exporter options.
maxRowCount: number;
@@ -138,7 +141,6 @@ const state = reactive<LocalState>(getInitialState());
watch(
() => state.role,
() => {
- state.databaseResourceCondition = undefined;
state.databaseResources = undefined;
},
{
@@ -160,15 +162,15 @@ watch(
const expiresAt = now.add(state.expireDays, "days");
expression.push(`request.time < timestamp("${expiresAt.toISOString()}")`);
}
- if (state.role === PresetRoleType.PROJECT_QUERIER) {
- if (state.databaseResourceCondition) {
- expression.push(state.databaseResourceCondition);
+ if (
+ state.role === PresetRoleType.PROJECT_QUERIER ||
+ state.role === PresetRoleType.PROJECT_EXPORTER
+ ) {
+ if (state.databaseResources) {
+ expression.push(stringifyDatabaseResources(state.databaseResources));
}
}
if (state.role === PresetRoleType.PROJECT_EXPORTER) {
- if (state.databaseResourceCondition) {
- expression.push(state.databaseResourceCondition);
- }
if (state.maxRowCount) {
expression.push(`request.row_limit <= ${state.maxRowCount}`);
}
@@ -246,7 +248,13 @@ defineExpose({
if ((!state.expireDays && state.expireDays !== 0) || state.expireDays < 0) {
return false;
}
- // TODO: use parsed expression to check if the expression is valid.
+ // undefined databaseResources means all databases
+ if (
+ !isUndefined(state.databaseResources) &&
+ state.databaseResources.length === 0
+ ) {
+ return false;
+ }
return true;
}),
});
diff --git a/frontend/src/components/ProjectMember/ProjectMemberRolePanel/EditProjectRolePanel.vue b/frontend/src/components/ProjectMember/ProjectMemberRolePanel/EditProjectRolePanel.vue
index da09c638f1..954c50dd50 100644
--- a/frontend/src/components/ProjectMember/ProjectMemberRolePanel/EditProjectRolePanel.vue
+++ b/frontend/src/components/ProjectMember/ProjectMemberRolePanel/EditProjectRolePanel.vue
@@ -29,12 +29,15 @@
"
class="w-full"
>
- <p class="mb-2">{{ $t("common.databases") }}</p>
+ <div class="flex items-center gap-x-1 mb-2">
+ <span>{{ $t("common.databases") }}</span>
+ <span class="text-red-600">*</span>
+ </div>
<QuerierDatabaseResourceForm
+ v-model:database-resources="state.databaseResources"
:project-name="project.name"
- :database-resources="state.databaseResources"
- @update:condition="state.databaseResourceCondition = $event"
- @update:database-resources="state.databaseResources = $event"
+ :include-cloumn="false"
+ :required-feature="'bb.feature.access-control'"
/>
</div>
@@ -109,7 +112,7 @@
</template>
<script lang="ts" setup>
-import { cloneDeep, isEqual } from "lodash-es";
+import { cloneDeep, isEqual, isUndefined } from "lodash-es";
import { NButton, NDatePicker, NInput } from "naive-ui";
import { computed, reactive, ref, onMounted } from "vue";
import { useI18n } from "vue-i18n";
@@ -130,6 +133,7 @@ import { State } from "@/types/proto/v1/common";
import type { Binding } from "@/types/proto/v1/iam_policy";
import { displayRoleTitle } from "@/utils";
import { convertFromExpr } from "@/utils/issue/cel";
+import { stringifyDatabaseResources } from "@/utils/issue/cel";
import { getBindingIdentifier } from "../utils";
const props = defineProps<{
@@ -146,7 +150,6 @@ interface LocalState {
description: string;
expirationTimestamp?: number;
// Querier and exporter options.
- databaseResourceCondition?: string;
databaseResources?: DatabaseResource[];
// Exporter options.
maxRowCount: number;
@@ -182,6 +185,12 @@ const allowRemoveRole = () => {
};
const allowConfirm = computed(() => {
+ if (
+ !isUndefined(state.databaseResources) &&
+ state.databaseResources.length === 0
+ ) {
+ return false;
+ }
// only allow update current single user.
return props.binding.members.length === 1;
});
@@ -253,15 +262,15 @@ const handleUpdateRole = async () => {
).toISOString()}")`
);
}
- if (props.binding.role === PresetRoleType.PROJECT_QUERIER) {
- if (state.databaseResourceCondition) {
- expression.push(state.databaseResourceCondition);
+ if (
+ props.binding.role === PresetRoleType.PROJECT_QUERIER ||
+ props.binding.role === PresetRoleType.PROJECT_EXPORTER
+ ) {
+ if (state.databaseResources) {
+ expression.push(stringifyDatabaseResources(state.databaseResources));
}
}
if (props.binding.role === PresetRoleType.PROJECT_EXPORTER) {
- if (state.databaseResourceCondition) {
- expression.push(state.databaseResourceCondition);
- }
if (state.maxRowCount) {
expression.push(`request.row_limit <= ${state.maxRowCount}`);
}
diff --git a/frontend/src/components/QuickActionPanel.vue b/frontend/src/components/QuickActionPanel.vue
index 7b75076c8d..3e4025b80c 100644
--- a/frontend/src/components/QuickActionPanel.vue
+++ b/frontend/src/components/QuickActionPanel.vue
@@ -97,6 +97,7 @@ import {
ChevronsDownIcon,
FileSearchIcon,
FileDownIcon,
+ ShieldCheckIcon,
} from "lucide-vue-next";
import { NButton, NEllipsis } from "naive-ui";
import type { PropType, VNode } from "vue";
@@ -170,6 +171,10 @@ const hasDBAWorkflowFeature = computed(() => {
return subscriptionStore.hasFeature("bb.feature.dba-workflow");
});
+const hasSensitiveDataFeature = computed(() => {
+ return subscriptionStore.hasFeature("bb.feature.sensitive-data");
+});
+
const state = reactive<LocalState>({
quickActionType: undefined,
});
@@ -307,6 +312,14 @@ const availableQuickActionList = computed((): QuickAction[] => {
(state.quickActionType = "quickaction.bb.issue.grant.request.exporter"),
icon: h(FileDownIcon),
},
+ {
+ type: "quickaction.bb.database.masking-access",
+ title: t("project.masking-access.grant-access"),
+ hide: !hasSensitiveDataFeature.value,
+ action: () =>
+ (state.quickActionType = "quickaction.bb.database.masking-access"),
+ icon: h(ShieldCheckIcon),
+ },
];
return props.quickActionList.reduce((list, quickAction) => {
diff --git a/frontend/src/components/SensitiveData/GrantAccessDrawer.vue b/frontend/src/components/SensitiveData/GrantAccessDrawer.vue
index 790244cd9d..dec4db077b 100644
--- a/frontend/src/components/SensitiveData/GrantAccessDrawer.vue
+++ b/frontend/src/components/SensitiveData/GrantAccessDrawer.vue
@@ -92,7 +92,7 @@ import { useI18n } from "vue-i18n";
import MembersBindingSelect from "@/components/Member/MembersBindingSelect.vue";
import { Drawer, DrawerContent } from "@/components/v2";
import { usePolicyV1Store, pushNotification } from "@/store";
-import type { ComposedProject } from "@/types";
+import type { ComposedProject, DatabaseResource } from "@/types";
import { Expr } from "@/types/proto/google/type/expr";
import { MaskingLevel } from "@/types/proto/v1/common";
import type {
@@ -123,6 +123,7 @@ interface LocalState {
maskingLevel: MaskingLevel;
processing: boolean;
supportActions: Set<MaskingExceptionPolicy_MaskingException_Action>;
+ databaseResources?: DatabaseResource[];
}
const ACTIONS = [
diff --git a/frontend/src/layouts/ProjectV1Layout.vue b/frontend/src/layouts/ProjectV1Layout.vue
index 764ca9f10a..8b943ce0c8 100644
--- a/frontend/src/layouts/ProjectV1Layout.vue
+++ b/frontend/src/layouts/ProjectV1Layout.vue
@@ -46,6 +46,7 @@ import {
PROJECT_V1_ROUTE_DETAIL,
PROJECT_V1_ROUTE_DATABASES,
PROJECT_V1_ROUTE_DATABASE_GROUPS,
+ PROJECT_V1_ROUTE_MASKING_ACCESS,
} from "@/router/dashboard/projectV1";
import { WORKSPACE_ROUTE_MY_ISSUES } from "@/router/dashboard/workspaceRoutes";
import { useRecentVisit } from "@/router/useRecentVisit";
@@ -148,6 +149,10 @@ const quickActionProjectPermissionMap: Map<QuickActionType, Permission[]> =
["quickaction.bb.group.database-group.create", ["bb.projects.update"]],
["quickaction.bb.issue.grant.request.querier", ["bb.issues.create"]],
["quickaction.bb.issue.grant.request.exporter", ["bb.issues.create"]],
+ [
+ "quickaction.bb.database.masking-access",
+ ["bb.databases.list", "bb.policies.create"],
+ ],
]);
const getQuickActionList = (list: QuickActionType[]): QuickActionType[] => {
@@ -194,10 +199,20 @@ const quickActionListForDatabase = computed((): QuickActionType[] => {
return actions;
});
+const quickActionListForMaskingAccess = computed((): QuickActionType[] => {
+ if (project.value.state !== State.ACTIVE) {
+ return [];
+ }
+
+ return ["quickaction.bb.database.masking-access"];
+});
+
const quickActionList = computed(() => {
switch (route.name) {
case PROJECT_V1_ROUTE_DATABASES:
return getQuickActionList(quickActionListForDatabase.value);
+ case PROJECT_V1_ROUTE_MASKING_ACCESS:
+ return getQuickActionList(quickActionListForMaskingAccess.value);
case PROJECT_V1_ROUTE_DATABASE_GROUPS:
return getQuickActionList(quickActionListForDatabaseGroup.value);
}
diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.json
index 03377669bf..4a0627f4bc 100644
--- a/frontend/src/locales/en-US.json
+++ b/frontend/src/locales/en-US.json
@@ -2204,6 +2204,10 @@
"update-success": "Successfully updated GitOps connector",
"create-success": "Successfully created GitOps connector",
"delete-success": "The GitOps connector is removed"
+ },
+ "masking-access": {
+ "self": "Access Masking",
+ "grant-access": "Grant Access"
}
},
"gitops": {
diff --git a/frontend/src/locales/es-ES.json b/frontend/src/locales/es-ES.json
index 823b871d8f..55efea45f3 100644
--- a/frontend/src/locales/es-ES.json
+++ b/frontend/src/locales/es-ES.json
@@ -2204,6 +2204,10 @@
"update-success": "Conector GitOps actualizado correctamente",
"create-success": "Conector GitOps creado correctamente",
"delete-success": "Se elimina el conector GitOps"
+ },
+ "masking-access": {
+ "self": "Enmascaramiento de acceso",
+ "grant-access": "Conceder acceso"
}
},
"gitops": {
diff --git a/frontend/src/locales/ja-JP.json b/frontend/src/locales/ja-JP.json
index 20af2f9f9a..e3e00f73ad 100644
--- a/frontend/src/locales/ja-JP.json
+++ b/frontend/src/locales/ja-JP.json
@@ -2204,6 +2204,10 @@
"update-success": "GitOps 接続が更新されました",
"create-success": "GitOps 接続が作成されました",
"delete-success": "GitOps 接続が削除されました"
+ },
+ "masking-access": {
+ "self": "アクセスマスキング",
+ "grant-access": "アクセスを許可する"
}
},
"gitops": {
diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.json
index 6b01045ccd..f9df32d8c9 100644
--- a/frontend/src/locales/zh-CN.json
+++ b/frontend/src/locales/zh-CN.json
@@ -2204,6 +2204,10 @@
"update-success": "GitOps 连接已更新",
"create-success": "GitOps 连接已创建",
"delete-success": "GitOps 连接已删除"
+ },
+ "masking-access": {
+ "self": "数据访问",
+ "grant-access": "授予访问权限"
}
},
"gitops": {
@@ -3806,4 +3810,4 @@
"setup": {
"self": "设置"
}
-}
\ No newline at end of file
+}
diff --git a/frontend/src/router/dashboard/projectV1.ts b/frontend/src/router/dashboard/projectV1.ts
index 10937ed9a7..26b0875699 100644
--- a/frontend/src/router/dashboard/projectV1.ts
+++ b/frontend/src/router/dashboard/projectV1.ts
@@ -5,6 +5,7 @@ import { PROJECT_V1_ROUTE_DASHBOARD } from "./workspaceRoutes";
export const PROJECT_V1_ROUTE_DETAIL = `${PROJECT_V1_ROUTE_DASHBOARD}.detail`;
export const PROJECT_V1_ROUTE_DATABASES = `${PROJECT_V1_ROUTE_DASHBOARD}.database`;
+export const PROJECT_V1_ROUTE_MASKING_ACCESS = `${PROJECT_V1_ROUTE_DASHBOARD}.masking-access`;
export const PROJECT_V1_ROUTE_DATABASE_DETAIL = `${PROJECT_V1_ROUTE_DASHBOARD}.database.detail`;
export const PROJECT_V1_ROUTE_DATABASE_CHANGE_HISTORY_DETAIL = `${PROJECT_V1_ROUTE_DASHBOARD}.database.change-history.detail`;
export const PROJECT_V1_ROUTE_DATABASE_GROUPS = `${PROJECT_V1_ROUTE_DASHBOARD}.database-group`;
@@ -66,6 +67,21 @@ const projectV1Routes: RouteRecordRaw[] = [
component: () => import("@/views/project/ProjectDatabaseDashboard.vue"),
props: true,
},
+ {
+ path: "masking-access",
+ name: PROJECT_V1_ROUTE_MASKING_ACCESS,
+ meta: {
+ overrideTitle: true,
+ requiredProjectPermissionList: () => [
+ "bb.projects.get",
+ "bb.databases.list",
+ "bb.policies.get",
+ ],
+ },
+ component: () =>
+ import("@/views/project/ProjectDatabaseMaskingAccess.vue"),
+ props: true,
+ },
{
path: "database-groups",
meta: {
diff --git a/frontend/src/types/member.ts b/frontend/src/types/member.ts
index 3f49f30c11..c02f04a2a9 100644
--- a/frontend/src/types/member.ts
+++ b/frontend/src/types/member.ts
@@ -3,4 +3,5 @@ export interface DatabaseResource {
databaseName: string;
schema?: string;
table?: string;
+ column?: string;
}
diff --git a/frontend/src/types/quickAction.ts b/frontend/src/types/quickAction.ts
index 88ab4339d7..b37a203bcb 100644
--- a/frontend/src/types/quickAction.ts
+++ b/frontend/src/types/quickAction.ts
@@ -7,7 +7,9 @@ export type ProjectQuickActionType =
| "quickaction.bb.project.create"
| "quickaction.bb.project.database.transfer";
export type InstanceQuickActionType = "quickaction.bb.instance.create";
-export type DatabaseQuickActionType = "quickaction.bb.database.create";
+export type DatabaseQuickActionType =
+ | "quickaction.bb.database.create"
+ | "quickaction.bb.database.masking-access";
export type DatabaseGroupQuickActionType =
"quickaction.bb.group.database-group.create";
export type IssueQuickActionType =
diff --git a/frontend/src/views/project/ProjectDatabaseMaskingAccess.vue b/frontend/src/views/project/ProjectDatabaseMaskingAccess.vue
new file mode 100644
index 0000000000..5184f7de07
--- /dev/null
+++ b/frontend/src/views/project/ProjectDatabaseMaskingAccess.vue
@@ -0,0 +1,5 @@
+<template>
+ <div></div>
+</template>
+
+<script lang="tsx" setup></script>