Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
feat(frontend): allow using custom role for environment rollout releaser policy (#10229)
Liu Jid51a40bd394b
diff --git a/frontend/src/components/EnvironmentForm/RolloutPolicyConfig.vue b/frontend/src/components/EnvironmentForm/RolloutPolicyConfig.vueindex 7dc2308eb1..90987ba61c 100644--- a/frontend/src/components/EnvironmentForm/RolloutPolicyConfig.vue+++ b/frontend/src/components/EnvironmentForm/RolloutPolicyConfig.vue@@ -1,8 +1,8 @@<template>- <div class="flex flex-col gap-y-2">+ <div class="flex flex-col items-start gap-y-2"><div class="flex flex-col gap-y-2"><NRadio- :checked="rolloutPolicy.automatic"+ :checked="isAutomaticRolloutChecked":disabled="disabled"style="--n-label-padding: 0 0 0 1rem"@update:checked="selectAutomaticRollout"@@ -103,6 +103,33 @@{{ $t("policy.rollout.manual-by-issue-creator") }}</div></NCheckbox>+ <div class="flex flex-col gap-y-1">+ <NCheckbox+ :checked="customProjectRoles.checked"+ :disabled="disabled"+ style="--n-label-padding: 0 0 0 1rem"+ @update:checked="toggleCustomProjectRoles($event)"+ >+ <div class="textlabel">+ {{ $t("policy.rollout.manual-by-custom-project-roles") }}+ </div>+ </NCheckbox>+ <div v-if="customProjectRoles.checked" class="pl-8">+ <ProjectRoleSelect+ :roles="customProjectRoles.roles"+ :multiple="true"+ :filter="filterProjectRole"+ :status="+ customProjectRoles.roles.length === 0 ? 'error' : undefined+ "+ :tooltip-props="{+ placement: 'right',+ }"+ style="width: 24rem"+ @update:roles="handleUpdateCustomProjectRoles"+ />+ </div>+ </div></div></div><div class="flex flex-col gap-y-2">@@ -128,6 +155,7 @@ import { ref, watch } from "vue";import { computed } from "vue";import { PresetRoleType, VirtualRoleType } from "@/types";import { Policy, RolloutPolicy } from "@/types/proto/v1/org_policy_service";+import { Role } from "@/types/proto/v1/role_service";import FeatureBadge from "../FeatureGuard/FeatureBadge.vue";const props = defineProps<{@@ -139,7 +167,14 @@ const emit = defineEmits<{}>();const rolloutPolicy = ref(cloneDeep(props.policy.rolloutPolicy!));+const PresetProjectRoles = [+ PresetRoleType.PROJECT_OWNER,+ PresetRoleType.PROJECT_RELEASER,+];+const isAutomaticRolloutChecked = computed(() => {+ return rolloutPolicy.value.automatic && !customProjectRoles.value.checked;+});const isDBAChecked = computed(() => {return rolloutPolicy.value.workspaceRoles.includes(VirtualRoleType.WORKSPACE_DBA@@ -163,10 +198,31 @@ const isProjectReleaserChecked = computed(() => {const isIssueCreatorChecked = computed(() => {return rolloutPolicy.value.issueRoles.includes(VirtualRoleType.CREATOR);});++const extractCustomProjectRolesFromRolloutPolicy = (rp: RolloutPolicy) => {+ const customRoles = rp.projectRoles.filter((role) => {+ return !PresetProjectRoles.includes(role);+ });+ return {+ checked: customRoles.length > 0,+ roles: customRoles,+ };+};+const customProjectRoles = ref(+ extractCustomProjectRolesFromRolloutPolicy(rolloutPolicy.value)+);+const isIssueLastApproverChecked = computed(() => {- return rolloutPolicy.value.issueRoles.includes(VirtualRoleType.LAST_APPROVER);+ return (+ rolloutPolicy.value.issueRoles.includes(VirtualRoleType.LAST_APPROVER) &&+ !customProjectRoles.value.checked+ );});const isManualRolloutByDedicatedRolesChecked = computed(() => {+ if (customProjectRoles.value.checked) {+ return true;+ }+if (rolloutPolicy.value.automatic) {return false;}@@ -256,11 +312,60 @@ const toggleDedicatedRoles = (pull(patch.issueRoles, VirtualRoleType.LAST_APPROVER);update(patch);};+const toggleCustomProjectRoles = (checked: boolean) => {+ if (checked) {+ customProjectRoles.value = {+ checked: true,+ roles: [],+ };+ } else {+ const rp = rolloutPolicy.value;+ // Remove custom project roles+ // remaining preset project roles+ const set = new Set(+ rp.projectRoles.filter((role) => PresetProjectRoles.includes(role))+ );+ const patch = RolloutPolicy.fromPartial({+ ...rp,+ automatic: false,+ projectRoles: Array.from(set),+ });+ pull(patch.issueRoles, VirtualRoleType.LAST_APPROVER);+ customProjectRoles.value = {+ checked: false,+ roles: [],+ };+ update(patch);+ }+};+const handleUpdateCustomProjectRoles = (roles: string[]) => {+ const rp = rolloutPolicy.value;+ const presetProjectRoleSet = new Set(+ rp.projectRoles.filter((role) => PresetProjectRoles.includes(role))+ );+ const customProjectRoleSet = new Set(roles);+ const patch = RolloutPolicy.fromPartial({+ ...rp,+ automatic: false,+ projectRoles: [+ ...Array.from(presetProjectRoleSet),+ ...Array.from(customProjectRoleSet),+ ],+ });+ pull(patch.issueRoles, VirtualRoleType.LAST_APPROVER);+ customProjectRoles.value.roles = roles;+ update(patch);+};++const filterProjectRole = (role: Role) => {+ return !PresetProjectRoles.includes(role.name);+};watch(() => props.policy.rolloutPolicy!,(p) => {rolloutPolicy.value = cloneDeep(p);+ customProjectRoles.value = extractCustomProjectRolesFromRolloutPolicy(p);},{ immediate: true, deep: true });diff --git a/frontend/src/components/ProjectMember/AddProjectMember/AddProjectMemberForm.vue b/frontend/src/components/ProjectMember/AddProjectMember/AddProjectMemberForm.vueindex fee2bf4d81..b75636f649 100644--- a/frontend/src/components/ProjectMember/AddProjectMember/AddProjectMemberForm.vue+++ b/frontend/src/components/ProjectMember/AddProjectMember/AddProjectMemberForm.vue@@ -20,7 +20,7 @@</div><div class="w-full"><span>{{ $t("project.members.assign-role") }}</span>- <ProjectMemberRoleSelect v-model:role="state.role" class="mt-2" />+ <ProjectRoleSelect v-model:role="state.role" class="mt-2" /></div><div@@ -72,7 +72,7 @@ import { computed, onMounted, reactive, watch } from "vue";import { useI18n } from "vue-i18n";import ExpirationSelector from "@/components/ExpirationSelector.vue";import QuerierDatabaseResourceForm from "@/components/Issue/panel/RequestQueryPanel/DatabaseResourceForm/index.vue";-import ProjectMemberRoleSelect from "@/components/v2/Select/ProjectMemberRoleSelect.vue";+import ProjectRoleSelect from "@/components/v2/Select/ProjectRoleSelect.vue";import { useUserStore } from "@/store";import { getUserId } from "@/store/modules/v1/common";import {diff --git a/frontend/src/components/v2/Select/ProjectMemberRoleSelect.vue b/frontend/src/components/v2/Select/ProjectRoleSelect.vuesimilarity index 64%rename from frontend/src/components/v2/Select/ProjectMemberRoleSelect.vuerename to frontend/src/components/v2/Select/ProjectRoleSelect.vueindex 477356ccdf..f680283ad3 100644--- a/frontend/src/components/v2/Select/ProjectMemberRoleSelect.vue+++ b/frontend/src/components/v2/Select/ProjectRoleSelect.vue@@ -1,7 +1,7 @@<template><NSelectv-bind="$attrs"- :value="role"+ :value="multiple ? roles : role":options="roleOptions":max-tag-count="'responsive'":filterable="true"@@ -9,8 +9,9 @@:render-option="renderOption":placeholder="$t('role.select')":render-label="renderLabel"+ :multiple="multiple"class="bb-project-member-role-select"- @update:value="changeRole"+ @update:value="handleChange"/><FeatureModalfeature="bb.feature.custom-role"@@ -20,12 +21,12 @@</template><script setup lang="ts">-import { type SelectOption, NSelect, NTooltip } from "naive-ui";+import { type SelectOption, NSelect, NTooltip, TooltipProps } from "naive-ui";import { computed, h, ref, VNode } from "vue";import FeatureBadge from "@/components/FeatureGuard/FeatureBadge.vue";import FeatureModal from "@/components/FeatureGuard/FeatureModal.vue";import { featureToRef, useRoleStore } from "@/store";-import { ProjectRoleType, PresetRoleType, WorkspaceLevelRoles } from "@/types";+import { PresetRoleType, WorkspaceLevelRoles } from "@/types";import { Role } from "@/types/proto/v1/role_service";import { displayRoleDescription, displayRoleTitle } from "@/utils";@@ -34,12 +35,17 @@ type ProjectRoleSelectOption = SelectOption & {role: Role;};-defineProps<{- role?: ProjectRoleType;+const props = defineProps<{+ role?: string;+ roles?: string[];+ multiple?: boolean;+ filter?: (role: Role) => boolean;+ tooltipProps?: TooltipProps;}>();const emit = defineEmits<{- (event: "update:role", role: ProjectRoleType): void;+ (event: "update:role", role: string): void;+ (event: "update:roles", roles: string[]): void;}>();const FREE_ROLE_LIST = [@@ -59,18 +65,19 @@ const roleList = computed(() => {});const roleOptions = computed(() => {- return (- roleList.value- // Exclude workspace level roles.- .filter((role) => !WorkspaceLevelRoles.includes(role.name))- .map<ProjectRoleSelectOption>((role) => {- return {- label: displayRoleTitle(role.name),- value: role.name,- role,- };- })- );+ let roles = roleList.value+ // Exclude workspace level roles.+ .filter((role) => !WorkspaceLevelRoles.includes(role.name));+ if (props.filter) {+ roles = roles.filter(props.filter);+ }+ return roles.map<ProjectRoleSelectOption>((role) => {+ return {+ label: displayRoleTitle(role.name),+ value: role.name,+ role,+ };+ });});const renderLabel = (option: SelectOption) => {@@ -96,6 +103,21 @@ const renderLabel = (option: SelectOption) => {);};+const changeRoles = (values: string[]) => {+ if (+ values.some((value) => !roleList.value.find((role) => role.name === value))+ ) {+ // some roles not found+ return;+ }+ if (!hasCustomRoleFeature.value) {+ if (values.some((value) => !FREE_ROLE_LIST.includes(value))) {+ showFeatureModal.value = true;+ return;+ }+ }+ emit("update:roles", values);+};const changeRole = (value: string) => {const role = roleList.value.find((role) => role.name === value);if (!role) return;@@ -107,6 +129,14 @@ const changeRole = (value: string) => {}emit("update:role", value);};+const handleChange = (e: string | string[]) => {+ if (props.multiple && Array.isArray(e)) {+ changeRoles(e);+ }+ if (!props.multiple && typeof e === "string") {+ changeRole(e);+ }+};const filterByName = (pattern: string, option: SelectOption) => {const { role } = option as ProjectRoleSelectOption;@@ -122,7 +152,7 @@ const renderOption = ({option: SelectOption;}) => {const { role } = option as ProjectRoleSelectOption;- return h(NTooltip, null, {+ return h(NTooltip, props.tooltipProps, {trigger: () => node,default: () => displayRoleDescription(role.name),});diff --git a/frontend/src/components/v2/Select/index.ts b/frontend/src/components/v2/Select/index.tsindex d4b96b623f..1d4ed2bd04 100644--- a/frontend/src/components/v2/Select/index.ts+++ b/frontend/src/components/v2/Select/index.ts@@ -2,6 +2,7 @@ import AnnouncementLevelSelect from "./AnnouncementLevelSelect.vue";import DatabaseSelect from "./DatabaseSelect.vue";import EnvironmentSelect from "./EnvironmentSelect.vue";import InstanceSelect from "./InstanceSelect.vue";+import ProjectRoleSelect from "./ProjectRoleSelect.vue";import ProjectSelect from "./ProjectSelect.vue";import RoleRadioSelect from "./RoleRadioSelect.vue";import UserSelect from "./UserSelect.vue";@@ -14,6 +15,7 @@ export {EnvironmentSelect,ProjectSelect,WorkspaceRoleSelect,+ ProjectRoleSelect,RoleRadioSelect,UserSelect,};diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.jsonindex 61a7d0a142..ce4424a8b0 100644--- a/frontend/src/locales/en-US.json+++ b/frontend/src/locales/en-US.json@@ -1462,7 +1462,8 @@"manual-by-dedicated-roles": "Manual rollout by dedicated roles","manual-by-dedicated-roles-info": "Allow any of the following selected roles to click the \"Rollout\" button, and then the change will be executed.","manual-by-dba": "DBA",- "manual-by-workspace-admin": "Workspace admin"+ "manual-by-workspace-admin": "Workspace admin",+ "manual-by-custom-project-roles": "Custom project roles"},"backup": {"name": "Database backup schedule policy",diff --git a/frontend/src/locales/es-ES.json b/frontend/src/locales/es-ES.jsonindex 7337df98d2..2c7473aecd 100644--- a/frontend/src/locales/es-ES.json+++ b/frontend/src/locales/es-ES.json@@ -1461,7 +1461,8 @@"manual-by-dedicated-roles": "Implementación manual por roles especializados","manual-by-dedicated-roles-info": "Permita que cualquiera de los siguientes roles seleccionados haga clic en el botón \"Implementar\" y luego se ejecutará el cambio.","manual-by-dba": "DBA",- "manual-by-workspace-admin": "Administrador del espacio de trabajo"+ "manual-by-workspace-admin": "Administrador del espacio de trabajo",+ "manual-by-custom-project-roles": "Roles de proyecto personalizados"},"backup": {"name": "Política de programación de copias de seguridad de la base de datos",diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.jsonindex 7d83441625..bab00bbca2 100644--- a/frontend/src/locales/zh-CN.json+++ b/frontend/src/locales/zh-CN.json@@ -1459,7 +1459,8 @@"manual-by-dedicated-roles": "特定角色手工发布","manual-by-dedicated-roles-info": "允许以下任一选中角色,点击「发布」按钮后,执行变更。","manual-by-dba": "DBA",- "manual-by-workspace-admin": "Bytebase 工作空间管理员"+ "manual-by-workspace-admin": "Bytebase 工作空间管理员",+ "manual-by-custom-project-roles": "自定义项目角色"},"backup": {"name": "数据库备份策略",diff --git a/frontend/src/types/project.ts b/frontend/src/types/project.tsindex ab7bfb566a..0210836488 100644--- a/frontend/src/types/project.ts+++ b/frontend/src/types/project.ts@@ -8,13 +8,6 @@ import { ProjectId } from "./id";import { Principal } from "./principal";import { ExternalRepositoryInfo, RepositoryConfig } from "./repository";-export type ProjectRoleType =- | "OWNER"- | "DEVELOPER"- | "EXPORTER"- | "QUERIER"- | string;-export type ProjectWorkflowType = "UI" | "VCS";export type ProjectVisibility = "PUBLIC" | "PRIVATE";@@ -49,7 +42,7 @@ export type ProjectMember = {project: Project;// Domain specific fields- role: ProjectRoleType;+ role: string;principal: Principal;};diff --git a/frontend/src/utils/projectIamPolicy.ts b/frontend/src/utils/projectIamPolicy.tsindex cadf8955ba..434d1024b5 100644--- a/frontend/src/utils/projectIamPolicy.ts+++ b/frontend/src/utils/projectIamPolicy.ts@@ -1,4 +1,3 @@-import { ProjectRoleType } from "@/types";import { Binding, type IamPolicy } from "@/types/proto/v1/iam_policy";const tidyUpPolicy = (policy: IamPolicy) => {@@ -10,7 +9,7 @@ const tidyUpPolicy = (policy: IamPolicy) => {export const removeRoleFromProjectIamPolicy = (policy: IamPolicy,user: string,- role: ProjectRoleType+ role: string) => {const binding = policy.bindings.find((binding) => binding.role === role);if (binding) {@@ -39,7 +38,7 @@ export const removeUserFromProjectIamPolicy = (export const addRoleToProjectIamPolicy = (policy: IamPolicy,user: string,- role: ProjectRoleType+ role: string) => {policy.bindings.push(Binding.fromPartial({diff --git a/frontend/src/utils/role.ts b/frontend/src/utils/role.tsindex 054c7e1531..71da88b2c1 100644--- a/frontend/src/utils/role.ts+++ b/frontend/src/utils/role.ts@@ -2,7 +2,7 @@ import { kebabCase } from "lodash-es";import { computed, unref } from "vue";import { t } from "@/plugins/i18n";import { hasFeature, useCurrentUserV1, useRoleStore } from "@/store";-import { MaybeRef, ProjectRoleType, RoleType, PresetRoleType } from "@/types";+import { MaybeRef, RoleType, PresetRoleType } from "@/types";import { UserRole } from "@/types/proto/v1/auth_service";export type WorkspacePermissionType =@@ -107,7 +107,7 @@ export type ProjectPermissionType =// Returns true if RBAC is not enabled or the particular project role has the particular project permission.export function hasProjectPermission(permission: ProjectPermissionType,- role: ProjectRoleType+ role: string): boolean {if (!hasFeature("bb.feature.rbac")) {return true;@@ -171,7 +171,7 @@ export function roleName(role: RoleType): string {}// Project Role-export function projectRoleName(role: ProjectRoleType): string {+export function projectRoleName(role: string): string {switch (role) {case "OWNER":return "Owner";