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: retire `request.statement` cel factor (#11402)
boojack7f2b7e83c5be
diff --git a/backend/api/v1/issue_service.go b/backend/api/v1/issue_service.goindex e3f9e2a7ea..2c1d5a0a25 100644--- a/backend/api/v1/issue_service.go+++ b/backend/api/v1/issue_service.go@@ -629,30 +629,6 @@ func (s *IssueService) createIssueGrantRequest(ctx context.Context, request *v1pif _, issues := e.Compile(expression); issues != nil {return nil, status.Errorf(codes.InvalidArgument, "found issues in grant request condition expression, issues: %v", issues.String())}-- factors, err := common.GetQueryExportFactors(expression)- if err != nil {- return nil, status.Errorf(codes.InvalidArgument, "failed to get query export factors, error: %v", err)- }- // Validate the statement if it's not empty.- if factors.Statement != "" {- for _, dbName := range factors.DatabaseNames {- instanceID, _, err := common.GetInstanceDatabaseID(dbName)- if err != nil {- return nil, status.Errorf(codes.InvalidArgument, "invalid database name %q, error: %v", dbName, err)- }- instance, err := s.store.GetInstanceV2(ctx, &store.FindInstanceMessage{ResourceID: &instanceID})- if err != nil {- return nil, status.Errorf(codes.Internal, "failed to get instance, error: %v", err)- }- if instance == nil {- return nil, status.Errorf(codes.NotFound, "instance %q not found", instanceID)- }- if err := validateQueryRequest(instance, factors.Statement); err != nil {- return nil, status.Errorf(codes.InvalidArgument, "invalid statement, error: %v", err)- }- }- }}issueCreateMessage := &store.IssueMessage{diff --git a/backend/api/v1/sql_service.go b/backend/api/v1/sql_service.goindex 40ce53bc07..060ecc576d 100644--- a/backend/api/v1/sql_service.go+++ b/backend/api/v1/sql_service.go@@ -297,7 +297,7 @@ func (s *SQLService) Export(ctx context.Context, request *v1pb.ExportRequest) (*}if s.licenseService.IsFeatureEnabled(api.FeatureAccessControl) == nil {- if err := s.accessCheck(ctx, instance, user, request.Statement, spans, request.Limit, false /* isAdmin */, true /* isExport */); err != nil {+ if err := s.accessCheck(ctx, instance, user, spans, request.Limit, false /* isAdmin */, true /* isExport */); err != nil {return nil, err}}@@ -1144,7 +1144,7 @@ func (s *SQLService) Query(ctx context.Context, request *v1pb.QueryRequest) (*v1}if s.licenseService.IsFeatureEnabled(api.FeatureAccessControl) == nil {- if err := s.accessCheck(ctx, instance, user, request.Statement, spans, request.Limit, false /* isAdmin */, false /* isExport */); err != nil {+ if err := s.accessCheck(ctx, instance, user, spans, request.Limit, false /* isAdmin */, false /* isExport */); err != nil {return nil, err}}@@ -1197,7 +1197,7 @@ func (s *SQLService) Query(ctx context.Context, request *v1pb.QueryRequest) (*v1allowExport := true// AllowExport is a validate only check.if s.licenseService.IsFeatureEnabled(api.FeatureAccessControl) == nil {- err := s.accessCheck(ctx, instance, user, request.Statement, spans, request.Limit, false /* isAdmin */, true /* isExport */)+ err := s.accessCheck(ctx, instance, user, spans, request.Limit, false /* isAdmin */, true /* isExport */)allowExport = (err == nil)}@@ -1392,7 +1392,6 @@ func (s *SQLService) accessCheck(ctx context.Context,instance *store.InstanceMessage,user *store.UserMessage,- statement string,spans []*base.QuerySpan,limit int32,isAdmin,@@ -1410,7 +1409,6 @@ func (s *SQLService) accessCheck("resource.database": databaseResourceURL,"resource.schema": column.Schema,"resource.table": column.Table,- "request.statement": encodeToBase64String(statement),"request.row_limit": limit,}diff --git a/backend/common/cel.go b/backend/common/cel.goindex 30d2a14abb..23ff4bb0e5 100644--- a/backend/common/cel.go+++ b/backend/common/cel.go@@ -1,7 +1,6 @@package commonimport (- "encoding/base64""time""github.com/google/cel-go/cel"@@ -46,7 +45,6 @@ var IAMPolicyConditionCELAttributes = []cel.EnvOption{cel.Variable("resource.database", cel.StringType),cel.Variable("resource.schema", cel.StringType),cel.Variable("resource.table", cel.StringType),- cel.Variable("request.statement", cel.StringType),cel.Variable("request.row_limit", cel.IntType),cel.Variable("request.time", cel.TimestampType),cel.ParserExpressionSizeLimit(celLimit),@@ -200,7 +198,6 @@ func ValidateProjectMemberCELExpr(expression *expr.Expr) (cel.Program, error) {type QueryExportFactors struct {DatabaseNames []stringExportRows int64- Statement string}// GetQueryExportFactors is used to get risk factors from query and export expressions.@@ -243,14 +240,6 @@ func findField(callExpr *exprproto.Expr_Call, factors *QueryExportFactors) {factors.DatabaseNames = append(factors.DatabaseNames, element.GetConstExpr().GetStringValue())}}- if idExpr.Name == "request.statement" && callExpr.Function == "_==_" {- encodedStatment := callExpr.Args[1].GetConstExpr().GetStringValue()- statement, err := base64.StdEncoding.DecodeString(encodedStatment)- if err != nil {- return- }- factors.Statement = string(statement)- }return}}diff --git a/backend/common/cel_test.go b/backend/common/cel_test.goindex a3bc6b02ef..c33fa0c0f6 100644--- a/backend/common/cel_test.go+++ b/backend/common/cel_test.go@@ -85,11 +85,10 @@ func TestGetQueryExportFactors(t *testing.T) {},},{- expression: "request.time < timestamp(\"2023-07-04T07:40:05.658Z\") && request.row_limit == 1000 && request.statement == \"c2VsZWN0ICogZnJvbSBlbXBsb3llZTs=\" && (resource.database in [\"instances/postgres-sample/databases/employee\"])",+ expression: "request.time < timestamp(\"2023-07-04T07:40:05.658Z\") && request.row_limit == 1000 && (resource.database in [\"instances/postgres-sample/databases/employee\"])",want: QueryExportFactors{DatabaseNames: []string{"instances/postgres-sample/databases/employee"},ExportRows: 1000,- Statement: "select * from employee;",},},{diff --git a/backend/migrator/migration/prod/2.15/0016##project_member_with_statement.sql b/backend/migrator/migration/prod/2.15/0016##project_member_with_statement.sqlnew file mode 100644index 0000000000..3cc8c61c57--- /dev/null+++ b/backend/migrator/migration/prod/2.15/0016##project_member_with_statement.sql@@ -0,0 +1 @@+DELETE FROM project_member WHERE (condition->>'expression')::text LIKE '%request.statement%';\ No newline at end of filediff --git a/backend/migrator/migrator_test.go b/backend/migrator/migrator_test.goindex 3fe7046444..e03a5acff5 100644--- a/backend/migrator/migrator_test.go+++ b/backend/migrator/migrator_test.go@@ -230,5 +230,5 @@ func TestMigrationCompatibility(t *testing.T) {func TestGetCutoffVersion(t *testing.T) {releaseVersion, err := getProdCutoffVersion()require.NoError(t, err)- require.Equal(t, semver.MustParse("2.15.15"), releaseVersion)+ require.Equal(t, semver.MustParse("2.15.16"), releaseVersion)}diff --git a/frontend/src/components/Issue/panel/RequestExportPanel/ExportResourceForm/DatabaseResourceSelector.vue b/frontend/src/components/Issue/panel/RequestExportPanel/ExportResourceForm/DatabaseResourceSelector.vuedeleted file mode 100644index 9cebc3ad16..0000000000--- a/frontend/src/components/Issue/panel/RequestExportPanel/ExportResourceForm/DatabaseResourceSelector.vue+++ /dev/null@@ -1,224 +0,0 @@-<template>- <div class="w-[60rem] space-y-2">- <NTransfer- v-if="!loading"- v-model:value="selectedValueList"- class="select-table-transfer"- :options="sourceTransferOptions"- :render-source-list="renderSourceList"- :render-target-list="renderTargetList"- :source-filterable="true"- :source-filter-placeholder="$t('common.filter-by-name')"- />- <div- v-else- style="height: 512px"- class="border flex items-center justify-center"- >- <BBSpin size="large" />- </div>- </div>-</template>--<script setup lang="ts">-import { orderBy } from "lodash-es";-import type { TransferRenderSourceList, TreeOption } from "naive-ui";-import { NTransfer, NTree } from "naive-ui";-import { computed, h, ref, watch } from "vue";-import {- useDatabaseV1Store,- useDBSchemaV1Store,- useProjectV1Store,-} from "@/store";-import type { DatabaseResource } from "@/types";-import Label from "./Label.vue";-import type { DatabaseTreeOption } from "./common";-import { flattenTreeOptions, mapTreeOptions } from "./common";--const props = defineProps<{- projectId: string;- databaseId: string;- databaseResources: DatabaseResource[];-}>();--const emit = defineEmits<{- (e: "update", databaseResourceList: DatabaseResource[]): void;-}>();--const databaseStore = useDatabaseV1Store();-const dbSchemaStore = useDBSchemaV1Store();-const selectedValueList = ref<string[]>(- props.databaseResources- .map((databaseResource) => {- const database = databaseStore.getDatabaseByName(- databaseResource.databaseName- );- if (databaseResource.table !== undefined) {- return `t-${database.uid}-${databaseResource.schema}-${databaseResource.table}`;- } else {- return "";- }- })- .filter((item) => item !== "")-);-const databaseResourceMap = ref<Map<string, DatabaseResource>>(new Map());-const loading = ref(true);--watch(- () => props.projectId,- async (projectId) => {- loading.value = true;-- const project = await useProjectV1Store().getOrFetchProjectByUID(projectId);- const filters = [`instance = "instances/-"`, `project = "${project.name}"`];- const databaseList = await databaseStore.searchDatabases({- filter: filters.join(" && "),- });-- for (const database of databaseList) {- const databaseMetadata = await dbSchemaStore.getOrFetchDatabaseMetadata({- database: database.name,- });- databaseResourceMap.value.set(`d-${database.uid}`, {- databaseName: database.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,- }-);--const databaseList = computed(() => {- const project = useProjectV1Store().getProjectByUID(props.projectId);- const list = orderBy(- databaseStore.databaseListByProject(project.name),- [- (db) => db.effectiveEnvironmentEntity.order,- (db) => db.effectiveEnvironmentEntity.title,- (db) => db.databaseName,- (db) => db.instanceEntity.title,- ],- ["desc", "asc", "asc", "asc"]- );- return props.databaseId- ? list.filter((item) => item.uid === props.databaseId)- : list;-});--const sourceTreeOptions = computed(() => {- return mapTreeOptions(databaseList.value);-});--const sourceTransferOptions = computed(() => {- const options = flattenTreeOptions(sourceTreeOptions.value);- return options;-});--const renderSourceList: TransferRenderSourceList = ({ onCheck, pattern }) => {- return h(NTree, {- keyField: "value",- checkable: true,- selectable: false,- data: sourceTreeOptions.value,- defaultExpandAll: true,- blockLine: true,- style: "height: 428px", // since <NTransfer> height is 512- renderLabel: ({ option }: { option: TreeOption }) => {- return h(Label, {- option: option as DatabaseTreeOption,- keyword: pattern,- });- },- pattern,- checkedKeys: selectedValueList.value,- showIrrelevantNodes: false,- onUpdateCheckedKeys: (checkedKeys: string[]) => {- onCheck(checkedKeys);- },- });-};--const targetTreeOptions = computed(() => {- return mapTreeOptions(databaseList.value, selectedValueList.value);-});--const renderTargetList: TransferRenderSourceList = ({ onCheck }) => {- return h(NTree, {- keyField: "value",- checkable: true,- selectable: false,- checkOnClick: true,- defaultExpandAll: true,- data: targetTreeOptions.value,- blockLine: true,- style: "height: 468px", // since <NTransfer> height is 512- renderLabel: ({ option }: { option: TreeOption }) => {- return h(Label, {- option: option as DatabaseTreeOption,- });- },- checkedKeys: selectedValueList.value,- showIrrelevantNodes: false,- onUpdateCheckedKeys: (checkedKeys: string[]) => {- onCheck(checkedKeys);- },- });-};--// Clear selectedValueList when projectId changed.-watch(- () => props.projectId,- () => {- selectedValueList.value = [];- }-);--watch(- () => [props.projectId, props.databaseId],- () => {- if (!props.databaseId) {- selectedValueList.value = [];- return;- }- const database = databaseStore.getDatabaseByUID(props.databaseId);- selectedValueList.value = selectedValueList.value.filter((key) =>- key.startsWith(`t-${database.databaseName}`)- );- }-);--watch(selectedValueList, () => {- emit(- "update",- selectedValueList.value.map((key) => databaseResourceMap.value.get(key)!)- );-});-</script>--<style>-/* Hide the select all button in NTransfer */-.select-table-transfer- > .n-transfer-list--source- > .n-transfer-list-header- > .n-transfer-list-header__button {- @apply hidden;-}-</style>diff --git a/frontend/src/components/Issue/panel/RequestExportPanel/ExportResourceForm/Label.vue b/frontend/src/components/Issue/panel/RequestExportPanel/ExportResourceForm/Label.vuedeleted file mode 100644index 97e7a5e7eb..0000000000--- a/frontend/src/components/Issue/panel/RequestExportPanel/ExportResourceForm/Label.vue+++ /dev/null@@ -1,77 +0,0 @@-<template>- <div class="w-full flex items-center truncate gap-x-1">- <span v-if="environment" class="text-gray-400">- (<EnvironmentV1Name :environment="environment" :link="false" />)- </span>- <Prefix />- <!-- eslint-disable-next-line vue/no-v-html -->- <span v-html="optionName" />- <span v-if="database" class="ml-1 text-gray-500 flex flex-row items-center">- (<InstanceV1Name- :instance="database.instanceEntity"- :link="false"- class="whitespace-nowrap"- />)- </span>- </div>-</template>--<script setup lang="ts">-import { escape } from "lodash-es";-import { computed, h } from "vue";-import DatabaseIcon from "~icons/heroicons-outline/circle-stack";-import TableIcon from "~icons/heroicons-outline/table-cells";-import SchemaIcon from "~icons/heroicons-outline/view-columns";-import { EnvironmentV1Name, InstanceV1Name } from "@/components/v2";-import { useDatabaseV1Store } from "@/store";-import { getHighlightHTMLByRegExp } from "@/utils";-import type { DatabaseTreeOption } from "./common";--const props = defineProps<{- option: DatabaseTreeOption;- keyword?: string;-}>();--const option = computed(() => props.option);--const database = computed(() => {- const { option } = props;- if (option.level !== "database") return undefined;- const databaseId = option.value.replace("d-", "");- return useDatabaseV1Store().getDatabaseByUID(databaseId);-});--const environment = computed(() => {- const { option } = props;- if (option.level !== "database") return undefined;- return database.value?.effectiveEnvironmentEntity;-});--const Prefix = () => {- if (option.value.level === "database") {- return h(DatabaseIcon, {- class: "w-4 h-auto text-gray-400 shrink-0",- });- } else if (option.value.level === "schema") {- return h(SchemaIcon, {- class: "w-4 h-auto text-gray-400 shrink-0",- });- } else if (option.value.level === "table") {- return h(TableIcon, {- class: "w-4 h-auto text-gray-400 shrink-0",- });- }- return null;-};--const optionName = computed(() => {- const name = option.value?.label ?? "";- const keyword = (props.keyword ?? "").trim();-- return getHighlightHTMLByRegExp(- escape(name),- escape(keyword),- false /* !caseSensitive */- );-});-</script>diff --git a/frontend/src/components/Issue/panel/RequestExportPanel/ExportResourceForm/common.ts b/frontend/src/components/Issue/panel/RequestExportPanel/ExportResourceForm/common.tsdeleted file mode 100644index cad36f0bd0..0000000000--- a/frontend/src/components/Issue/panel/RequestExportPanel/ExportResourceForm/common.ts+++ /dev/null@@ -1,109 +0,0 @@-import { flatten } from "lodash-es";-import type { TransferOption, TreeOption } from "naive-ui";-import { useDBSchemaV1Store } from "@/store";-import type { ComposedDatabase } from "@/types";-import { hasSchemaProperty } from "@/utils";--export interface DatabaseTreeOption<L = "database" | "schema" | "table">- extends TreeOption {- level: L;- value: string;-}--export const mapTreeOptions = (- databaseList: ComposedDatabase[],- filterValueList?: string[]-) => {- const dbSchemaStore = useDBSchemaV1Store();- const databaseNodes: DatabaseTreeOption<"database">[] = [];- for (const database of databaseList) {- const databaseMetadata = dbSchemaStore.getDatabaseMetadata(database.name);- const databaseNode: DatabaseTreeOption<"database"> = {- level: "database",- value: `d-${database.uid}`,- label: database.databaseName,- checkboxDisabled: true,- };-- if (hasSchemaProperty(database.instanceEntity.engine)) {- const schemaNodes = databaseMetadata.schemas.map(- (schema): DatabaseTreeOption<"schema"> => {- const schemaNode: DatabaseTreeOption<"schema"> = {- level: "schema",- value: `s-${database.uid}-${schema.name}`,- label: schema.name,- checkboxDisabled: true,- };- const tableNodes = schema.tables.map(- (table): DatabaseTreeOption<"table"> => {- return {- level: "table",- value: `t-${database.uid}-${schema.name}-${table.name}`,- label: table.name,- };- }- );- if (tableNodes.length > 0) {- schemaNode.children = filterValueList- ? tableNodes.filter(- (node) =>- (node.children && node.children?.length > 0) ||- filterValueList.includes(node.value)- )- : tableNodes;- }- return schemaNode;- }- );- if (schemaNodes.length > 0) {- databaseNode.children = filterValueList- ? schemaNodes.filter(- (node) =>- (node.children && node.children?.length > 0) ||- filterValueList.includes(node.value)- )- : schemaNodes;- }- } else {- const tableNodes = flatten(- databaseMetadata.schemas.map((schema) => schema.tables)- ).map((table): DatabaseTreeOption<"table"> => {- return {- level: "table",- value: `t-${database.uid}--${table.name}`,- label: table.name,- };- });- if (tableNodes.length > 0) {- databaseNode.children = filterValueList- ? tableNodes.filter(- (node) =>- (node.children && node.children?.length > 0) ||- filterValueList.includes(node.value)- )- : tableNodes;- }- }- databaseNodes.push(databaseNode);- }- return filterValueList- ? databaseNodes.filter(- (node) =>- (node.children && node.children?.length > 0) ||- filterValueList.includes(node.value)- )- : databaseNodes;-};--export const flattenTreeOptions = (- options: DatabaseTreeOption[]-): TransferOption[] => {- return options.flatMap((option) => {- return [- option as TransferOption,- ...flattenTreeOptions(- (option.children as DatabaseTreeOption[] | undefined) ?? []- ),- ];- });-};diff --git a/frontend/src/components/Issue/panel/RequestExportPanel/ExportResourceForm/index.vue b/frontend/src/components/Issue/panel/RequestExportPanel/ExportResourceForm/index.vuedeleted file mode 100644index a967a53061..0000000000--- a/frontend/src/components/Issue/panel/RequestExportPanel/ExportResourceForm/index.vue+++ /dev/null@@ -1,156 +0,0 @@-<template>- <div class="w-full mb-2">- <NRadioGroup- v-if="!props.statementOnly"- v-model:value="state.exportMethod"- class="w-full !flex flex-row justify-start items-center gap-4"- >- <NRadio :value="'SQL'" label="SQL" />- <NTooltip :disabled="allowSelectTableResource">- <template #trigger>- <NRadio- :disabled="!allowSelectTableResource"- :value="'DATABASE'"- :label="$t('common.database')"- />- </template>- {{ $t("issue.grant-request.please-select-database-first") }}- </NTooltip>- </NRadioGroup>- </div>- <div- v-show="state.exportMethod === 'SQL'"- class="w-full h-[300px] border rounded"- >- <MonacoEditor- v-model:content="state.statement"- class="w-full h-full py-2"- :auto-focus="false"- :language="'sql'"- :dialect="dialect"- />- </div>- <template v-if="!props.statementOnly">- <div- v-if="state.exportMethod === 'DATABASE'"- class="w-full flex flex-row justify-start items-center"- >- <DatabaseResourceSelector- :project-id="project!.uid"- :database-id="props.databaseId as string"- :database-resources="state.databaseResources"- @update="handleTableResourceUpdate"- />- </div>- </template>-</template>--<script lang="ts" setup>-import { isUndefined } from "lodash-es";-import { NRadioGroup, NRadio, NTooltip } from "naive-ui";-import { computed, onMounted, reactive, watch } from "vue";-import { MonacoEditor } from "@/components/MonacoEditor";-import { useDatabaseV1Store, useProjectV1Store } from "@/store";-import type { DatabaseResource, SQLDialect } from "@/types";-import { UNKNOWN_ID, dialectOfEngineV1 } from "@/types";-import { Engine } from "@/types/proto/v1/common";-import { stringifyDatabaseResources } from "@/utils/issue/cel";-import DatabaseResourceSelector from "./DatabaseResourceSelector.vue";--const props = defineProps<{- projectId?: string;- databaseId?: string;- statement?: string;- statementOnly?: boolean;- databaseResources?: DatabaseResource[];-}>();--const emit = defineEmits<{- (event: "update:condition", value?: string): void;- (- event: "update:database-resources",- databaseResources: DatabaseResource[]- ): void;-}>();--interface LocalState {- exportMethod: "SQL" | "DATABASE";- statement: string;- databaseResources: DatabaseResource[];-}--const projectStore = useProjectV1Store();-const databaseStore = useDatabaseV1Store();-const state = reactive<LocalState>({- exportMethod: "SQL",- statement: props.statement || "",- databaseResources: props.databaseResources || [],-});--const project = computed(() => {- return props.projectId- ? projectStore.getProjectByUID(props.projectId)- : undefined;-});--const selectedDatabase = computed(() => {- if (!props.databaseId || props.databaseId === String(UNKNOWN_ID)) {- return undefined;- }- return databaseStore.getDatabaseByUID(props.databaseId);-});--const allowSelectTableResource = computed(() => {- return props.databaseId !== undefined;-});--const dialect = computed((): SQLDialect => {- const db = selectedDatabase.value;- return dialectOfEngineV1(db?.instanceEntity.engine ?? Engine.MYSQL);-});--onMounted(() => {- if (- props.databaseResources &&- props.databaseResources.length > 0 &&- isUndefined(props.statement)- ) {- state.exportMethod = "DATABASE";- }-});--watch(- () => [state.exportMethod, state.statement, state.databaseResources],- () => {- if (state.exportMethod === "SQL") {- if (state.statement === "") {- emit("update:condition", undefined);- } else {- emit(- "update:condition",- `request.statement == "${btoa(- unescape(encodeURIComponent(state.statement))- )}"`- );- }- } else {- 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);- }- },- {- immediate: true,- }-);--const handleTableResourceUpdate = (- databaseResourceList: DatabaseResource[]-) => {- state.databaseResources = databaseResourceList;-};-</script>diff --git a/frontend/src/components/Issue/panel/RequestExportPanel/index.vue b/frontend/src/components/Issue/panel/RequestExportPanel/index.vueindex 8714c81423..92fc4a3b0e 100644--- a/frontend/src/components/Issue/panel/RequestExportPanel/index.vue+++ b/frontend/src/components/Issue/panel/RequestExportPanel/index.vue@@ -23,57 +23,18 @@/></div>- <template v-if="props.statementOnly">- <div class="w-full flex flex-col justify-start items-start">- <span class="flex items-center textlabel mb-2">- {{ $t("common.database") }}- <RequiredStar />- </span>- <div class="flex flex-row justify-start items-center">- <EnvironmentSelect- class="!w-60 mr-4 shrink-0"- :environment="state.environmentId"- @update:environment="handleEnvironmentSelect"- />- <DatabaseSelect- class="!w-96"- :database="state.databaseId"- :environment="state.environmentId"- :project="state.projectId"- @update:database="handleDatabaseSelect"- >- </DatabaseSelect>- </div>- </div>- <div class="w-full flex flex-col justify-start items-start">- <span class="flex items-center textlabel mb-2">- SQL- <RequiredStar />- </span>- <div class="w-full h-[300px]">- <MonacoEditor- v-model:content="state.statement"- class="w-full h-full rounded border"- :auto-focus="false"- :dialect="dialect"- />- </div>- </div>- </template>- <template v-else>- <div class="w-full flex flex-col justify-start items-start">- <span class="flex items-center textlabel mb-2">- {{ $t("common.databases") }}- <RequiredStar />- </span>- <DatabaseResourceForm- :project-id="state.projectId"- :database-resources="state.databaseResources"- @update:condition="state.databaseResourceCondition = $event"- @update:database-resources="state.databaseResources = $event"- />- </div>- </template>+ <div class="w-full flex flex-col justify-start items-start">+ <span class="flex items-center textlabel mb-2">+ {{ $t("common.databases") }}+ <RequiredStar />+ </span>+ <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-center textlabel mb-2">{{ $t("issue.grant-request.export-rows") }}@@ -135,15 +96,8 @@ import { computed, onMounted, reactive } from "vue";import { useI18n } from "vue-i18n";import { useRouter } from "vue-router";import ExpirationSelector from "@/components/ExpirationSelector.vue";-import { MonacoEditor } from "@/components/MonacoEditor";import RequiredStar from "@/components/RequiredStar.vue";-import {- ProjectSelect,- EnvironmentSelect,- DatabaseSelect,- DrawerContent,- Drawer,-} from "@/components/v2";+import { ProjectSelect, DrawerContent, Drawer } from "@/components/v2";import { issueServiceClient } from "@/grpcweb";import { PROJECT_V1_ROUTE_ISSUE_DETAIL } from "@/router/dashboard/projectV1";import {@@ -152,16 +106,10 @@ import {useProjectV1Store,pushNotification,} from "@/store";-import type { DatabaseResource, SQLDialect, ComposedProject } from "@/types";-import {- SYSTEM_BOT_EMAIL,- UNKNOWN_ID,- dialectOfEngineV1,- PresetRoleType,-} from "@/types";+import type { DatabaseResource, ComposedProject } from "@/types";+import { SYSTEM_BOT_EMAIL, UNKNOWN_ID, PresetRoleType } from "@/types";import { Duration } from "@/types/proto/google/protobuf/duration";import { Expr } from "@/types/proto/google/type/expr";-import { Engine } from "@/types/proto/v1/common";import { Issue, Issue_Type } from "@/types/proto/v1/issue_service";import {extractProjectResourceName,@@ -169,7 +117,6 @@ import {issueSlug,memberListInProjectV1,} from "@/utils";-import { stringifyDatabaseResources } from "@/utils/issue/cel";import DatabaseResourceForm from "../RequestQueryPanel/DatabaseResourceForm/index.vue";interface LocalState {@@ -180,7 +127,6 @@ interface LocalState {databaseResources: DatabaseResource[];expireDays: number;maxRowCount: number;- statement: string;description: string;}@@ -191,8 +137,6 @@ defineOptions({const props = defineProps<{projectId?: string;databaseId?: string;- statement?: string;- statementOnly?: boolean;redirectToIssuePage?: boolean;}>();@@ -209,17 +153,9 @@ const state = reactive<LocalState>({databaseResources: [],expireDays: 1,maxRowCount: 1000,- statement: "",description: "",});-const selectedDatabase = computed(() => {- if (!state.databaseId || state.databaseId === String(UNKNOWN_ID)) {- return undefined;- }- return databaseStore.getDatabaseByUID(state.databaseId);-});-const expireDaysOptions = computed(() => [{value: 1,@@ -239,23 +175,12 @@ const expireDaysOptions = computed(() => [},]);-const dialect = computed((): SQLDialect => {- const db = selectedDatabase.value;- return dialectOfEngineV1(db?.instanceEntity.engine ?? Engine.MYSQL);-});-const allowCreate = computed(() => {if (!state.projectId) {return false;}- if (props.statementOnly) {- if (!state.databaseId || !state.statement) {- return false;- }- } else {- if (isUndefined(state.databaseResourceCondition)) {- return false;- }+ if (isUndefined(state.databaseResourceCondition)) {+ return false;}return true;});@@ -267,9 +192,6 @@ onMounted(async () => {if (props.databaseId) {handleDatabaseSelect(props.databaseId);}- if (props.statement) {- state.statement = props.statement;- }});const filterProject = (project: ComposedProject) => {@@ -338,25 +260,8 @@ const doCreateIssue = async () => {.toISOString()}")`);expression.push(`request.row_limit <= ${state.maxRowCount}`);- if (props.statementOnly) {- // Selected database condition.- expression.push(- stringifyDatabaseResources([- {- databaseName: selectedDatabase.value!.name,- },- ])- );- // Statement condition.- expression.push(- `request.statement == "${btoa(- unescape(encodeURIComponent(state.statement))- )}"`- );- } else {- if (state.databaseResourceCondition) {- expression.push(state.databaseResourceCondition);- }+ if (state.databaseResourceCondition) {+ expression.push(state.databaseResourceCondition);}const celExpressionString = expression.join(" && ");@@ -397,33 +302,7 @@ const doCreateIssue = async () => {};const generateIssueName = () => {- if (props.statementOnly) {- const database = selectedDatabase.value;- if (!database) {- throw new Error("Database is not selected");- }-- if (state.databaseResources.length === 0) {- return `Request data export for "${database.databaseName} (${database.instanceEntity.title})"`;- } else {- const sections: string[] = [];- for (const databaseResource of state.databaseResources) {- const nameList = [database.databaseName];- if (databaseResource.schema) {- nameList.push(databaseResource.schema);- }- if (databaseResource.table) {- nameList.push(databaseResource.table);- }- sections.push(nameList.join("."));- }- return `Request data export for "${sections.join(".")} (${- database.instanceEntity.title- })"`;- }- } else {- const project = projectStore.getProjectByUID(state.projectId!);- return `Request data export for "${project.title}"`;- }+ const project = projectStore.getProjectByUID(state.projectId!);+ return `Request data export for "${project.title}"`;};</script>diff --git a/frontend/src/components/IssueV1/components/GrantRequest/GrantRequestExporterForm.vue b/frontend/src/components/IssueV1/components/GrantRequest/GrantRequestExporterForm.vueindex e59c87e384..c73f35c3f1 100644--- a/frontend/src/components/IssueV1/components/GrantRequest/GrantRequestExporterForm.vue+++ b/frontend/src/components/IssueV1/components/GrantRequest/GrantRequestExporterForm.vue@@ -9,12 +9,9 @@<divclass="w-full flex flex-row justify-start items-start flex-wrap gap-2 gap-x-4">- <span- v-if="- exportMethod !== 'SQL' && selectedDatabaseResources.length === 0- "- >{{ $t("issue.grant-request.all-databases") }}</span- >+ <span v-if="selectedDatabaseResources.length === 0">{{+ $t("issue.grant-request.all-databases")+ }}</span><DatabaseResourceTablev-elseclass="w-full"@@ -22,20 +19,6 @@/></div></div>- <div- v-if="exportMethod === 'SQL'"- class="w-full flex flex-col justify-start items-start"- >- <span class="flex items-center textlabel mb-2">SQL</span>- <div class="w-full border rounded min-h-[6rem] relative">- <MonacoEditor- class="w-full h-[300px]"- :content="state.statement"- :auto-focus="false"- :readonly="true"- />- </div>- </div><div class="w-full flex flex-col justify-start items-start"><span class="flex items-center textlabel mb-2">{{ $t("issue.grant-request.export-rows") }}@@ -57,8 +40,7 @@<script lang="ts" setup>import dayjs from "dayjs";-import { computed, onMounted, reactive, ref } from "vue";-import { MonacoEditor } from "@/components/MonacoEditor";+import { onMounted, reactive, ref } from "vue";import type { DatabaseResource } from "@/types";import { PresetRoleType } from "@/types";import { convertFromCELString } from "@/utils/issue/cel";@@ -67,22 +49,16 @@ import DatabaseResourceTable from "./DatabaseResourceTable.vue";interface LocalState {maxRowCount: number;- statement: string;expiredAt: string;}const { issue } = useIssueContext();const state = reactive<LocalState>({maxRowCount: 1000,- statement: "",expiredAt: "",});const selectedDatabaseResources = ref<DatabaseResource[]>([]);-const exportMethod = computed(() => {- return state.statement === "" ? "DATABASE" : "SQL";-});-onMounted(async () => {const grantRequest = issue.value.grantRequest!;if (grantRequest.role !== PresetRoleType.PROJECT_EXPORTER) {@@ -105,9 +81,6 @@ onMounted(async () => {} else {state.expiredAt = "-";}- if (conditionExpression.statement !== undefined) {- state.statement = conditionExpression.statement;- }if (conditionExpression.rowLimit !== undefined) {state.maxRowCount = conditionExpression.rowLimit;}diff --git a/frontend/src/components/ProjectMember/EditProjectRolePanel.vue b/frontend/src/components/ProjectMember/EditProjectRolePanel.vueindex 21c10df6b0..b83bf392f7 100644--- a/frontend/src/components/ProjectMember/EditProjectRolePanel.vue+++ b/frontend/src/components/ProjectMember/EditProjectRolePanel.vue@@ -136,11 +136,7 @@ import type { User } from "@/types/proto/v1/auth_service";import { State } from "@/types/proto/v1/common";import type { Binding } from "@/types/proto/v1/iam_policy";import { displayRoleTitle, extractUserUID } from "@/utils";-import {- convertFromCELString,- convertFromExpr,- stringifyDatabaseResources,-} from "@/utils/issue/cel";+import { convertFromExpr } from "@/utils/issue/cel";const props = defineProps<{project: ComposedProject;@@ -160,7 +156,6 @@ interface LocalState {databaseResourceCondition?: string;databaseResources?: DatabaseResource[];// Exporter options.- statement?: string;maxRowCount: number;databaseId?: string;}@@ -227,9 +222,6 @@ onMounted(() => {if (conditionExpr.rowLimit) {state.maxRowCount = conditionExpr.rowLimit;}- if (conditionExpr.statement) {- state.statement = conditionExpr.statement;- }}// Extract user list from members.@@ -298,24 +290,6 @@ const handleUpdateRole = async () => {if (props.binding.role === PresetRoleType.PROJECT_EXPORTER) {if (state.databaseResourceCondition) {expression.push(state.databaseResourceCondition);-- // Check if the statement export method is selected.- const condition = await convertFromCELString(- state.databaseResourceCondition- );- if (condition.statement) {- if (!state.databaseId) {- throw new Error("Database ID is not set.");- }- const database = databaseStore.getDatabaseByUID(state.databaseId);- expression.push(- stringifyDatabaseResources([- {- databaseName: database.name,- },- ])- );- }}if (state.maxRowCount) {expression.push(`request.row_limit <= ${state.maxRowCount}`);diff --git a/frontend/src/components/ProjectMember/ProjectMemberPanel.vue b/frontend/src/components/ProjectMember/ProjectMemberPanel.vueindex 7ada3cd31d..e54a769051 100644--- a/frontend/src/components/ProjectMember/ProjectMemberPanel.vue+++ b/frontend/src/components/ProjectMember/ProjectMemberPanel.vue@@ -98,13 +98,11 @@ import {DEFAULT_PROJECT_V1_NAME,getUserEmailInBinding,unknownUser,- PresetRoleType,ALL_USERS_USER_EMAIL,PRESET_WORKSPACE_ROLES,} from "@/types";import type { User } from "@/types/proto/v1/auth_service";import { State } from "@/types/proto/v1/common";-import { convertFromExpr } from "@/utils/issue/cel";import AddProjectMembersPanel from "./AddProjectMember/AddProjectMembersPanel.vue";import ProjectMemberDataTable from "./ProjectMemberDataTable/index.vue";import ProjectMemberDataTableByRole from "./ProjectMemberDataTableByRole/index.vue";@@ -154,19 +152,7 @@ const allowAdmin = computed(() => {});const projectIAMPolicyBindings = computed(() => {- return iamPolicy.value.bindings.filter((binding) => {- // Don't show EXPORTER role if it has a non-empty statement condition.- if (binding.role === PresetRoleType.PROJECT_EXPORTER) {- const parsedExpr = binding.parsedExpr;- if (parsedExpr?.expr) {- const expression = convertFromExpr(parsedExpr.expr);- if (expression.statement && expression.statement !== "") {- return false;- }- }- }- return true;- });+ return iamPolicy.value.bindings;});const activeUserList = computed(() => {diff --git a/frontend/src/plugins/cel/types/factor.ts b/frontend/src/plugins/cel/types/factor.tsindex ddc59faaba..be9dab3c0b 100644--- a/frontend/src/plugins/cel/types/factor.ts+++ b/frontend/src/plugins/cel/types/factor.ts@@ -28,7 +28,6 @@ export const StringFactorList = ["resource.database","resource.schema","resource.table",- "request.statement",// Deprecated"request.export_format",diff --git a/frontend/src/utils/issue/cel.ts b/frontend/src/utils/issue/cel.tsindex 20852718e8..c9e78d8d97 100644--- a/frontend/src/utils/issue/cel.ts+++ b/frontend/src/utils/issue/cel.ts@@ -28,7 +28,6 @@ type DatabaseResourceCondition =interface ConditionExpression {databaseResources?: DatabaseResource[];expiredTime?: string;- statement?: string;rowLimit?: number;exportFormat?: string;}@@ -106,13 +105,6 @@ export const stringifyConditionExpression = (`request.time < timestamp("${conditionExpression.expiredTime}")`);}- if (conditionExpression.statement !== undefined) {- expression.push(- `request.statement == "${btoa(- unescape(encodeURIComponent(conditionExpression.statement))- )}"`- );- }if (conditionExpression.rowLimit !== undefined) {expression.push(`request.row_limit <= ${conditionExpression.rowLimit}`);}@@ -239,9 +231,6 @@ export const convertFromCELString = async (if (databaseResource) {databaseResource.schema = right;}- } else if (left === "request.statement") {- const statement = decodeURIComponent(escape(window.atob(right)));- conditionExpression.statement = statement;}} else if (typeof right === "number") {if (left === "request.row_limit") {@@ -328,9 +317,6 @@ export const convertFromExpr = (expr: Expr): ConditionExpression => {if (databaseResource) {databaseResource.schema = right;}- } else if (left === "request.statement") {- const statement = decodeURIComponent(escape(window.atob(right)));- conditionExpression.statement = statement;}} else if (typeof right === "number") {// Deprecated. Use _<=_ instead.