Skip to content

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

fix(frontend): custom roles fixes (#5768)

Liu Ji658eb11037c5
diff --git a/frontend/src/components/ProjectMemberPanel.vue b/frontend/src/components/ProjectMemberPanel.vue
index 38dcb45c1d..f505d91b98 100644
--- a/frontend/src/components/ProjectMemberPanel.vue
+++ b/frontend/src/components/ProjectMemberPanel.vue
@@ -129,7 +129,6 @@ const props = defineProps({
});
const ROLE_OWNER = "roles/OWNER";
-const ROLE_DEVELOPER = "roles/DEVELOPER";
const { t } = useI18n();
const currentUser = useCurrentUser();
const projectResourceName = computed(
@@ -273,7 +272,7 @@ const addMember = async () => {
name: principal.name,
}),
});
- state.roleList = [ROLE_DEVELOPER];
+ state.roleList = [];
state.principalId = undefined;
} finally {
state.adding = false;
diff --git a/frontend/src/components/Role/Setting/RoleSetting.vue b/frontend/src/components/Role/Setting/RoleSetting.vue
index 5fdc9df199..eb4a275152 100644
--- a/frontend/src/components/Role/Setting/RoleSetting.vue
+++ b/frontend/src/components/Role/Setting/RoleSetting.vue
@@ -30,17 +30,25 @@
:mode="state.detail.mode"
@close="state.detail.role = undefined"
/>
+
+ <FeatureModal
+ v-if="showFeatureModal"
+ feature="bb.feature.custom-role"
+ @cancel="showFeatureModal = false"
+ />
</div>
</template>
<script lang="ts" setup>
-import { computed, onMounted, reactive } from "vue";
+import { computed, onMounted, reactive, ref } from "vue";
import { NButton } from "naive-ui";
import { RoleTable, RolePanel } from "./components";
-import { useRoleStore } from "@/store";
+import FeatureModal from "@/components/FeatureModal.vue";
+import { featureToRef, useRoleStore } from "@/store";
import { Role } from "@/types/proto/v1/role_service";
import { useWorkspacePermission } from "@/utils";
+import { provideCustomRoleSettingContext } from "./context";
type LocalState = {
ready: boolean;
@@ -65,6 +73,9 @@ const state = reactive<LocalState>({
},
});
+const hasCustomRoleFeature = featureToRef("bb.feature.custom-role");
+const showFeatureModal = ref(false);
+
const allowAdmin = useWorkspacePermission(
"bb.permission.workspace.manage-general"
);
@@ -99,4 +110,9 @@ const prepare = async () => {
}
};
onMounted(prepare);
+
+provideCustomRoleSettingContext({
+ hasCustomRoleFeature,
+ showFeatureModal,
+});
</script>
diff --git a/frontend/src/components/Role/Setting/components/RolePanel.vue b/frontend/src/components/Role/Setting/components/RolePanel.vue
index 09a48c7cda..1deb24969a 100644
--- a/frontend/src/components/Role/Setting/components/RolePanel.vue
+++ b/frontend/src/components/Role/Setting/components/RolePanel.vue
@@ -79,6 +79,7 @@ import { ResourceIdField } from "@/components/v2";
import { pushNotification, useRoleStore } from "@/store";
import { extractRoleResourceName } from "@/utils";
import { ValidatedMessage } from "@/types";
+import { useCustomRoleSettingContext } from "../context";
type LocalState = {
role: Role;
@@ -98,6 +99,8 @@ const emit = defineEmits<{
const { t } = useI18n();
const resourceIdField = ref<InstanceType<typeof ResourceIdField>>();
const store = useRoleStore();
+const { hasCustomRoleFeature, showFeatureModal } =
+ useCustomRoleSettingContext();
const state = reactive<LocalState>({
role: Role.fromJSON({}),
dirty: false,
@@ -124,6 +127,15 @@ const allowSave = computed(() => {
});
const handleSave = async () => {
+ if (!hasCustomRoleFeature.value) {
+ showFeatureModal.value = true;
+
+ // Getting crazy to adjust the z-indexes of the modal and the panel drawer
+ // so just close the panel drawer here.
+ emit("close");
+ return;
+ }
+
state.loading = true;
try {
await store.upsertRole(state.role);
diff --git a/frontend/src/components/Role/Setting/components/RoleTableRow.vue b/frontend/src/components/Role/Setting/components/RoleTableRow.vue
index 8c4dd02c8c..982fe8df3a 100644
--- a/frontend/src/components/Role/Setting/components/RoleTableRow.vue
+++ b/frontend/src/components/Role/Setting/components/RoleTableRow.vue
@@ -32,6 +32,7 @@ import type { Role } from "@/types/proto/v1/role_service";
import { useWorkspacePermission } from "@/utils";
import { SpinnerButton } from "@/components/v2";
import { useRoleStore } from "@/store";
+import { useCustomRoleSettingContext } from "../context";
const props = defineProps<{
role: Role;
@@ -42,6 +43,8 @@ defineEmits<{
}>();
const { t } = useI18n();
+const { hasCustomRoleFeature, showFeatureModal } =
+ useCustomRoleSettingContext();
const description = computed(() => {
const { role } = props;
@@ -68,6 +71,11 @@ const allowEdit = computed(() => {
});
const deleteRole = async () => {
+ if (!hasCustomRoleFeature.value) {
+ showFeatureModal.value = true;
+ return;
+ }
+
await useRoleStore().deleteRole(props.role);
};
</script>
diff --git a/frontend/src/components/Role/Setting/context.ts b/frontend/src/components/Role/Setting/context.ts
new file mode 100644
index 0000000000..c95878ca16
--- /dev/null
+++ b/frontend/src/components/Role/Setting/context.ts
@@ -0,0 +1,20 @@
+import { type InjectionKey, type Ref, provide, inject } from "vue";
+
+export type CustomRoleSettingContext = {
+ hasCustomRoleFeature: Ref<boolean>;
+ showFeatureModal: Ref<boolean>;
+};
+
+const KEY = Symbol(
+ "bb.settings.custom-role"
+) as InjectionKey<CustomRoleSettingContext>;
+
+export const provideCustomRoleSettingContext = (
+ context: CustomRoleSettingContext
+) => {
+ provide(KEY, context);
+};
+
+export const useCustomRoleSettingContext = () => {
+ return inject(KEY)!;
+};
diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.json
index 148a5a7465..2aea227a1d 100644
--- a/frontend/src/locales/en-US.json
+++ b/frontend/src/locales/en-US.json
@@ -387,7 +387,7 @@
"sensitive-data": "Data Anonymization",
"access-control": "Data Access Control",
"audit-log": "Audit Log",
- "roles": "Roles",
+ "custom-roles": "Custom Roles",
"mail-delivery": "Mail Delivery"
},
"profile": {
@@ -1856,6 +1856,10 @@
"title": "Role management",
"desc": "Role management can assign a particular role (e.g. DBA) to a member."
},
+ "bb-feature-custom-role": {
+ "title": "Custom role",
+ "desc": "Defining custom roles, and you may apply them to project members."
+ },
"bb-feature-watermark": {
"title": "Watermark",
"desc": "Display visible watermarks on pages, including username, ID and email."
diff --git a/frontend/src/locales/es-ES.json b/frontend/src/locales/es-ES.json
index 02edfc920e..bcaf0a036d 100644
--- a/frontend/src/locales/es-ES.json
+++ b/frontend/src/locales/es-ES.json
@@ -379,7 +379,6 @@
"sensitive-data": "Anonimización de Datos",
"access-control": "Control de Acceso a Datos",
"audit-log": "Registro de auditoría",
- "roles": "Roles",
"mail-delivery": "Entrega de Correo"
},
"profile": {
diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.json
index aadc95bfd1..b8430f46d8 100644
--- a/frontend/src/locales/zh-CN.json
+++ b/frontend/src/locales/zh-CN.json
@@ -385,7 +385,7 @@
"sensitive-data": "数据脱敏",
"access-control": "数据访问控制",
"audit-log": "审计日志",
- "roles": "角色",
+ "custom-roles": "自定义角色",
"mail-delivery": "邮件传输"
},
"profile": {
@@ -1854,6 +1854,10 @@
"title": "角色管理",
"desc": "「角色管理」可以赋予成员诸如 DBA 这样的特定角色。"
},
+ "bb-feature-custom-role": {
+ "title": "自定义角色",
+ "desc": "定义自定义角色,你可以将它们应用到项目成员上。"
+ },
"bb-feature-watermark": {
"title": "水印设置",
"desc": "在页面上显示水印,包含用户名、ID 和 Email。"
diff --git a/frontend/src/router/index.ts b/frontend/src/router/index.ts
index 364cc6326f..7671a64528 100644
--- a/frontend/src/router/index.ts
+++ b/frontend/src/router/index.ts
@@ -400,7 +400,7 @@ const routes: Array<RouteRecordRaw> = [
{
path: "role",
name: "setting.workspace.role",
- meta: { title: () => t("settings.sidebar.roles") },
+ meta: { title: () => t("settings.sidebar.custom-roles") },
component: () => import("../views/SettingWorkspaceRole.vue"),
props: true,
},
diff --git a/frontend/src/types/plan.ts b/frontend/src/types/plan.ts
index dbaa234804..94e36d8632 100644
--- a/frontend/src/types/plan.ts
+++ b/frontend/src/types/plan.ts
@@ -7,6 +7,8 @@ import {
// Check api/plan.go to understand what each feature means.
export type FeatureType =
+ // General
+ | "bb.feature.custom-role"
// Admin & Security
| "bb.feature.sso"
| "bb.feature.2fa"
diff --git a/frontend/src/views/SettingSidebar.vue b/frontend/src/views/SettingSidebar.vue
index 4bab0ea22c..a2054bf138 100644
--- a/frontend/src/views/SettingSidebar.vue
+++ b/frontend/src/views/SettingSidebar.vue
@@ -54,7 +54,7 @@
<router-link
to="/setting/role"
class="outline-item group w-full flex items-center pl-11 pr-2 py-2"
- >{{ $t("settings.sidebar.roles") }}</router-link
+ >{{ $t("settings.sidebar.custom-roles") }}</router-link
>
<router-link
v-if="showProjectItem"