Skip to content

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

chore: unify and reuse the AddProjectMemberForm (#19216)

ecmadao3e2aed90c3b6
diff --git a/frontend/src/components/ExpirationSelector.vue b/frontend/src/components/ExpirationSelector.vue
index 5290be7612..605ef8ab75 100644
--- a/frontend/src/components/ExpirationSelector.vue
+++ b/frontend/src/components/ExpirationSelector.vue
@@ -7,29 +7,26 @@
@update:value="onSelect"
/>
- <template v-if="state.selected === -1">
- <div class="flex flex-col gap-y-2">
- <NDatePicker
- size="medium"
- class="w-full"
- :value="state.expirationTimestampInMS"
- :actions="null"
- :update-value-on-close="true"
- type="datetime"
- :is-date-disabled="isDateDisabled"
- clearable
- :placeholder="$t('issue.grant-request.custom-date-placeholder')"
- @update:value="handleCustomDateChange"
- />
- <div v-if="maximumRoleExpiration" class="text-xs text-gray-500">
- {{ $t("settings.general.workspace.maximum-role-expiration.self") }}:
- {{ $t("common.date.days", { days: maximumRoleExpiration }) }}
- </div>
+ <div v-if="state.selected === -1" class="flex flex-col gap-y-2">
+ <NDatePicker
+ size="medium"
+ class="w-full"
+ :value="state.expirationTimestampInMS"
+ :actions="null"
+ :update-value-on-close="true"
+ type="datetime"
+ :is-date-disabled="isDateDisabled"
+ clearable
+ :placeholder="$t('issue.grant-request.custom-date-placeholder')"
+ @update:value="handleCustomDateChange"
+ />
+ <div v-if="maximumRoleExpiration" class="text-xs text-gray-500">
+ {{ $t("settings.general.workspace.maximum-role-expiration.self") }}:
+ {{ $t("common.date.days", { days: maximumRoleExpiration }) }}
</div>
- </template>
-
+ </div>
<div
- v-if="state.selected !== -1"
+ v-else
class="p-3 bg-gray-50 rounded-md text-sm text-gray-600"
>
<div v-if="state.expirationTimestampInMS">
@@ -67,6 +64,7 @@ interface LocalState {
const props = defineProps<{
timestampInMs?: number;
role: string;
+ useCachedSelection?: boolean;
}>();
const emit = defineEmits<{
@@ -88,6 +86,9 @@ const getInitialSelection = () => {
// If timestamp is provided, use custom date
return -1;
}
+ if (!props.useCachedSelection) {
+ return 0;
+ }
// Otherwise, use the last selected value if it's still valid
return lastSelectedExpiration.value;
};
diff --git a/frontend/src/components/GrantRequestPanel/GrantRequestPanel.vue b/frontend/src/components/GrantRequestPanel/GrantRequestPanel.vue
index 88860ad1b3..4fdb68c608 100644
--- a/frontend/src/components/GrantRequestPanel/GrantRequestPanel.vue
+++ b/frontend/src/components/GrantRequestPanel/GrantRequestPanel.vue
@@ -16,7 +16,6 @@
class="w-full"
:project-name="projectName"
:binding="binding"
- :allow-remove="false"
:disable-member-change="true"
:require-reason="project.enforceIssueTitle"
:database-resources="databaseResources"
diff --git a/frontend/src/components/ProjectMember/AddProjectMember/AddProjectMemberForm.vue b/frontend/src/components/ProjectMember/AddProjectMember/AddProjectMemberForm.vue
index ca87da01c9..b18f786507 100644
--- a/frontend/src/components/ProjectMember/AddProjectMember/AddProjectMemberForm.vue
+++ b/frontend/src/components/ProjectMember/AddProjectMember/AddProjectMemberForm.vue
@@ -5,15 +5,7 @@
:required="true"
:include-all-users="true"
:disabled="disableMemberChange"
- >
- <template #suffix>
- <NButton v-if="allowRemove" text @click="$emit('remove')">
- <template #icon>
- <heroicons:trash class="w-4 h-4" />
- </template>
- </NButton>
- </template>
- </MembersBindingSelect>
+ />
<div class="w-full flex flex-col gap-y-2">
<div class="flex items-center gap-x-1">
@@ -39,6 +31,7 @@
:include-workspace-roles="false"
:suffix="''"
:filter="filterRole"
+ :disabled="disableRoleChange"
/>
</div>
<div v-if="selectedRole" class="w-full flex flex-col gap-y-2">
@@ -84,7 +77,7 @@
</div>
<QuerierDatabaseResourceForm
ref="databaseResourceFormRef"
- :database-resources="databaseResources"
+ :database-resources="databaseResourceList"
:project-name="projectName"
:required-feature="PlanFeature.FEATURE_IAM"
:include-cloumn="false"
@@ -99,6 +92,7 @@
<ExpirationSelector
ref="expirationSelectorRef"
:role="state.role"
+ :use-cached-selection="!isEdit"
v-model:timestamp-in-ms="state.expirationTimestampInMS"
class="grid-cols-3 sm:grid-cols-4"
/>
@@ -108,7 +102,7 @@
<script lang="ts" setup>
import { create } from "@bufbuild/protobuf";
-import { NButton, NInput } from "naive-ui";
+import { NInput } from "naive-ui";
import { computed, reactive, ref } from "vue";
import { BBAttention } from "@/bbkit";
import ExpirationSelector from "@/components/ExpirationSelector.vue";
@@ -121,28 +115,18 @@ import { type DatabaseResource } from "@/types";
import { type Binding, BindingSchema } from "@/types/proto-es/v1/iam_policy_pb";
import type { Role } from "@/types/proto-es/v1/role_service_pb";
import { PlanFeature } from "@/types/proto-es/v1/subscription_service_pb";
-import { buildConditionExpr } from "@/utils/issue/cel";
+import { buildConditionExpr, convertFromExpr } from "@/utils/issue/cel";
import { roleHasDatabaseLimitation } from "../utils";
-const props = withDefaults(
- defineProps<{
- projectName: string;
- binding: Binding;
- allowRemove: boolean;
- requireReason?: boolean;
- disableMemberChange?: boolean;
- requiredPermissions?: string[];
- databaseResources?: DatabaseResource[];
- }>(),
- {
- disableMemberChange: false,
- requireReason: false,
- databaseResources: () => [],
- }
-);
-
-defineEmits<{
- (event: "remove"): void;
+const props = defineProps<{
+ projectName: string;
+ binding: Binding;
+ isEdit?: boolean;
+ requireReason?: boolean;
+ disableRoleChange?: boolean;
+ disableMemberChange?: boolean;
+ requiredPermissions?: string[];
+ databaseResources?: DatabaseResource[];
}>();
interface LocalState {
@@ -150,7 +134,7 @@ interface LocalState {
role: string;
reason: string;
expirationTimestampInMS?: number;
- databaseId?: string;
+ environments?: string[];
}
const filterRole = (role: Role) => {
@@ -164,13 +148,34 @@ const getInitialState = (): LocalState => {
const defaultState: LocalState = {
role: props.binding.role,
memberList: props.binding.members,
- reason: "",
+ reason: props.binding.condition?.description ?? "",
};
+ if (props.binding.parsedExpr) {
+ const conditionExpr = convertFromExpr(props.binding.parsedExpr);
+ if (conditionExpr.expiredTime) {
+ defaultState.expirationTimestampInMS = new Date(
+ conditionExpr.expiredTime
+ ).getTime();
+ }
+ }
+
return defaultState;
};
const state = reactive<LocalState>(getInitialState());
+
+const databaseResourceList = computed(() => {
+ if (props.databaseResources !== undefined) {
+ return props.databaseResources;
+ }
+ if (props.binding.parsedExpr) {
+ const conditionExpr = convertFromExpr(props.binding.parsedExpr);
+ return conditionExpr.databaseResources;
+ }
+ return [];
+});
+
const expirationSelectorRef = ref<InstanceType<typeof ExpirationSelector>>();
const databaseResourceFormRef =
ref<InstanceType<typeof QuerierDatabaseResourceForm>>();
@@ -185,10 +190,11 @@ defineExpose({
await databaseResourceFormRef.value?.getDatabaseResources();
return resources;
},
- getBinding: async (): Promise<Binding> => {
+ getBinding: async (title: string = ""): Promise<Binding> => {
const databaseResources =
await databaseResourceFormRef.value?.getDatabaseResources();
const condition = buildConditionExpr({
+ title,
role: state.role,
description: state.reason,
expirationTimestampInMS: state.expirationTimestampInMS,
diff --git a/frontend/src/components/ProjectMember/AddProjectMember/AddProjectMembersPanel.vue b/frontend/src/components/ProjectMember/AddProjectMember/AddProjectMembersPanel.vue
index efe0b66e37..49f204761c 100644
--- a/frontend/src/components/ProjectMember/AddProjectMember/AddProjectMembersPanel.vue
+++ b/frontend/src/components/ProjectMember/AddProjectMember/AddProjectMembersPanel.vue
@@ -12,17 +12,27 @@
<div
v-for="(binding, index) in state.bindings"
:key="index"
- class="w-full"
+ class="w-full border-b mb-4 pb-4 flex flex-col gap-y-2 items-start"
>
<AddProjectMemberForm
v-if="binding"
ref="formRefs"
- class="w-full border-b mb-4 pb-4"
+ class="w-full"
:project-name="project.name"
:binding="binding"
- :allow-remove="state.bindings.length > 1"
- @remove="handleRemove(index)"
/>
+ <NButton
+ v-if="state.bindings.length > 1"
+ tertiary
+ type="error"
+ size="small"
+ @click="handleRemove(index)"
+ >
+ <template #icon>
+ <heroicons:trash class="w-4 h-4" />
+ </template>
+ {{ $t("common.remove") }}
+ </NButton>
</div>
<div>
<NButton @click="handleAddMore">
diff --git a/frontend/src/components/ProjectMember/ProjectMemberRolePanel/EditProjectRolePanel.vue b/frontend/src/components/ProjectMember/ProjectMemberRolePanel/EditProjectRolePanel.vue
index f4f2b877ad..a7eaf9ab0b 100644
--- a/frontend/src/components/ProjectMember/ProjectMemberRolePanel/EditProjectRolePanel.vue
+++ b/frontend/src/components/ProjectMember/ProjectMemberRolePanel/EditProjectRolePanel.vue
@@ -15,60 +15,20 @@
<span>{{ $t("project.members.condition-name") }}</span>
</p>
<NInput
- v-model:value="state.title"
+ v-model:value="title"
type="text"
:placeholder="displayRoleTitle(binding.role)"
/>
</div>
- <template v-if="!state.isLoading">
- <div
- v-if="
- binding.role !== PresetRoleType.PROJECT_OWNER &&
- checkRoleContainsAnyPermission(binding.role, 'bb.sql.select')
- "
- class="w-full"
- >
- <div class="flex items-center gap-x-1 mb-2">
- <span>{{ $t("common.databases") }}</span>
- <RequiredStar />
- </div>
- <QuerierDatabaseResourceForm
- ref="databaseResourceFormRef"
- :database-resources="databaseResources"
- :project-name="project.name"
- :include-cloumn="false"
- :required-feature="PlanFeature.FEATURE_IAM"
- />
- </div>
- </template>
-
- <div class="w-full">
- <p class="mb-2">{{ $t("common.description") }}</p>
- <NInput
- v-model:value="state.description"
- type="textarea"
- :placeholder="$t('project.members.role-description')"
- />
- </div>
-
- <div class="w-full">
- <p class="mb-2">{{ $t("common.expiration") }}</p>
- <ExpirationSelector
- v-if="!state.isLoading"
- ref="expirationSelectorRef"
- :role="binding.role"
- v-model:timestamp-in-ms="state.expirationTimestamp"
- class="grid-cols-3 sm:grid-cols-4"
- />
- </div>
-
- <MembersBindingSelect
- :value="binding.members"
- :disabled="true"
- :required="true"
- :allow-change-type="false"
- :include-all-users="true"
+ <AddProjectMemberForm
+ ref="formRef"
+ class="w-full"
+ :project-name="projectResourceName"
+ :binding="binding"
+ :is-edit="true"
+ :disable-role-change="true"
+ :disable-member-change="true"
/>
</div>
<template #footer>
@@ -89,7 +49,7 @@
:disabled="!allowConfirm"
@click="handleUpdateRole"
>
- {{ $t("common.ok") }}
+ {{ $t("common.update") }}
</NButton>
</div>
</div>
@@ -101,26 +61,20 @@
<script lang="ts" setup>
import { cloneDeep, isEqual } from "lodash-es";
import { NButton, NInput } from "naive-ui";
-import { computed, onMounted, reactive, ref } from "vue";
+import { computed, onMounted, ref } from "vue";
import { useI18n } from "vue-i18n";
import { BBButtonConfirm } from "@/bbkit";
-import ExpirationSelector from "@/components/ExpirationSelector.vue";
-import QuerierDatabaseResourceForm from "@/components/GrantRequestPanel/DatabaseResourceForm/index.vue";
-import MembersBindingSelect from "@/components/Member/MembersBindingSelect.vue";
-import RequiredStar from "@/components/RequiredStar.vue";
+import AddProjectMemberForm from "@/components/ProjectMember/AddProjectMember/AddProjectMemberForm.vue";
import { Drawer, DrawerContent } from "@/components/v2";
import {
pushNotification,
useProjectIamPolicy,
useProjectIamPolicyStore,
} from "@/store";
-import { PresetRoleType } from "@/types";
import { State } from "@/types/proto-es/v1/common_pb";
import type { Binding } from "@/types/proto-es/v1/iam_policy_pb";
import type { Project } from "@/types/proto-es/v1/project_service_pb";
-import { PlanFeature } from "@/types/proto-es/v1/subscription_service_pb";
-import { checkRoleContainsAnyPermission, displayRoleTitle } from "@/utils";
-import { buildConditionExpr, convertFromExpr } from "@/utils/issue/cel";
+import { displayRoleTitle } from "@/utils";
import { getBindingIdentifier } from "../utils";
const props = defineProps<{
@@ -132,23 +86,9 @@ const emit = defineEmits<{
(event: "close"): void;
}>();
-interface LocalState {
- title: string;
- description: string;
- expirationTimestamp?: number;
- isLoading: boolean;
-}
-
const { t } = useI18n();
-
-const state = reactive<LocalState>({
- title: "",
- description: "",
- isLoading: true,
-});
-const expirationSelectorRef = ref<InstanceType<typeof ExpirationSelector>>();
-const databaseResourceFormRef =
- ref<InstanceType<typeof QuerierDatabaseResourceForm>>();
+const title = ref<string>("");
+const formRef = ref<InstanceType<typeof AddProjectMemberForm>>();
const projectResourceName = computed(() => props.project.name);
const { policy: iamPolicy } = useProjectIamPolicy(projectResourceName);
@@ -173,35 +113,13 @@ const allowRemoveRole = () => {
const allowConfirm = computed(() => {
// only allow update current single user.
- return (
- props.binding.members.length === 1 &&
- expirationSelectorRef.value?.isValid &&
- databaseResourceFormRef.value?.isValid
- );
-});
-
-const databaseResources = computed(() => {
- if (props.binding.parsedExpr) {
- const conditionExpr = convertFromExpr(props.binding.parsedExpr);
- return conditionExpr.databaseResources;
- }
- return undefined;
+ return props.binding.members.length === 1 && formRef.value?.allowConfirm;
});
onMounted(() => {
const binding = props.binding;
// Set the display title with the role name.
- state.title = binding.condition?.title || "";
- state.description = binding.condition?.description || "";
-
- if (binding.parsedExpr) {
- const conditionExpr = convertFromExpr(binding.parsedExpr);
- if (conditionExpr.expiredTime) {
- state.expirationTimestamp = new Date(conditionExpr.expiredTime).getTime();
- }
- }
-
- state.isLoading = false;
+ title.value = binding.condition?.title || displayRoleTitle(binding.role);
});
const handleDeleteRole = async () => {
@@ -217,20 +135,11 @@ const handleDeleteRole = async () => {
};
const handleUpdateRole = async () => {
- const member = props.binding.members[0];
-
- const newBinding = cloneDeep(props.binding);
- newBinding.members = [member];
-
- const databaseResources =
- await databaseResourceFormRef.value?.getDatabaseResources();
- newBinding.condition = buildConditionExpr({
- title: state.title,
- role: props.binding.role,
- description: state.description,
- expirationTimestampInMS: state.expirationTimestamp,
- databaseResources,
- });
+ const binding = await formRef.value?.getBinding(title.value);
+ if (!binding) {
+ return;
+ }
+ const member = binding.members[0];
const policy = cloneDeep(iamPolicy.value);
const oldBindingIndex = policy.bindings.findIndex(
@@ -247,7 +156,7 @@ const handleUpdateRole = async () => {
}
}
- policy.bindings.push(newBinding);
+ policy.bindings.push(binding);
await useProjectIamPolicyStore().updateProjectIamPolicy(
projectResourceName.value,
diff --git a/frontend/src/components/SensitiveData/GlobalMaskingRulesView.vue b/frontend/src/components/SensitiveData/GlobalMaskingRulesView.vue
index 17a401d824..ed37a5ea30 100644
--- a/frontend/src/components/SensitiveData/GlobalMaskingRulesView.vue
+++ b/frontend/src/components/SensitiveData/GlobalMaskingRulesView.vue
@@ -95,7 +95,7 @@
class="pb-5"
:class="[
'w-full',
- item.mode === 'NORMAL' ? '' : 'ml-[42px]',
+ item.mode === 'NORMAL' ? '' : 'ml-10.5',
index === state.maskingRuleItemList.length - 1 ? '' : 'border-b',
]"
>
diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.json
index 8898a619b0..f174c9f8e4 100644
--- a/frontend/src/locales/en-US.json
+++ b/frontend/src/locales/en-US.json
@@ -246,6 +246,7 @@
"title": "Title",
"text-wrap": "Text Wrap",
"catalog": "Catalog",
+ "remove": "Remove",
"removed": "Removed",
"submit": "Submit",
"draft": "Draft",
@@ -1891,7 +1892,6 @@
"view-by-roles": "View by roles",
"revoke-role-from-user": "Revoke '{role}' from '{user}'",
"never-expires": "Never",
- "role-description": "Role description",
"role-never-expires": "This role never expires.",
"add-more": "Add more",
"condition-name": "Condition name",
diff --git a/frontend/src/locales/es-ES.json b/frontend/src/locales/es-ES.json
index 238ab227eb..84cc6b60a5 100644
--- a/frontend/src/locales/es-ES.json
+++ b/frontend/src/locales/es-ES.json
@@ -239,6 +239,7 @@
"title": "Título",
"text-wrap": "Ajuste de texto",
"catalog": "Catálogo",
+ "remove": "Eliminar",
"removed": "Eliminado",
"submit": "Enviar",
"draft": "Borrador",
@@ -1891,7 +1892,6 @@
"view-by-roles": "Ver por roles",
"revoke-role-from-user": "Revocar '{role}' de '{user}'",
"never-expires": "Nunca caduca",
- "role-description": "El rol de un miembro determina qué puede hacer en el proyecto.",
"role-never-expires": "Este rol nunca expira.",
"add-more": "Agregar más",
"condition-name": "Nombre de la condición",
diff --git a/frontend/src/locales/ja-JP.json b/frontend/src/locales/ja-JP.json
index 1afe285cee..bc39635a1c 100644
--- a/frontend/src/locales/ja-JP.json
+++ b/frontend/src/locales/ja-JP.json
@@ -239,6 +239,7 @@
"title": "タイトル",
"text-wrap": "テキストの折り返し",
"catalog": "カタログ",
+ "remove": "削除",
"removed": "削除されました",
"submit": "提出する",
"draft": "下書き",
@@ -1891,7 +1892,6 @@
"view-by-roles": "ロールごとに表示",
"revoke-role-from-user": "「{user}」{role} のロールを削除します",
"never-expires": "有効期限が切れることはありません",
- "role-description": "ロールの説明",
"role-never-expires": "このロールには有効期限はありません。",
"add-more": "さらに追加",
"condition-name": "条件名",
diff --git a/frontend/src/locales/vi-VN.json b/frontend/src/locales/vi-VN.json
index b41f2504bd..3a979fbae5 100644
--- a/frontend/src/locales/vi-VN.json
+++ b/frontend/src/locales/vi-VN.json
@@ -239,6 +239,7 @@
"title": "Tiêu đề",
"text-wrap": "Ngắt dòng văn bản",
"catalog": "Danh mục",
+ "remove": "Xóa",
"removed": "LOẠI BỎ",
"submit": "Nộp",
"draft": "Bản nháp",
@@ -1891,7 +1892,6 @@
"view-by-roles": "Xem theo vai trò",
"revoke-role-from-user": "Thu hồi '{role}' từ '{user}'",
"never-expires": "Không bao giờ",
- "role-description": "Mô tả vai trò",
"role-never-expires": "Vai trò này không bao giờ hết hạn.",
"add-more": "Thêm",
"condition-name": "Tên điều kiện",
diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.json
index d0449f772c..11fc8709e3 100644
--- a/frontend/src/locales/zh-CN.json
+++ b/frontend/src/locales/zh-CN.json
@@ -239,6 +239,7 @@
"title": "标题",
"text-wrap": "文本折行",
"catalog": "Catalog",
+ "remove": "移除",
"removed": "已移除",
"submit": "提交",
"draft": "草稿",
@@ -1891,7 +1892,6 @@
"view-by-roles": "按角色查看",
"revoke-role-from-user": "删除'{user}'{role}的角色",
"never-expires": "永不过期",
- "role-description": "角色描述",
"role-never-expires": "此角色没有过期时间。",
"add-more": "增加更多",
"condition-name": "条件名称",
diff --git a/frontend/src/store/modules/v1/common.ts b/frontend/src/store/modules/v1/common.ts
index 490693db72..146c2432a1 100644
--- a/frontend/src/store/modules/v1/common.ts
+++ b/frontend/src/store/modules/v1/common.ts
@@ -63,6 +63,12 @@ export const getNameParentTokens = (
return tokens;
};
+export const getEnvironmentId = (name: string): string => {
+ const tokens = getNameParentTokens(name, [environmentNamePrefix]);
+ const envId = tokens[0];
+ return envId;
+};
+
export const getUserId = (name: string): number => {
const tokens = getNameParentTokens(name, [userNamePrefix]);
const userId = Number(tokens[0] || UNKNOWN_ID);
diff --git a/frontend/src/store/modules/v1/environment.ts b/frontend/src/store/modules/v1/environment.ts
index d23695ad73..8aba98dcbc 100644
--- a/frontend/src/store/modules/v1/environment.ts
+++ b/frontend/src/store/modules/v1/environment.ts
@@ -20,7 +20,7 @@ import {
} from "@/types/proto-es/v1/setting_service_pb";
import type { Environment } from "@/types/v1/environment";
import { hasWorkspacePermissionV2 } from "@/utils";
-import { environmentNamePrefix } from "./common";
+import { environmentNamePrefix, getEnvironmentId } from "./common";
import { useSettingV1Store } from "./setting";
interface EnvironmentState {
@@ -181,7 +181,7 @@ export const useEnvironmentV1Store = defineStore("environment_v1", {
return newEnvironment;
},
async deleteEnvironment(name: string): Promise<void> {
- const id = name.replace(environmentNamePrefix, "");
+ const id = getEnvironmentId(name);
const newEnvironments = await updateEnvironmentSetting(
create(EnvironmentSettingSchema, {
environments: convertEnvironments(
@@ -206,7 +206,7 @@ export const useEnvironmentV1Store = defineStore("environment_v1", {
if (name === NULL_ENVIRONMENT_NAME) {
return nullEnvironment();
}
- const id = name.replace(environmentNamePrefix, "");
+ const id = getEnvironmentId(name);
if (!id) {
return unknownEnvironment();
}
diff --git a/frontend/src/utils/issue/cel.ts b/frontend/src/utils/issue/cel.ts
index 932cab8e63..2c1c553bf8 100644
--- a/frontend/src/utils/issue/cel.ts
+++ b/frontend/src/utils/issue/cel.ts
@@ -5,6 +5,7 @@ import type { SimpleExpr } from "@/plugins/cel";
import { isRawStringExpr, resolveCELExpr } from "@/plugins/cel";
import {
databaseNamePrefix,
+ getEnvironmentId,
instanceNamePrefix,
} from "@/store/modules/v1/common";
import type { DatabaseResource } from "@/types";
@@ -21,6 +22,7 @@ import {
CEL_ATTRIBUTE_RESOURCE_COLUMN_NAME,
CEL_ATTRIBUTE_RESOURCE_DATABASE,
CEL_ATTRIBUTE_RESOURCE_DATABASE_NAME,
+ CEL_ATTRIBUTE_RESOURCE_ENVIRONMENT_ID,
CEL_ATTRIBUTE_RESOURCE_INSTANCE_ID,
CEL_ATTRIBUTE_RESOURCE_SCHEMA_NAME,
CEL_ATTRIBUTE_RESOURCE_TABLE_NAME,
@@ -125,16 +127,19 @@ export const buildConditionExpr = ({
description,
expirationTimestampInMS,
databaseResources,
+ environments,
}: {
title?: string;
role: string;
description: string;
expirationTimestampInMS?: number;
databaseResources?: DatabaseResource[];
+ environments?: string[];
}): ConditionExpr => {
const expresson = stringifyConditionExpression({
expirationTimestampInMS,
databaseResources,
+ environments,
});
return create(ConditionExprSchema, {
title:
@@ -220,9 +225,11 @@ const stringifyDatabaseResources = (resources: DatabaseResource[]) => {
export const stringifyConditionExpression = ({
expirationTimestampInMS,
databaseResources,
+ environments,
}: {
expirationTimestampInMS?: number;
databaseResources?: DatabaseResource[];
+ environments?: string[];
}): string => {
const expression: string[] = [];
if (databaseResources !== undefined && databaseResources.length > 0) {
@@ -233,6 +240,11 @@ export const stringifyConditionExpression = ({
`${CEL_ATTRIBUTE_REQUEST_TIME} < timestamp("${dayjs(expirationTimestampInMS).toISOString()}")`
);
}
+ if (environments && environments.length > 0) {
+ expression.push(
+ `${CEL_ATTRIBUTE_RESOURCE_ENVIRONMENT_ID} in [${environments.map((env) => `"${getEnvironmentId(env)}"`)}]`
+ );
+ }
return expression.join(" && ");
};
diff --git a/frontend/src/views/InstanceDashboard.vue b/frontend/src/views/InstanceDashboard.vue
index 0a001369df..9ffefccca4 100644
--- a/frontend/src/views/InstanceDashboard.vue
+++ b/frontend/src/views/InstanceDashboard.vue
@@ -63,7 +63,7 @@
>
<DrawerContent
:title="$t('quick-action.add-instance')"
- class="w-[850px] max-w-[100vw]"
+ class="w-212.5 max-w-[100vw]"
>
<InstanceFormBody />
<template #footer>