Skip to content

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

feat(frontend): update task and issue status transition limitations for assignee (#5526)

Liu Jib6143b69e542
diff --git a/frontend/src/components/Issue/BatchIssueActions.vue b/frontend/src/components/Issue/BatchIssueActions.vue
index 3d6eb5fb45..642d72e5ca 100644
--- a/frontend/src/components/Issue/BatchIssueActions.vue
+++ b/frontend/src/components/Issue/BatchIssueActions.vue
@@ -129,18 +129,9 @@ import type {
IssueStatusTransition,
IssueStatusTransitionType,
} from "@/types";
-import {
- ASSIGNEE_APPLICABLE_ACTION_LIST,
- CREATOR_APPLICABLE_ACTION_LIST,
- ISSUE_STATUS_TRANSITION_LIST,
-} from "@/types";
-import { allTaskList, hasWorkspacePermission } from "@/utils";
-import {
- pushNotification,
- refreshIssueList,
- useCurrentUser,
- useIssueStore,
-} from "@/store";
+import { ISSUE_STATUS_TRANSITION_LIST } from "@/types";
+import { pushNotification, refreshIssueList, useIssueStore } from "@/store";
+import { calcApplicableIssueStatusTransitionList } from "./logic";
type RequestStats = {
total: number;
@@ -180,63 +171,12 @@ const state = reactive<LocalState>({
},
});
-const currentUser = useCurrentUser();
const issueStore = useIssueStore();
const { t } = useI18n();
-const getApplicableIssueStatusTransitionList = (
- issue: Issue
-): IssueStatusTransition[] => {
- const actionList: IssueStatusTransitionType[] = [];
-
- const isHighPrivilegedUser = hasWorkspacePermission(
- "bb.permission.workspace.manage-issue",
- currentUser.value.role
- );
- // The current user is the assignee of the issue
- // or the assignee is SYSTEM_BOT and the current user can manage issue.
- // Users with manage issue permission can change the assignee. If they do
- // want to change the issue status, we require them to first change the assignee
- // and then change the issue status to avoid accidental click.
- const isAssignee =
- issue.assignee?.id === currentUser.value.id || isHighPrivilegedUser;
- if (isAssignee) {
- actionList.push(...ASSIGNEE_APPLICABLE_ACTION_LIST.get(issue.status)!);
- }
- const isCreator =
- issue.creator?.id === currentUser.value.id || isHighPrivilegedUser;
- if (isCreator) {
- CREATOR_APPLICABLE_ACTION_LIST.get(issue.status)!.forEach((item) => {
- if (actionList.indexOf(item) === -1) {
- actionList.push(item);
- }
- });
- }
-
- const applicableActionList: IssueStatusTransition[] = [];
-
- actionList.forEach((type) => {
- const transition = ISSUE_STATUS_TRANSITION_LIST.get(type)!;
- const taskList = allTaskList(issue.pipeline);
- if (taskList.some((task) => task.status === "RUNNING")) {
- // Disallow any issue status transition if some of the tasks are in RUNNING state.
- return;
- }
- if (type === "RESOLVE") {
- // Disallow to "resolve" issue if some of the tasks are NOT DONE.
- if (taskList.some((task) => task.status !== "DONE")) {
- return;
- }
- }
- applicableActionList.push(transition);
- });
-
- return applicableActionList;
-};
-
const issueTransitionList = computed(() => {
return props.issueList.map((issue) => {
- const transitions = getApplicableIssueStatusTransitionList(issue);
+ const transitions = calcApplicableIssueStatusTransitionList(issue);
return { issue, transitions };
});
});
diff --git a/frontend/src/components/Issue/IssueSidebar.vue b/frontend/src/components/Issue/IssueSidebar.vue
index a48642c614..bcbba19bf0 100644
--- a/frontend/src/components/Issue/IssueSidebar.vue
+++ b/frontend/src/components/Issue/IssueSidebar.vue
@@ -42,7 +42,7 @@
<MemberSelect
class="w-full"
:disabled="!allowEditAssignee"
- :selectedId="create ? (issue as IssueCreate).assigneeId : (issue as Issue).assignee?.id"
+ :selected-id="assigneeId as number"
:custom-filter="filterPrincipal"
data-label="bb-assignee-select"
@select-principal-id="
@@ -93,7 +93,7 @@
<div class="col-span-2">
<StageSelect
:pipeline="(issue as Issue).pipeline"
- :selected-id="(selectedStage as Stage).id"
+ :selected-id="(selectedStage as Stage).id as number"
@select-stage-id="(stageId) => selectStageOrTask(stageId)"
/>
</div>
@@ -332,7 +332,6 @@ import {
hasWorkspacePermission,
hidePrefix,
taskSlug,
- isOwnerOfProject,
extractDatabaseNameFromTask,
PRESET_LABEL_KEYS,
} from "@/utils";
@@ -344,9 +343,11 @@ import {
useProjectStore,
} from "@/store";
import {
+ allowUserToBeAssignee,
+ allowUserToChangeAssignee,
+ useCurrentRollOutPolicyForActiveEnvironment,
useExtraIssueLogic,
useIssueLogic,
- useAllowProjectOwnerToApprove,
} from "./logic";
import ProductionEnvironmentIcon from "@/components/Environment/ProductionEnvironmentIcon.vue";
import { SQLEditorButton } from "@/components/DatabaseDetail";
@@ -443,6 +444,13 @@ const project = computed((): Project => {
return (issue.value as Issue).project;
});
+const assigneeId = computed(() => {
+ if (create.value) {
+ return (issue.value as IssueCreate).assigneeId;
+ }
+ return (issue.value as Issue).assignee.id;
+});
+
const databaseEntity = ref<Database>();
const visibleLabelList = computed((): DatabaseLabel[] => {
@@ -479,30 +487,7 @@ const allowEditAssignee = computed(() => {
if (create.value) {
return true;
}
- const issueEntity = issue.value as Issue;
- if (issueEntity.status !== "OPEN") {
- return false;
- }
-
- // Who can re-assign the issue?
- // - The issue creator
- // - The current assignee
- // - Workspace owners and DBAs (they always have the highest privileges)
- if (currentUser.value.id === issueEntity.creator.id) {
- return true;
- }
- if (currentUser.value.id === issueEntity.assignee.id) {
- return true;
- }
- if (
- hasWorkspacePermission(
- "bb.permission.workspace.manage-issue",
- currentUser.value.role
- )
- ) {
- return true;
- }
- return false;
+ return allowUserToChangeAssignee(currentUser.value, issue.value as Issue);
});
const allowEditEarliestAllowedTime = computed(() => {
@@ -620,17 +605,15 @@ const selectTaskId = (taskId: TaskId) => {
if (!task) return;
const slug = taskSlug(task.name, task.id);
const stage = selectedStage.value as Stage;
- selectStageOrTask(stage.id, slug);
+ selectStageOrTask(stage.id as number, slug);
};
-
-const allowProjectOwnerToApprove = useAllowProjectOwnerToApprove();
+const rollOutPolicy = useCurrentRollOutPolicyForActiveEnvironment();
const filterPrincipal = (principal: Principal): boolean => {
- if (allowProjectOwnerToApprove.value) {
- return isOwnerOfProject(principal, project.value);
- }
- return hasWorkspacePermission(
- "bb.permission.workspace.manage-issue",
- principal.role
+ return allowUserToBeAssignee(
+ principal,
+ project.value,
+ rollOutPolicy.value.policy,
+ rollOutPolicy.value.assigneeGroup
);
};
</script>
diff --git a/frontend/src/components/Issue/logic/assignee.ts b/frontend/src/components/Issue/logic/assignee.ts
index 5116fc80c4..1e693d391d 100644
--- a/frontend/src/components/Issue/logic/assignee.ts
+++ b/frontend/src/components/Issue/logic/assignee.ts
@@ -1,16 +1,23 @@
import { computed } from "vue";
import {
+ AssigneeGroupValue,
EnvironmentId,
+ Issue,
IssueCreate,
IssueType,
Pipeline,
PipelineApprovalPolicyPayload,
+ PipelineApprovalPolicyValue,
Policy,
+ Principal,
+ Project,
+ SYSTEM_BOT_ID,
} from "@/types";
import { useIssueLogic } from ".";
import { usePolicyByEnvironmentAndType } from "@/store";
+import { hasWorkspacePermission, isOwnerOfProject } from "@/utils";
-export const useAllowProjectOwnerToApprove = () => {
+export const useCurrentRollOutPolicyForActiveEnvironment = () => {
const { create, issue, activeStageOfPipeline } = useIssueLogic();
const activeEnvironmentId = computed((): EnvironmentId => {
@@ -31,14 +38,86 @@ export const useAllowProjectOwnerToApprove = () => {
}))
);
- const allowProjectOwnerAsAssignee = computed((): boolean => {
+ return computed(() => {
const policy = activeEnvironmentApprovalPolicy.value;
- if (!policy) return false;
-
- return allowProjectOwnerToApprove(policy, issue.value.type);
+ return extractRollOutPolicyValue(policy, issue.value.type);
});
+};
+
+export const extractRollOutPolicyValue = (
+ policy: Policy | undefined,
+ issueType: IssueType
+): {
+ policy: PipelineApprovalPolicyValue;
+ assigneeGroup?: AssigneeGroupValue;
+} => {
+ if (!policy) {
+ return {
+ policy: "MANUAL_APPROVAL_ALWAYS",
+ assigneeGroup: "WORKSPACE_OWNER_OR_DBA",
+ };
+ }
+
+ const payload = policy.payload as PipelineApprovalPolicyPayload;
+ if (payload.value === "MANUAL_APPROVAL_NEVER") {
+ return { policy: "MANUAL_APPROVAL_NEVER" };
+ }
+
+ const assigneeGroup = payload.assigneeGroupList.find(
+ (group) => group.issueType === issueType
+ );
+
+ if (!assigneeGroup || assigneeGroup.value === "WORKSPACE_OWNER_OR_DBA") {
+ return {
+ policy: "MANUAL_APPROVAL_ALWAYS",
+ assigneeGroup: "WORKSPACE_OWNER_OR_DBA",
+ };
+ }
- return allowProjectOwnerAsAssignee;
+ return {
+ policy: "MANUAL_APPROVAL_ALWAYS",
+ assigneeGroup: "PROJECT_OWNER",
+ };
+};
+
+export const allowUserToBeAssignee = (
+ user: Principal,
+ project: Project,
+ policy: PipelineApprovalPolicyValue,
+ assigneeGroup: AssigneeGroupValue | undefined
+): boolean => {
+ const hasWorkspaceIssueManagementPermission = hasWorkspacePermission(
+ "bb.permission.workspace.manage-issue",
+ user.role
+ );
+
+ if (policy === "MANUAL_APPROVAL_NEVER") {
+ // DBA / workspace owner
+ return hasWorkspaceIssueManagementPermission;
+ }
+
+ if (assigneeGroup === "WORKSPACE_OWNER_OR_DBA") {
+ // DBA / workspace owner
+ return hasWorkspaceIssueManagementPermission;
+ }
+
+ if (assigneeGroup === "PROJECT_OWNER") {
+ // Project owner
+ return isOwnerOfProject(user, project);
+ }
+
+ console.assert(false, "should never reach this line");
+ return false;
+};
+
+export const allowUserToChangeAssignee = (user: Principal, issue: Issue) => {
+ if (issue.status !== "OPEN") {
+ return false;
+ }
+ if (issue.assignee.id === SYSTEM_BOT_ID) {
+ return user.id === issue.creator.id;
+ }
+ return user.id === issue.assignee.id;
};
export const allowProjectOwnerToApprove = (
diff --git a/frontend/src/components/Issue/logic/transition.ts b/frontend/src/components/Issue/logic/transition.ts
index 6626cf40cf..e64d353c3c 100644
--- a/frontend/src/components/Issue/logic/transition.ts
+++ b/frontend/src/components/Issue/logic/transition.ts
@@ -2,59 +2,36 @@ import { computed, Ref } from "vue";
import { useCurrentUser } from "@/store";
import {
Issue,
- SYSTEM_BOT_ID,
IssueStatusTransitionType,
- ASSIGNEE_APPLICABLE_ACTION_LIST,
- CREATOR_APPLICABLE_ACTION_LIST,
ISSUE_STATUS_TRANSITION_LIST,
IssueStatusTransition,
+ APPLICABLE_ISSUE_ACTION_LIST,
} from "@/types";
import {
activeStage,
+ activeTask,
allTaskList,
applicableTaskTransition,
- hasWorkspacePermission,
- isOwnerOfProject,
StageStatusTransition,
TaskStatusTransition,
TASK_STATUS_TRANSITION_LIST,
} from "@/utils";
-import { useAllowProjectOwnerToApprove, useIssueLogic } from ".";
+import { useIssueLogic } from ".";
export const useIssueTransitionLogic = (issue: Ref<Issue>) => {
- const {
- create,
- activeTaskOfPipeline,
- allowApplyIssueStatusTransition,
- allowApplyTaskStatusTransition,
- } = useIssueLogic();
+ const { create, activeTaskOfPipeline, 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 (
- hasWorkspacePermission(
- "bb.permission.workspace.manage-issue",
- currentUser.value.role
- )
- ) {
- return true;
- }
- if (
- allowProjectOwnerAsAssignee.value &&
- isOwnerOfProject(currentUser.value, (issue.value as Issue).project)
- ) {
- return true;
- }
- return false;
+ // Only the assignee can apply task status transitions
+ // including roll out, cancel, retry, etc.
+ return issue.value.assignee.id === currentUser.value.id;
});
const getApplicableIssueStatusTransitionList = (
@@ -63,58 +40,7 @@ export const useIssueTransitionLogic = (issue: Ref<Issue>) => {
if (create.value) {
return [];
}
-
- const currentTask = activeTaskOfPipeline(issue.pipeline);
-
- const issueEntity = issue as Issue;
- const list: IssueStatusTransitionType[] = [];
- // Allow assignee, or assignee is the system bot and current user can manage issue
- if (
- currentUser.value.id === issueEntity.assignee?.id ||
- (issueEntity.assignee?.id == SYSTEM_BOT_ID &&
- hasWorkspacePermission(
- "bb.permission.workspace.manage-issue",
- currentUser.value.role
- ))
- ) {
- list.push(...ASSIGNEE_APPLICABLE_ACTION_LIST.get(issueEntity.status)!);
- }
- if (currentUser.value.id === issueEntity.creator.id) {
- CREATOR_APPLICABLE_ACTION_LIST.get(issueEntity.status)!.forEach(
- (item) => {
- if (list.indexOf(item) == -1) {
- list.push(item);
- }
- }
- );
- }
-
- return list
- .map(
- (type: IssueStatusTransitionType) =>
- ISSUE_STATUS_TRANSITION_LIST.get(type)!
- )
- .filter((transition) => {
- const pipeline = issueEntity.pipeline;
- // Disallow any issue status transition if the active task is in RUNNING state.
- if (currentTask.status == "RUNNING") {
- return false;
- }
-
- const taskList = allTaskList(pipeline);
- // Don't display the Resolve action if the last task is NOT in DONE status.
- if (
- transition.type == "RESOLVE" &&
- taskList.length > 0 &&
- (currentTask.id != taskList[taskList.length - 1].id ||
- currentTask.status != "DONE")
- ) {
- return false;
- }
-
- return allowApplyIssueStatusTransition(issue, transition.to);
- })
- .reverse();
+ return calcApplicableIssueStatusTransitionList(issue);
};
const getApplicableStageStatusTransitionList = (issue: Issue) => {
@@ -199,6 +125,56 @@ export const useIssueTransitionLogic = (issue: Ref<Issue>) => {
};
};
+export const calcApplicableIssueStatusTransitionList = (
+ issue: Issue
+): IssueStatusTransition[] => {
+ const currentUser = useCurrentUser();
+ const currentTask = activeTask(issue.pipeline);
+ const flattenTaskList = allTaskList(issue.pipeline);
+
+ const issueEntity = issue as Issue;
+ const transitionTypeList: IssueStatusTransitionType[] = [];
+
+ // The creator and the assignee can apply issue status transition
+ // including resolve, cancel, reopen
+ if (
+ currentUser.value.id === issueEntity.creator?.id ||
+ currentUser.value.id === issueEntity.assignee?.id
+ ) {
+ const actions = APPLICABLE_ISSUE_ACTION_LIST.get(issueEntity.status);
+ if (actions) {
+ transitionTypeList.push(...actions);
+ }
+ }
+
+ const applicableTransitionList: IssueStatusTransition[] = [];
+ transitionTypeList.forEach((type) => {
+ const transition = ISSUE_STATUS_TRANSITION_LIST.get(type);
+ if (!transition) return;
+
+ if (flattenTaskList.some((task) => task.status === "RUNNING")) {
+ // Disallow any issue status transition if some of the tasks are in RUNNING state.
+ return;
+ }
+ if (type === "RESOLVE") {
+ if (transition.type === "RESOLVE" && flattenTaskList.length > 0) {
+ const lastTask = flattenTaskList[flattenTaskList.length - 1];
+ // Don't display the RESOLVE action if the pipeline doesn't reach the
+ // last task
+ if (lastTask.id !== currentTask.id) {
+ return;
+ }
+ // Don't display the RESOLVE action if the last task is not DONE.
+ if (currentTask.status !== "DONE") {
+ return;
+ }
+ }
+ }
+ applicableTransitionList.push(transition);
+ });
+ return applicableTransitionList;
+};
+
export function isApplicableTransition<
T extends IssueStatusTransition | TaskStatusTransition | StageStatusTransition
>(target: T, list: T[]): boolean {
diff --git a/frontend/src/plugins/issue/logic/initialize/assignee.ts b/frontend/src/plugins/issue/logic/initialize/assignee.ts
index d06e7f0ecf..f794a7547e 100644
--- a/frontend/src/plugins/issue/logic/initialize/assignee.ts
+++ b/frontend/src/plugins/issue/logic/initialize/assignee.ts
@@ -1,4 +1,4 @@
-import type { IssueCreate, PipelineApprovalPolicyPayload } from "@/types";
+import type { IssueCreate } from "@/types";
import {
useInstanceStore,
useMemberStore,
@@ -6,6 +6,7 @@ import {
useProjectStore,
} from "@/store";
import { hasWorkspacePermission } from "@/utils";
+import { extractRollOutPolicyValue } from "@/components/Issue/logic";
export const tryGetDefaultAssignee = async (issueCreate: IssueCreate) => {
const firstTask = issueCreate.pipeline?.stageList[0]?.taskList[0];
@@ -21,21 +22,19 @@ export const tryGetDefaultAssignee = async (issueCreate: IssueCreate) => {
type: "bb.policy.pipeline-approval",
});
- const payload = policy.payload as PipelineApprovalPolicyPayload;
+ const rollOutPolicy = extractRollOutPolicyValue(policy, issueCreate.type);
- if (payload.value === "MANUAL_APPROVAL_NEVER") {
+ if (rollOutPolicy.policy === "MANUAL_APPROVAL_NEVER") {
// We don't need to approve manually.
// But we still set the workspace owner or DBA as the default assignee.
// Just to notify the project owner.
assignToWorkspaceOwnerOrDBA(issueCreate);
return;
}
- if (payload.value === "MANUAL_APPROVAL_ALWAYS") {
- const assigneeGroup = payload.assigneeGroupList.find(
- (group) => group.issueType === issueCreate.type
- );
+ if (rollOutPolicy.policy === "MANUAL_APPROVAL_ALWAYS") {
+ const { assigneeGroup } = rollOutPolicy;
- if (assigneeGroup && assigneeGroup.value === "PROJECT_OWNER") {
+ if (assigneeGroup === "PROJECT_OWNER") {
// Assign to the project owner if needed.
assignToProjectOwner(issueCreate);
return;
diff --git a/frontend/src/types/issue.ts b/frontend/src/types/issue.ts
index 2e9da0b2f4..92110165bb 100644
--- a/frontend/src/types/issue.ts
+++ b/frontend/src/types/issue.ts
@@ -204,16 +204,7 @@ export const ISSUE_STATUS_TRANSITION_LIST: Map<
// The first transition in the list is the primary action and the rests are
// the normal action. For now there are at most 1 primary 1 normal action.
-export const CREATOR_APPLICABLE_ACTION_LIST: Map<
- IssueStatus,
- IssueStatusTransitionType[]
-> = new Map([
- ["OPEN", ["CANCEL"]],
- ["DONE", ["REOPEN"]],
- ["CANCELED", ["REOPEN"]],
-]);
-
-export const ASSIGNEE_APPLICABLE_ACTION_LIST: Map<
+export const APPLICABLE_ISSUE_ACTION_LIST: Map<
IssueStatus,
IssueStatusTransitionType[]
> = new Map([