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): project owner approval policy (#2240)
Liu Ji088518d8859f
diff --git a/frontend/src/components/EnvironmentForm.vue b/frontend/src/components/EnvironmentForm.vueindex 373da54c01..65e03d93df 100644--- a/frontend/src/components/EnvironmentForm.vue+++ b/frontend/src/components/EnvironmentForm.vue@@ -11,7 +11,7 @@:disabled="!allowEdit":required="true":value="state.environment.name"- @input="state.environment.name = $event.target.value"+ @input="state.environment.name = ($event.target as HTMLInputElement).value"/></div><div class="col-span-1">@@ -25,7 +25,7 @@<div class="mt-4 flex flex-col space-y-4"><div class="flex space-x-4"><input- v-model="state.approvalPolicy.payload.value"+ v-model="(state.approvalPolicy.payload as PipelineApprovalPolicyPayload).value"name="manual-approval-always"tabindex="-1"type="radio"@@ -40,9 +40,19 @@</div></div></div>++ <AssigneeGroupEditor+ class="ml-8"+ :policy="state.approvalPolicy"+ :allow-edit="allowEdit"+ @update="(assigneeGroupList) => {+ (state.approvalPolicy.payload as PipelineApprovalPolicyPayload).assigneeGroupList = assigneeGroupList+ }"+ />+<div class="flex space-x-4"><input- v-model="state.approvalPolicy.payload.value"+ v-model="(state.approvalPolicy.payload as PipelineApprovalPolicyPayload).value"name="manual-approval-never"tabindex="-1"type="radio"@@ -73,7 +83,7 @@<div class="mt-4 flex flex-col space-y-4"><div class="flex space-x-4"><input- v-model="state.backupPolicy.payload.schedule"+ v-model="(state.backupPolicy.payload as BackupPlanPolicyPayload).schedule"tabindex="-1"type="radio"class="text-accent disabled:text-accent-disabled focus:ring-accent"@@ -91,7 +101,7 @@</div><div class="flex space-x-4"><input- v-model="state.backupPolicy.payload.schedule"+ v-model="(state.backupPolicy.payload as BackupPlanPolicyPayload).schedule"tabindex="-1"type="radio"class="text-accent disabled:text-accent-disabled focus:ring-accent"@@ -113,7 +123,7 @@</div><div class="flex space-x-4"><input- v-model="state.backupPolicy.payload.schedule"+ v-model="(state.backupPolicy.payload as BackupPlanPolicyPayload).schedule"tabindex="-1"type="radio"class="text-accent disabled:text-accent-disabled focus:ring-accent"@@ -185,7 +195,7 @@</div><!-- Update button group --><div v-else class="flex justify-between items-center pt-5">- <template v-if="state.environment.rowStatus == 'NORMAL'">+ <template v-if="(state.environment as Environment).rowStatus == 'NORMAL'"><BBButtonConfirmv-if="allowArchive":style="'ARCHIVE'"@@ -199,7 +209,9 @@@confirm="archiveEnvironment"/></template>- <template v-else-if="state.environment.rowStatus == 'ARCHIVED'">+ <template+ v-else-if="(state.environment as Environment).rowStatus == 'ARCHIVED'"+ ><BBButtonConfirmv-if="allowRestore":style="'RESTORE'"@@ -236,26 +248,22 @@</div></template>-<script lang="ts">-import {- computed,- reactive,- PropType,- watch,- watchEffect,- defineComponent,-} from "vue";+<script lang="ts" setup>+import { computed, reactive, PropType, watch, watchEffect } from "vue";import { cloneDeep, isEqual, isEmpty } from "lodash-es";import { useRouter } from "vue-router";-import {+import type {+ BackupPlanPolicyPayload,Environment,EnvironmentCreate,EnvironmentPatch,+ PipelineApprovalPolicyPayload,Policy,SQLReviewPolicy,} from "../types";-import { isDev, isDBAOrOwner, sqlReviewPolicySlug } from "../utils";+import { isDBAOrOwner, sqlReviewPolicySlug } from "../utils";import { useCurrentUser, useEnvironmentList, useSQLReviewStore } from "@/store";+import AssigneeGroupEditor from "./EnvironmentForm/AssigneeGroupEditor.vue";interface LocalState {environment: Environment | EnvironmentCreate;@@ -265,213 +273,191 @@ interface LocalState {const ROUTE_NAME = "setting.workspace.sql-review";-export default defineComponent({- name: "EnvironmentForm",- props: {- create: {- type: Boolean,- default: false,- },- environment: {- required: true,- type: Object as PropType<Environment | EnvironmentCreate>,- },- approvalPolicy: {- required: true,- type: Object as PropType<Policy>,- },- backupPolicy: {- required: true,- type: Object as PropType<Policy>,- },+const props = defineProps({+ create: {+ type: Boolean,+ default: false,},- emits: ["create", "update", "cancel", "archive", "restore", "update-policy"],- setup(props, { emit }) {- const state = reactive<LocalState>({- environment: cloneDeep(props.environment),- approvalPolicy: cloneDeep(props.approvalPolicy),- backupPolicy: cloneDeep(props.backupPolicy),- });+ environment: {+ required: true,+ type: Object as PropType<Environment | EnvironmentCreate>,+ },+ approvalPolicy: {+ required: true,+ type: Object as PropType<Policy>,+ },+ backupPolicy: {+ required: true,+ type: Object as PropType<Policy>,+ },+});- const router = useRouter();- const sqlReviewStore = useSQLReviewStore();+const emit = defineEmits([+ "create",+ "update",+ "cancel",+ "archive",+ "restore",+ "update-policy",+]);+const state = reactive<LocalState>({+ environment: cloneDeep(props.environment),+ approvalPolicy: cloneDeep(props.approvalPolicy),+ backupPolicy: cloneDeep(props.backupPolicy),+});- const environmentId = computed(() => {- if (props.create) {- return;- }- return (props.environment as Environment).id;- });+const router = useRouter();+const sqlReviewStore = useSQLReviewStore();- const prepareSQLReviewPolicy = () => {- if (!environmentId.value) {- return;- }- return sqlReviewStore.fetchReviewPolicyByEnvironmentId(- environmentId.value- );- };- watchEffect(prepareSQLReviewPolicy);-- const sqlReviewPolicy = computed((): SQLReviewPolicy | undefined => {- if (!environmentId.value) {- return;- }- return sqlReviewStore.getReviewPolicyByEnvironmentId(environmentId.value);+const environmentId = computed(() => {+ if (props.create) {+ return;+ }+ return (props.environment as Environment).id;+});++const prepareSQLReviewPolicy = () => {+ if (!environmentId.value) {+ return;+ }+ return sqlReviewStore.fetchReviewPolicyByEnvironmentId(environmentId.value);+};+watchEffect(prepareSQLReviewPolicy);++const sqlReviewPolicy = computed((): SQLReviewPolicy | undefined => {+ if (!environmentId.value) {+ return;+ }+ return sqlReviewStore.getReviewPolicyByEnvironmentId(environmentId.value);+});++const onSQLReviewPolicyClick = () => {+ if (sqlReviewPolicy.value) {+ router.push({+ name: `${ROUTE_NAME}.detail`,+ params: {+ sqlReviewPolicySlug: sqlReviewPolicySlug(sqlReviewPolicy.value),+ },+ });+ } else {+ router.push({+ name: `${ROUTE_NAME}.create`,+ query: {+ environmentId: environmentId.value,+ },});+ }+};- const onSQLReviewPolicyClick = () => {- if (sqlReviewPolicy.value) {- router.push({- name: `${ROUTE_NAME}.detail`,- params: {- sqlReviewPolicySlug: sqlReviewPolicySlug(sqlReviewPolicy.value),- },- });- } else {- router.push({- name: `${ROUTE_NAME}.create`,- query: {- environmentId: environmentId.value,- },- });- }- };-- watch(- () => props.environment,- (cur: Environment | EnvironmentCreate) => {- state.environment = cloneDeep(cur);- }- );+watch(+ () => props.environment,+ (cur: Environment | EnvironmentCreate) => {+ state.environment = cloneDeep(cur);+ }+);- watch(- () => props.approvalPolicy,- (cur: Policy) => {- state.approvalPolicy = cloneDeep(cur);- }- );+watch(+ () => props.approvalPolicy,+ (cur: Policy) => {+ state.approvalPolicy = cloneDeep(cur);+ }+);- watch(- () => props.backupPolicy,- (cur: Policy) => {- state.backupPolicy = cloneDeep(cur);- }- );+watch(+ () => props.backupPolicy,+ (cur: Policy) => {+ state.backupPolicy = cloneDeep(cur);+ }+);- const currentUser = useCurrentUser();+const currentUser = useCurrentUser();- const environmentList = useEnvironmentList();+const environmentList = useEnvironmentList();- const hasPermission = computed(() => {- return isDBAOrOwner(currentUser.value.role);- });+const hasPermission = computed(() => {+ return isDBAOrOwner(currentUser.value.role);+});- const allowArchive = computed(() => {- return allowEdit.value && environmentList.value.length > 1;- });+const allowArchive = computed(() => {+ return allowEdit.value && environmentList.value.length > 1;+});- const allowRestore = computed(() => {- return hasPermission.value;- });+const allowRestore = computed(() => {+ return hasPermission.value;+});++const allowEdit = computed(() => {+ return (+ props.create ||+ ((state.environment as Environment).rowStatus == "NORMAL" &&+ hasPermission.value)+ );+});- const allowEdit = computed(() => {+const allowCreate = computed(() => {+ return !isEmpty(state.environment?.name);+});++const valueChanged = (+ field?: "environment" | "approvalPolicy" | "backupPolicy"+): boolean => {+ switch (field) {+ case "environment":+ return !isEqual(props.environment, state.environment);+ case "approvalPolicy":+ return !isEqual(props.approvalPolicy, state.approvalPolicy);+ case "backupPolicy":+ return !isEqual(props.backupPolicy, state.backupPolicy);++ default:return (- props.create ||- ((state.environment as Environment).rowStatus == "NORMAL" &&- hasPermission.value)+ !isEqual(props.environment, state.environment) ||+ !isEqual(props.approvalPolicy, state.approvalPolicy) ||+ !isEqual(props.backupPolicy, state.backupPolicy));- });+ }+};- const allowCreate = computed(() => {- return !isEmpty(state.environment?.name);- });+const revertEnvironment = () => {+ state.environment = cloneDeep(props.environment!);+};- const valueChanged = (- field?: "environment" | "approvalPolicy" | "backupPolicy"- ): boolean => {- switch (field) {- case "environment":- return !isEqual(props.environment, state.environment);- case "approvalPolicy":- return !isEqual(props.approvalPolicy, state.approvalPolicy);- case "backupPolicy":- return !isEqual(props.backupPolicy, state.backupPolicy);-- default:- return (- !isEqual(props.environment, state.environment) ||- !isEqual(props.approvalPolicy, state.approvalPolicy) ||- !isEqual(props.backupPolicy, state.backupPolicy)- );- }- };-- const revertEnvironment = () => {- state.environment = cloneDeep(props.environment!);- };-- const createEnvironment = () => {- emit(- "create",- state.environment,- state.approvalPolicy,- state.backupPolicy- );- };-- const updateEnvironment = () => {- if (state.environment.name != props.environment!.name) {- const patchedEnvironment: EnvironmentPatch = {};-- patchedEnvironment.name = state.environment.name;- emit("update", patchedEnvironment);- }-- if (!isEqual(props.approvalPolicy, state.approvalPolicy)) {- emit(- "update-policy",- (state.environment as Environment).id,- "bb.policy.pipeline-approval",- state.approvalPolicy- );- }-- if (!isEqual(props.backupPolicy, state.backupPolicy)) {- emit(- "update-policy",- (state.environment as Environment).id,- "bb.policy.backup-plan",- state.backupPolicy- );- }- };-- const archiveEnvironment = () => {- emit("archive", state.environment);- };-- const restoreEnvironment = () => {- emit("restore", state.environment);- };-- return {- isDev,- state,- allowArchive,- allowRestore,- allowEdit,- valueChanged,- allowCreate,- hasPermission,- revertEnvironment,- createEnvironment,- updateEnvironment,- archiveEnvironment,- restoreEnvironment,- sqlReviewPolicy,- onSQLReviewPolicyClick,- };- },-});+const createEnvironment = () => {+ emit("create", state.environment, state.approvalPolicy, state.backupPolicy);+};++const updateEnvironment = () => {+ if (state.environment.name != props.environment!.name) {+ const patchedEnvironment: EnvironmentPatch = {};++ patchedEnvironment.name = state.environment.name;+ emit("update", patchedEnvironment);+ }++ if (!isEqual(props.approvalPolicy, state.approvalPolicy)) {+ emit(+ "update-policy",+ (state.environment as Environment).id,+ "bb.policy.pipeline-approval",+ state.approvalPolicy+ );+ }++ if (!isEqual(props.backupPolicy, state.backupPolicy)) {+ emit(+ "update-policy",+ (state.environment as Environment).id,+ "bb.policy.backup-plan",+ state.backupPolicy+ );+ }+};++const archiveEnvironment = () => {+ emit("archive", state.environment);+};++const restoreEnvironment = () => {+ emit("restore", state.environment);+};</script>diff --git a/frontend/src/components/EnvironmentForm/AssigneeGroupEditor.vue b/frontend/src/components/EnvironmentForm/AssigneeGroupEditor.vuenew file mode 100644index 0000000000..fad1ecfb03--- /dev/null+++ b/frontend/src/components/EnvironmentForm/AssigneeGroupEditor.vue@@ -0,0 +1,120 @@+<template>+ <div v-if="payload.value === 'MANUAL_APPROVAL_ALWAYS'" class="my-4 space-y-4">+ <div class="flex space-x-4">+ <input+ v-model="state.assigneeGroup"+ name="WORKSPACE_OWNER_OR_DBA"+ tabindex="-1"+ type="radio"+ class="text-accent disabled:text-accent-disabled focus:ring-accent"+ value="WORKSPACE_OWNER_OR_DBA"+ :disabled="!allowEdit"+ />+ <div class="-mt-0.5">+ <div class="textlabel">+ {{ $t("policy.approval.assignee-group.workspace-owner-or-dba") }}+ </div>+ </div>+ </div>+ <div class="flex space-x-4">+ <input+ v-model="state.assigneeGroup"+ name="PROJECT_OWNER"+ tabindex="-1"+ type="radio"+ class="text-accent disabled:text-accent-disabled focus:ring-accent"+ value="PROJECT_OWNER"+ :disabled="!allowEdit"+ />+ <div class="-mt-0.5">+ <div class="textlabel">+ {{ $t("policy.approval.assignee-group.project-owner") }}+ </div>+ </div>+ </div>+ </div>+</template>++<script lang="ts" setup>+import { computed, PropType, reactive, watch } from "vue";+import {+ AssigneeGroup,+ AssigneeGroupValue,+ DefaultAssigneeGroup,+ PipelineApprovalPolicyPayload,+ Policy,+} from "@/types";++type LocalState = {+ assigneeGroup: AssigneeGroupValue;+};++const props = defineProps({+ allowEdit: {+ type: Boolean,+ required: true,+ },+ policy: {+ type: Object as PropType<Policy>,+ required: true,+ },+});++const emit = defineEmits<{+ (event: "update", assigneeGroupList: AssigneeGroup[]): void;+}>();++const payload = computed(() => {+ return props.policy.payload as PipelineApprovalPolicyPayload;+});++const getAssigneeGroup = (): AssigneeGroupValue => {+ const { value, assigneeGroupList } = payload.value;+ if (value === "MANUAL_APPROVAL_NEVER") {+ return "WORKSPACE_OWNER_OR_DBA";+ }++ if (assigneeGroupList.length === 0) {+ return DefaultAssigneeGroup;+ }+ return assigneeGroupList[0].value;+};++const state = reactive<LocalState>({+ assigneeGroup: getAssigneeGroup(),+});++const getAssigneeGroupListByValue = (value: AssigneeGroupValue) => {+ const issueTypeList: Array<AssigneeGroup["issueType"]> = [+ "bb.issue.database.schema.update",+ "bb.issue.database.data.update",+ "bb.issue.database.schema.update.ghost",+ ];+ const assigneeGroupList = issueTypeList.map<AssigneeGroup>((issueType) => ({+ issueType,+ value,+ }));+ return assigneeGroupList;+};++// Editing different AssigneeGroup for each issueType is not supported by now.+// So even if assigneeGroupList is an array, we apply the same logic on its+// items one-by-one when setting value.+watch(+ () => state.assigneeGroup,+ (value) => {+ emit("update", getAssigneeGroupListByValue(value));+ }+);++watch(+ () => payload.value.value,+ (value) => {+ if (value === "MANUAL_APPROVAL_NEVER") {+ // Empty the array since it's meaningless when MANUAL_APPROVAL_NEVER+ emit("update", []);+ }+ },+ { immediate: true }+);+</script>diff --git a/frontend/src/components/Issue/IssueSidebar.vue b/frontend/src/components/Issue/IssueSidebar.vueindex b4461182b7..81687b442e 100644--- a/frontend/src/components/Issue/IssueSidebar.vue+++ b/frontend/src/components/Issue/IssueSidebar.vue@@ -30,7 +30,7 @@class="w-full":disabled="!allowEditAssignee":selectedId="create ? (issue as IssueCreate).assigneeId : (issue as Issue).assignee?.id"- :allowed-role-list="['OWNER', 'DBA']"+ :custom-filter="filterPrincipal"data-label="bb-assignee-select"@select-principal-id="(principalId: number) => {@@ -298,6 +298,7 @@ import type {Instance,TaskDatabaseCreatePayload,DatabaseLabel,+ Principal,} from "@/types";import { ONBOARDING_ISSUE_ID } from "@/types";import {@@ -307,6 +308,7 @@ import {isReservedDatabaseLabel,hidePrefix,taskSlug,+ isOwnerOfProject,} from "@/utils";import {hasFeature,@@ -316,7 +318,11 @@ import {useLabelList,useProjectStore,} from "@/store";-import { useExtraIssueLogic, useIssueLogic } from "./logic";+import {+ useExtraIssueLogic,+ useIssueLogic,+ useAllowProjectOwnerToApprove,+} from "./logic";dayjs.extend(isSameOrAfter);@@ -465,12 +471,19 @@ const allowEditAssignee = computed(() => {// assignee might not have DBA role in case its role is revoked after// being assigned to the issue.const issueEntity = issue.value as Issue;- return (- issueEntity.id !== ONBOARDING_ISSUE_ID &&- issueEntity.status == "OPEN" &&- (currentUser.value.id == issueEntity.assignee.id ||- isDBAOrOwner(currentUser.value.role))- );+ if (issueEntity.id === ONBOARDING_ISSUE_ID) {+ return false;+ }+ if (issueEntity.status !== "OPEN") {+ return false;+ }+ if (currentUser.value.id === issueEntity.assignee.id) {+ return true;+ }+ if (isDBAOrOwner(currentUser.value.role)) {+ return true;+ }+ return false;});const allowEditEarliestAllowedTime = computed(() => {@@ -567,4 +580,12 @@ const selectTaskId = (taskId: TaskId) => {const stage = selectedStage.value as Stage;selectStageOrTask(stage.id, slug);};++const allowProjectOwnerToApprove = useAllowProjectOwnerToApprove();+const filterPrincipal = (principal: Principal): boolean => {+ if (allowProjectOwnerToApprove.value) {+ return isOwnerOfProject(principal, project.value);+ }+ return isDBAOrOwner(principal.role);+};</script>diff --git a/frontend/src/components/Issue/logic/assignee.ts b/frontend/src/components/Issue/logic/assignee.tsnew file mode 100644index 0000000000..5116fc80c4--- /dev/null+++ b/frontend/src/components/Issue/logic/assignee.ts@@ -0,0 +1,62 @@+import { computed } from "vue";+import {+ EnvironmentId,+ IssueCreate,+ IssueType,+ Pipeline,+ PipelineApprovalPolicyPayload,+ Policy,+} from "@/types";+import { useIssueLogic } from ".";+import { usePolicyByEnvironmentAndType } from "@/store";++export const useAllowProjectOwnerToApprove = () => {+ const { create, issue, activeStageOfPipeline } = useIssueLogic();++ const activeEnvironmentId = computed((): EnvironmentId => {+ if (create.value) {+ // When creating an issue, activeEnvironmentId is the first stage's environmentId+ const stage = (issue.value as IssueCreate).pipeline!.stageList[0];+ return stage.environmentId;+ }++ const stage = activeStageOfPipeline(issue.value.pipeline as Pipeline);+ return stage.environment.id;+ });++ const activeEnvironmentApprovalPolicy = usePolicyByEnvironmentAndType(+ computed(() => ({+ environmentId: activeEnvironmentId.value,+ type: "bb.policy.pipeline-approval",+ }))+ );++ const allowProjectOwnerAsAssignee = computed((): boolean => {+ const policy = activeEnvironmentApprovalPolicy.value;+ if (!policy) return false;++ return allowProjectOwnerToApprove(policy, issue.value.type);+ });++ return allowProjectOwnerAsAssignee;+};++export const allowProjectOwnerToApprove = (+ policy: Policy,+ issueType: IssueType+): boolean => {+ const payload = policy.payload as PipelineApprovalPolicyPayload;+ if (payload.value === "MANUAL_APPROVAL_NEVER") {+ return false;+ }++ const assigneeGroup = payload.assigneeGroupList.find(+ (group) => group.issueType === issueType+ );++ if (!assigneeGroup) {+ return false;+ }++ return assigneeGroup.value === "PROJECT_OWNER";+};diff --git a/frontend/src/components/Issue/logic/index.ts b/frontend/src/components/Issue/logic/index.tsindex d386320a1c..5a291a9b85 100644--- a/frontend/src/components/Issue/logic/index.ts+++ b/frontend/src/components/Issue/logic/index.ts@@ -7,6 +7,7 @@ import StandardModeProvider from "./StandardModeProvider";export * from "./base";export * from "./common";export * from "./extra";+export * from "./assignee";export * from "./transition";export * from "./utils";diff --git a/frontend/src/components/Issue/logic/transition.ts b/frontend/src/components/Issue/logic/transition.tsindex 438fac656f..0c3a16a56a 100644--- a/frontend/src/components/Issue/logic/transition.ts+++ b/frontend/src/components/Issue/logic/transition.ts@@ -15,10 +15,11 @@ import {applicableStageTransition,applicableTaskTransition,isDBAOrOwner,+ isOwnerOfProject,StageStatusTransition,TaskStatusTransition,} from "@/utils";-import { useIssueLogic } from ".";+import { useAllowProjectOwnerToApprove, useIssueLogic } from ".";export const useIssueTransitionLogic = (issue: Ref<Issue>) => {const {@@ -27,8 +28,30 @@ export const useIssueTransitionLogic = (issue: Ref<Issue>) => {allowApplyIssueStatusTransition,allowApplyTaskStatusTransition,} = useIssueLogic();+const currentUser = useCurrentUser();+ const allowProjectOwnerAsAssignee = useAllowProjectOwnerToApprove();++ const isAllowedToApplyTaskTransition = computed(() => {+ if (create.value) {+ return false;+ }++ // Applying task transition is decoupled with the issue's Assignee.+ // But relative to the task's environment's approval policy.+ if (isDBAOrOwner(currentUser.value.role)) {+ return true;+ }+ if (+ allowProjectOwnerAsAssignee.value &&+ isOwnerOfProject(currentUser.value, (issue.value as Issue).project)+ ) {+ return true;+ }+ return false;+ });+const getApplicableIssueStatusTransitionList = (issue: Issue): IssueStatusTransition[] => {@@ -101,12 +124,7 @@ export const useIssueTransitionLogic = (issue: Ref<Issue>) => {case "CANCELED":return [];case "OPEN": {- // Allow assignee, or assignee is the system bot and current user is DBA or owner- if (- currentUser.value.id === issue.assignee?.id ||- (issue.assignee?.id == SYSTEM_BOT_ID &&- isDBAOrOwner(currentUser.value.role))- ) {+ if (isAllowedToApplyTaskTransition.value) {const currentTask = activeTaskOfPipeline(issue.pipeline);return applicableStageTransition(issue.pipeline).filter((transition) =>@@ -134,12 +152,7 @@ export const useIssueTransitionLogic = (issue: Ref<Issue>) => {case "CANCELED":return [];case "OPEN": {- // Allow assignee, or assignee is the system bot and current user is DBA or owner- if (- currentUser.value.id === issue.assignee?.id ||- (issue.assignee?.id == SYSTEM_BOT_ID &&- isDBAOrOwner(currentUser.value.role))- ) {+ if (isAllowedToApplyTaskTransition.value) {const currentTask = activeTaskOfPipeline(issue.pipeline);return applicableTaskTransition(issue.pipeline).filter((transition) =>allowApplyTaskStatusTransition(currentTask, transition.to)diff --git a/frontend/src/components/MemberSelect.vue b/frontend/src/components/MemberSelect.vueindex f5110e67a6..672c9ba09e 100644--- a/frontend/src/components/MemberSelect.vue+++ b/frontend/src/components/MemberSelect.vue@@ -100,6 +100,10 @@ export default defineComponent({default: true,type: Boolean,},+ customFilter: {+ type: Function as PropType<(principal: Principal) => boolean>,+ default: undefined,+ },},emits: ["select-principal-id"],setup(props) {@@ -138,6 +142,10 @@ export default defineComponent({return true;}+ if (typeof props.customFilter === "function") {+ return props.customFilter(item);+ }+return (// We write this way instead of props.allowedRoleList.includes(item.role)// is because isOwner/isDBA/isDeveloper has feature gate logic.diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.jsonindex 73319b2354..586267b45f 100644--- a/frontend/src/locales/en-US.json+++ b/frontend/src/locales/en-US.json@@ -655,7 +655,8 @@"archive": "Archive this environment","archive-info": "Archived environment will not be shown on the normal interface. You can still restore later from the Archive page.","create": "Create Environment",- "restore": "Restore this environment"+ "restore": "Restore this environment",+ "successfully-updated-environment": "Successfully updated environment '{name}'."},"quick-start": {"bookmark-an-issue": "Bookmark an issue",@@ -718,7 +719,11 @@"manual": "Require manual approval","manual-info": "Tasks will only be executed after being manually approved.","auto": "Skip manual approval",- "auto-info": "Tasks will be approved and executed automatically if all task checks pass."+ "auto-info": "Tasks will be approved and executed automatically if all task checks pass.",+ "assignee-group": {+ "workspace-owner-or-dba": "Require approval from DBA or workspace owner.",+ "project-owner": "Require approval from project owner."+ }},"backup": {"name": "Database backup schedule policy",diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.jsonindex 670069ad95..e6fb0a857d 100644--- a/frontend/src/locales/zh-CN.json+++ b/frontend/src/locales/zh-CN.json@@ -656,7 +656,8 @@"archive": "归档此环境","archive-info": "已归档环境不会显示。您可以从归档界面恢复。","create": "创建环境",- "restore": "恢复这个环境"+ "restore": "恢复此环境",+ "successfully-updated-environment": "环境'{0}'更新成功"},"quick-start": {"bookmark-an-issue": "收藏工单",@@ -719,7 +720,11 @@"manual": "需要人工审批","manual-info": "任务只有被人工审批后才会执行。","auto": "无需审批",- "auto-info": "如果任务检查都通过的话,任务无需审批并且会被自动执行。"+ "auto-info": "如果任务检查都通过的话,任务无需审批并且会被自动执行。",+ "assignee-group": {+ "workspace-owner-or-dba": "需要 DBA 或者 Bytebase 实例所有者审批。",+ "project-owner": "需要项目所有者审批。"+ }},"backup": {"name": "数据库备份策略",diff --git a/frontend/src/plugins/issue/logic/initialize/helper.ts b/frontend/src/plugins/issue/logic/initialize/helper.tsindex 9ca9b25098..2eaaed465a 100644--- a/frontend/src/plugins/issue/logic/initialize/helper.ts+++ b/frontend/src/plugins/issue/logic/initialize/helper.ts@@ -4,16 +4,11 @@ import {Issue,IssueCreate,Principal,+ SYSTEM_BOT_ID,TaskDatabaseSchemaUpdatePayload,UNKNOWN_ID,} from "@/types";-import { isDBAOrOwner } from "@/utils";-import {- useActuatorStore,- useCurrentUser,- useIssueStore,- usePrincipalStore,-} from "@/store";+import { useActuatorStore, useCurrentUser, useIssueStore } from "@/store";import { BuildNewIssueContext, VALIDATE_ONLY_SQL } from "../common";export class IssueCreateHelper {@@ -31,16 +26,6 @@ export class IssueCreateHelper {this.currentUser = useCurrentUser();}- findDBAOrOwner(): Principal {- const currentUser = this.currentUser.value;- if (isDBAOrOwner(currentUser.role)) return currentUser;-- const userList = usePrincipalStore().principalList;-- // In bytebase, we always have at least 1 DBA or Owner, so it's safe here.- return userList.find((user) => isDBAOrOwner(user.role))!;- }-async prepare(): Promise<IssueCreate> {const { context, currentUser } = this;const { route } = context;@@ -66,7 +51,7 @@ export class IssueCreateHelper {// validateOnly does not support assigneeId=-1// so we need to specify here// but will reset this to -1 if route.query.assignee is empty- assigneeId: this.findDBAOrOwner().id,+ assigneeId: SYSTEM_BOT_ID,createContext: {},payload: {},};diff --git a/frontend/src/router/index.ts b/frontend/src/router/index.tsindex 3227da11dd..6e9e10494b 100644--- a/frontend/src/router/index.ts+++ b/frontend/src/router/index.ts@@ -887,11 +887,18 @@ export const router = createRouter({routes,linkExactActiveClass: "bg-link-hover",scrollBehavior(to /*, from, savedPosition */) {- if (to.hash && document.querySelector(to.hash)) {- return {- el: to.hash,- behavior: "smooth",- };+ if (to.hash) {+ try {+ const el = document.querySelector(to.hash);+ if (el) {+ return {+ el: to.hash,+ behavior: "smooth",+ };+ }+ } catch {+ // nothing todo+ }}},});diff --git a/frontend/src/store/modules/policy.ts b/frontend/src/store/modules/policy.tsindex 912e431032..76d7d426a4 100644--- a/frontend/src/store/modules/policy.ts+++ b/frontend/src/store/modules/policy.ts@@ -7,10 +7,18 @@ import {ResourceIdentifier,ResourceObject,unknown,+ UNKNOWN_ID,} from "@/types";-import { Policy, PolicyType, PolicyUpsert } from "@/types/policy";+import {+ PipelineApprovalPolicyPayload,+ Policy,+ PolicyType,+ PolicyUpsert,+} from "@/types/policy";import { getPrincipalFromIncludedList } from "./principal";import { useEnvironmentStore } from "./environment";+import { computed, Ref, watchEffect } from "vue";+import { useCurrentUser } from "./auth";function convert(policy: ResourceObject,@@ -33,7 +41,7 @@ function convert(}}- return {+ const result = {...(policy.attributes as Omit<Policy,"id" | "environment" | "payload" | "creator" | "updater"@@ -50,6 +58,15 @@ function convert(environment,payload: JSON.parse((policy.attributes.payload as string) || "{}"),};+ if (result.type === "bb.policy.pipeline-approval") {+ const payload = result.payload as PipelineApprovalPolicyPayload;+ if (!payload.assigneeGroupList) {+ // Assign an empty array as fallback+ payload.assigneeGroupList = [];+ }+ }++ return result;}export const usePolicyStore = defineStore("policy", {@@ -150,3 +167,22 @@ export const usePolicyStore = defineStore("policy", {},},});++export const usePolicyByEnvironmentAndType = (+ params: Ref<{ environmentId: EnvironmentId; type: PolicyType }>+) => {+ const store = usePolicyStore();+ const currentUser = useCurrentUser();+ watchEffect(() => {+ if (currentUser.value.id === UNKNOWN_ID) return;++ store.fetchPolicyByEnvironmentAndType(params.value);+ });++ return computed(() =>+ store.getPolicyByEnvironmentIdAndType(+ params.value.environmentId,+ params.value.type+ )+ );+};diff --git a/frontend/src/types/common.ts b/frontend/src/types/common.tsindex 3d811c437b..0949c23107 100644--- a/frontend/src/types/common.ts+++ b/frontend/src/types/common.ts@@ -333,6 +333,7 @@ const makeUnknown = (type: ResourceType) => {type: "bb.policy.pipeline-approval",payload: {value: DefaultApprovalPolicy,+ assigneeGroupList: [],},};@@ -736,6 +737,7 @@ const makeEmpty = (type: ResourceType) => {type: "bb.policy.pipeline-approval",payload: {value: DefaultApprovalPolicy,+ assigneeGroupList: [],},};diff --git a/frontend/src/types/index.ts b/frontend/src/types/index.tsindex 455f03cb06..3798d1a37d 100644--- a/frontend/src/types/index.ts+++ b/frontend/src/types/index.ts@@ -43,3 +43,4 @@ export * from "./subscription";export * from "./sheet";export * from "./sheetOrganizer";export * from "./sqlReview";+export * from "./utils";diff --git a/frontend/src/types/policy.ts b/frontend/src/types/policy.tsindex aac2a17298..6c65f435d4 100644--- a/frontend/src/types/policy.ts+++ b/frontend/src/types/policy.ts@@ -1,10 +1,12 @@import {RowStatus,Environment,+ IssueType,PolicyId,Principal,RuleType,RuleLevel,+ SubsetOf,} from ".";export type PolicyType =@@ -18,6 +20,7 @@ export type PipelineApprovalPolicyValue =export type PipelineApprovalPolicyPayload = {value: PipelineApprovalPolicyValue;+ assigneeGroupList: AssigneeGroup[];};export const DefaultApprovalPolicy: PipelineApprovalPolicyValue =@@ -41,6 +44,21 @@ export type SQLReviewPolicyPayload = {}[];};+export type AssigneeGroupValue = "WORKSPACE_OWNER_OR_DBA" | "PROJECT_OWNER";++export const DefaultAssigneeGroup: AssigneeGroupValue =+ "WORKSPACE_OWNER_OR_DBA";++export type AssigneeGroup = {+ issueType: SubsetOf<+ IssueType,+ | "bb.issue.database.schema.update"+ | "bb.issue.database.data.update"+ | "bb.issue.database.schema.update.ghost"+ >;+ value: AssigneeGroupValue;+};+export type PolicyPayload =| PipelineApprovalPolicyPayload| BackupPlanPolicyPayloaddiff --git a/frontend/src/types/utils.ts b/frontend/src/types/utils.tsnew file mode 100644index 0000000000..b6d64a593e--- /dev/null+++ b/frontend/src/types/utils.ts@@ -0,0 +1 @@+export type SubsetOf<T, S extends T> = S;diff --git a/frontend/src/utils/index.ts b/frontend/src/utils/index.tsindex 2e64af127d..bb4824b039 100644--- a/frontend/src/utils/index.ts+++ b/frontend/src/utils/index.ts@@ -13,3 +13,4 @@ export * from "./types";export * from "./util";export * from "./label";export * from "./deployment";+export * from "./principal";diff --git a/frontend/src/utils/principal.ts b/frontend/src/utils/principal.tsnew file mode 100644index 0000000000..52eabc3c35--- /dev/null+++ b/frontend/src/utils/principal.ts@@ -0,0 +1,15 @@+import { Principal, Project } from "@/types";++export const isOwnerOfProject = (+ principal: Principal,+ project: Project+): boolean => {+ return (+ project.memberList.findIndex(+ (member) =>+ member.roleProvider === project.roleProvider &&+ member.role === "OWNER" &&+ member.principal.id === principal.id+ ) >= 0+ );+};diff --git a/frontend/src/views/EnvironmentDashboard.vue b/frontend/src/views/EnvironmentDashboard.vueindex e5b7d2226b..51f3a040ad 100644--- a/frontend/src/views/EnvironmentDashboard.vue+++ b/frontend/src/views/EnvironmentDashboard.vue@@ -93,6 +93,7 @@ const DEFAULT_NEW_ENVIRONMENT: EnvironmentCreate = {const DEFAULT_NEW_APPROVAL_POLICY: PolicyUpsert = {payload: {value: DefaultApprovalPolicy,+ assigneeGroupList: [],},};diff --git a/frontend/src/views/EnvironmentDetail.vue b/frontend/src/views/EnvironmentDetail.vueindex 1f1202700c..4f740f2176 100644--- a/frontend/src/views/EnvironmentDetail.vue+++ b/frontend/src/views/EnvironmentDetail.vue@@ -35,7 +35,13 @@ import {BackupPlanPolicyPayload,} from "../types";import { idFromSlug } from "../utils";-import { hasFeature, useEnvironmentStore, usePolicyStore } from "@/store";+import {+ hasFeature,+ pushNotification,+ useEnvironmentStore,+ usePolicyStore,+} from "@/store";+import { useI18n } from "vue-i18n";interface LocalState {environment: Environment;@@ -63,6 +69,7 @@ export default defineComponent({setup(props, { emit }) {const environmentStore = useEnvironmentStore();const policyStore = usePolicyStore();+ const { t } = useI18n();const state = reactive<LocalState>({environment: environmentStore.getEnvironmentById(@@ -105,6 +112,14 @@ export default defineComponent({}).then((environment) => {assignEnvironment(environment);++ pushNotification({+ module: "bytebase",+ style: "SUCCESS",+ title: t("environment.successfully-updated-environment", {+ name: environment.name,+ }),+ });});};@@ -172,6 +187,14 @@ export default defineComponent({} else if (type === "bb.policy.backup-plan") {state.backupPolicy = policy;}++ pushNotification({+ module: "bytebase",+ style: "SUCCESS",+ title: t("environment.successfully-updated-environment", {+ name: state.environment.name,+ }),+ });});};