Skip to content

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

feat(frontend): implement custom permissions in custom roles (#10464)

boojackc85eb244faa0
diff --git a/frontend/src/components/Role/Setting/components/RolePanel.vue b/frontend/src/components/Role/Setting/components/RolePanel.vue
index c2243ddcaa..939fdfb856 100644
--- a/frontend/src/components/Role/Setting/components/RolePanel.vue
+++ b/frontend/src/components/Role/Setting/components/RolePanel.vue
@@ -7,7 +7,7 @@
<DrawerContent
:title="mode === 'ADD' ? $t('role.setting.add') : $t('role.setting.edit')"
:closable="true"
- class="w-[30rem] max-w-[100vw] relative"
+ class="w-[44rem] max-w-[100vw] relative"
>
<div class="flex flex-col gap-y-4">
<div class="flex flex-col gap-y-2">
@@ -41,11 +41,47 @@
<NInput
v-model:value="state.role.description"
type="textarea"
- :autosize="{ minRows: 3, maxRows: 10 }"
+ :autosize="{ minRows: 2, maxRows: 4 }"
:placeholder="$t('role.setting.description-placeholder')"
/>
</div>
</div>
+
+ <div v-if="isDevelopmentIAM" class="flex flex-col gap-y-2">
+ <div class="textlabel">
+ {{ $t("common.permissions") }}
+ <span class="ml-0.5 text-error">*</span>
+ </div>
+ <div>
+ <span class="textinfolabel mr-2">{{ $t("common.type") }}</span>
+ <NRadio
+ :checked="state.permissionType === 'WORKSPACE'"
+ value="WORKSPACE"
+ @change="state.permissionType = 'WORKSPACE'"
+ >
+ <div class="flex flex-row justify-start items-center">
+ <BuildingIcon class="w-4 h-auto mr-1" />
+ <span>{{ $t("common.workspace") }}</span>
+ </div>
+ </NRadio>
+ <NRadio
+ :checked="state.permissionType === 'PROJECT'"
+ value="PROJECT"
+ @change="state.permissionType = 'PROJECT'"
+ >
+ <div class="flex flex-row justify-start items-center">
+ <GalleryHorizontalEndIcon class="w-4 h-auto mr-1" />
+ <span>{{ $t("common.project") }}</span>
+ </div>
+ </NRadio>
+ </div>
+ <NTransfer
+ v-model:value="state.role.permissions"
+ class="!h-[24rem]"
+ source-filterable
+ :options="permissionOptions"
+ />
+ </div>
</div>
<div
@@ -69,18 +105,24 @@
<script setup lang="ts">
import { cloneDeep } from "lodash-es";
-import { NButton, NInput } from "naive-ui";
+import { BuildingIcon, GalleryHorizontalEndIcon } from "lucide-vue-next";
+import { NButton, NInput, NRadio, NTransfer } from "naive-ui";
import { computed, reactive, watch, nextTick, ref } from "vue";
import { useI18n } from "vue-i18n";
import { Drawer, DrawerContent, ResourceIdField } from "@/components/v2";
-import { pushNotification, useRoleStore } from "@/store";
-import { ValidatedMessage } from "@/types";
+import { pushNotification, useActuatorV1Store, useRoleStore } from "@/store";
+import {
+ PROJECT_PERMISSIONS,
+ ValidatedMessage,
+ WORKSPACE_PERMISSIONS,
+} from "@/types";
import { Role } from "@/types/proto/v1/role_service";
import { extractRoleResourceName } from "@/utils";
import { useCustomRoleSettingContext } from "../context";
type LocalState = {
role: Role;
+ permissionType: "WORKSPACE" | "PROJECT";
dirty: boolean;
loading: boolean;
};
@@ -95,16 +137,20 @@ const emit = defineEmits<{
}>();
const { t } = useI18n();
+const actuatorStore = useActuatorV1Store();
const resourceIdField = ref<InstanceType<typeof ResourceIdField>>();
const roleStore = useRoleStore();
const { hasCustomRoleFeature, showFeatureModal } =
useCustomRoleSettingContext();
const state = reactive<LocalState>({
role: Role.fromJSON({}),
+ permissionType: "WORKSPACE",
dirty: false,
loading: false,
});
+const isDevelopmentIAM = computed(() => actuatorStore.serverInfo?.iamGuard);
+
const resourceId = computed({
get() {
return extractRoleResourceName(state.role.name);
@@ -114,6 +160,28 @@ const resourceId = computed({
},
});
+const permissionOptions = computed(() => {
+ return state.permissionType === "WORKSPACE"
+ ? WORKSPACE_PERMISSIONS.map((p) => ({
+ label: p,
+ value: p,
+ }))
+ : PROJECT_PERMISSIONS.map((p) => ({
+ label: p,
+ value: p,
+ }));
+});
+
+const filteredPermissions = computed(() => {
+ return state.role.permissions.filter((p) => {
+ if (state.permissionType === "WORKSPACE") {
+ return WORKSPACE_PERMISSIONS.includes(p as any);
+ } else {
+ return PROJECT_PERMISSIONS.includes(p as any);
+ }
+ });
+});
+
const allowSave = computed(() => {
if (!state.dirty) return false;
if (state.role.title?.length === 0) return false;
@@ -121,6 +189,9 @@ const allowSave = computed(() => {
if (!resourceIdField.value.resourceId) return false;
if (!resourceIdField.value.isValidated) return false;
}
+ if (filteredPermissions.value.length === 0) {
+ return false;
+ }
return true;
});
@@ -136,6 +207,7 @@ const handleSave = async () => {
state.loading = true;
try {
+ state.role.permissions = filteredPermissions.value;
state.role = await roleStore.upsertRole(state.role);
pushNotification({
module: "bytebase",
@@ -172,6 +244,13 @@ watch(
if (!state.role.title) {
state.role.title = extractRoleResourceName(state.role.name);
}
+ if (state.role.permissions.length > 0) {
+ state.permissionType = WORKSPACE_PERMISSIONS.includes(
+ state.role.permissions[0] as any
+ )
+ ? "WORKSPACE"
+ : "PROJECT";
+ }
}
nextTick(() => {
state.dirty = false;
@@ -183,7 +262,7 @@ watch(
);
watch(
- () => state.role,
+ () => [state.role, state.permissionType],
() => {
state.dirty = true;
},
diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.json
index 664dfe1525..e65d31cc75 100644
--- a/frontend/src/locales/en-US.json
+++ b/frontend/src/locales/en-US.json
@@ -272,7 +272,8 @@
"untitled": "Untitled",
"nickname": "Nickname",
"missing-permission": "Missing required permissions",
- "continue-anyway": "Continue anyway"
+ "continue-anyway": "Continue anyway",
+ "permissions": "Permissions"
},
"error-page": {
"go-back-home": "Go back home"
diff --git a/frontend/src/locales/es-ES.json b/frontend/src/locales/es-ES.json
index 9a4ed82ff9..7e24130017 100644
--- a/frontend/src/locales/es-ES.json
+++ b/frontend/src/locales/es-ES.json
@@ -272,7 +272,8 @@
"untitled": "Intitulado",
"nickname": "Apodo",
"missing-permission": "Faltan permisos requeridos",
- "continue-anyway": "De todas maneras, continúe"
+ "continue-anyway": "De todas maneras, continúe",
+ "permissions": "Permisos"
},
"error-page": {
"go-back-home": "Volver al inicio"
diff --git a/frontend/src/locales/ja-JP.json b/frontend/src/locales/ja-JP.json
index 9566a6dc37..9838ac4bda 100644
--- a/frontend/src/locales/ja-JP.json
+++ b/frontend/src/locales/ja-JP.json
@@ -271,7 +271,8 @@
"nothing-changed": "変更なし",
"untitled": "無題",
"nickname": "ニックネーム",
- "missing-permission": "必要な権限が不足しています"
+ "missing-permission": "必要な権限が不足しています",
+ "permissions": "権限"
},
"error-page": {
"go-back-home": "ホームに戻る"
diff --git a/frontend/src/locales/vi-VN.json b/frontend/src/locales/vi-VN.json
index b325578306..db1059e1e7 100644
--- a/frontend/src/locales/vi-VN.json
+++ b/frontend/src/locales/vi-VN.json
@@ -272,7 +272,8 @@
"untitled": "Không có tiêu đề",
"nickname": "Tên nick",
"missing-permission": "Thiếu quyền cần thiết",
- "continue-anyway": "Vẫn tiếp tục"
+ "continue-anyway": "Vẫn tiếp tục",
+ "permissions": "Quyền"
},
"error-page": {
"go-back-home": "Trở về nhà"
diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.json
index e6279dd184..a205aac2b0 100644
--- a/frontend/src/locales/zh-CN.json
+++ b/frontend/src/locales/zh-CN.json
@@ -270,7 +270,8 @@
"untitled": "未命名",
"nickname": "昵称",
"missing-permission": "缺少必需的权限",
- "continue-anyway": "仍要继续"
+ "continue-anyway": "仍要继续",
+ "permissions": "权限"
},
"error-page": {
"go-back-home": "回到主页"
diff --git a/frontend/src/store/modules/role.ts b/frontend/src/store/modules/role.ts
index 278a3424c7..55e17d5573 100644
--- a/frontend/src/store/modules/role.ts
+++ b/frontend/src/store/modules/role.ts
@@ -24,7 +24,7 @@ export const useRoleStore = defineStore("role", () => {
// update
const updated = await roleServiceClient.updateRole({
role,
- updateMask: ["title", "description"],
+ updateMask: ["title", "description", "permissions"],
});
const index = roleList.value.findIndex((r) => r.name === role.name);
if (index >= 0) {