Skip to content

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

Create dedicated endpoint for updating the task and stage status

天舟d08447967a33
diff --git a/frontend/src/components/TaskStatusTransitionForm.vue b/frontend/src/components/TaskStatusTransitionForm.vue
index 7a80ecce0f..3dc57c1667 100644
--- a/frontend/src/components/TaskStatusTransitionForm.vue
+++ b/frontend/src/components/TaskStatusTransitionForm.vue
@@ -81,7 +81,7 @@
type="button"
class="ml-3 px-4 py-2"
v-bind:class="submitButtonStyle"
- @click.prevent="$emit('submit', state.outputValueList, state.comment)"
+ @click.prevent="$emit('submit', state.comment)"
>
{{ okText }}
</button>
diff --git a/frontend/src/miragejs/factories/stage.js b/frontend/src/miragejs/factories/stage.js
index ba1688b872..f72b4b78a3 100644
--- a/frontend/src/miragejs/factories/stage.js
+++ b/frontend/src/miragejs/factories/stage.js
@@ -20,7 +20,7 @@ export default {
return faker.fake("{{lorem.sentence}}");
},
type() {
- return "bytebase.stage.general";
+ return "bytebase.stage.unknown";
},
status() {
return "PENDING";
diff --git a/frontend/src/miragejs/factories/step.js b/frontend/src/miragejs/factories/step.js
index 1c34a9df81..7ebf073913 100644
--- a/frontend/src/miragejs/factories/step.js
+++ b/frontend/src/miragejs/factories/step.js
@@ -20,7 +20,7 @@ export default {
return faker.fake("{{lorem.sentence}}");
},
type() {
- return "bytebase.step.general";
+ return "bytebase.step.final";
},
status() {
return "PENDING";
diff --git a/frontend/src/miragejs/models/index.js b/frontend/src/miragejs/models/index.js
index c76f0a322d..c66f4ba851 100644
--- a/frontend/src/miragejs/models/index.js
+++ b/frontend/src/miragejs/models/index.js
@@ -87,6 +87,7 @@ export default {
}),
taskNew: Model,
taskPatch: Model,
+ taskStatusPatch: Model,
// Stage
stage: Model.extend({
@@ -95,6 +96,7 @@ export default {
database: belongsTo(),
}),
stagePatch: Model,
+ stageStatusPatch: Model,
// Step
step: Model.extend({
diff --git a/frontend/src/miragejs/routes/stage.js b/frontend/src/miragejs/routes/stage.js
new file mode 100644
index 0000000000..f59ce05a55
--- /dev/null
+++ b/frontend/src/miragejs/routes/stage.js
@@ -0,0 +1,144 @@
+import { Response } from "miragejs";
+import isEqual from "lodash-es/isEqual";
+import { WORKSPACE_ID } from "./index";
+import { TaskBuiltinFieldId } from "../../plugins";
+import { UNKNOWN_ID, DEFAULT_PROJECT_ID } from "../../types";
+
+export default function configureStage(route) {
+ route.patch(
+ "/task/:taskId/stage/:stageId/status",
+ function (schema, request) {
+ const attrs = this.normalizedRequestAttrs("stage-status-patch");
+ const task = schema.tasks.find(request.params.taskId);
+
+ if (!task) {
+ return new Response(
+ 404,
+ {},
+ { errors: "Task " + request.params.taskId + " not found" }
+ );
+ }
+
+ const stage = schema.stages.find(request.params.stageId);
+ if (!stage) {
+ return new Response(
+ 404,
+ {},
+ { errors: "Stage " + request.params.stageId + " not found" }
+ );
+ }
+
+ const ts = Date.now();
+
+ if (attrs.status == "DONE") {
+ // We check each steps. Returns error if any of them is not finished.
+ const stepList = schema.steps.where({
+ taskId: task.id,
+ stageId: stage.id,
+ }).models;
+
+ for (let j = 0; j < stepList.length; j++) {
+ if (step[j].status != "DONE" || step[j].status != "SKIPPED") {
+ return new Response(
+ 404,
+ {},
+ {
+ errors: `Can't resolve task ${task.name}. Step ${step[j].name} in stage ${stage[i].name} is in ${step[j].status} status`,
+ }
+ );
+ }
+ }
+ }
+
+ const changeList = [];
+ const messageList = [];
+ const messageTemplate = {
+ containerId: task.id,
+ creatorId: attrs.updaterId,
+ createdTs: ts,
+ updaterId: attrs.updaterId,
+ lastUpdatedTs: ts,
+ status: "DELIVERED",
+ workspaceId: WORKSPACE_ID,
+ };
+
+ if (attrs.status) {
+ if (task.status != attrs.status) {
+ changeList.push({
+ fieldId: TaskBuiltinFieldId.STAGE_STATUS,
+ oldValue: task.status,
+ newValue: attrs.status,
+ });
+
+ messageList.push({
+ ...messageTemplate,
+ type: "bb.msg.task.stage.status.update",
+ receiverId: task.creatorId,
+ payload: {
+ taskName: task.name,
+ oldStatus: task.status,
+ newStatus: attrs.status,
+ },
+ });
+
+ if (task.assigneeId) {
+ messageList.push({
+ ...messageTemplate,
+ type: "bb.msg.task.stage.status.update",
+ receiverId: task.assigneeId,
+ });
+ }
+
+ for (let subscriberId of task.subscriberIdList) {
+ if (
+ subscriberId != task.creatorId &&
+ subscriberId != task.assigneeId
+ ) {
+ messageList.push({
+ ...messageTemplate,
+ type: "bb.msg.task.stage.status.update",
+ receiverId: subscriberId,
+ payload: {
+ taskName: task.name,
+ },
+ });
+ }
+ }
+ }
+ }
+
+ if (changeList.length) {
+ stage.update({ ...attrs, lastUpdatedTs: ts });
+
+ const payload = {
+ changeList,
+ };
+
+ schema.activities.create({
+ creatorId: attrs.updaterId,
+ createdTs: ts,
+ updaterId: attrs.updaterId,
+ lastUpdatedTs: ts,
+ actionType: "bytebase.task.stage.status.update",
+ containerId: updatedTask.id,
+ comment: attrs.comment,
+ payload,
+ workspaceId: WORKSPACE_ID,
+ });
+
+ if (messageList.length > 0) {
+ for (const message of messageList) {
+ // We only send out message if it's NOT destined to self.
+ if (attrs.updaterId != message.receiverId) {
+ schema.messages.create(message);
+ }
+ }
+ }
+
+ return updatedTask;
+ }
+
+ return task;
+ }
+ );
+}
diff --git a/frontend/src/miragejs/routes/task.js b/frontend/src/miragejs/routes/task.js
index 68472c30c2..08474edc36 100644
--- a/frontend/src/miragejs/routes/task.js
+++ b/frontend/src/miragejs/routes/task.js
@@ -96,231 +96,317 @@ export default function configureTask(route) {
route.patch("/task/:taskId", function (schema, request) {
const attrs = this.normalizedRequestAttrs("task-patch");
const task = schema.tasks.find(request.params.taskId);
- if (task) {
- const ts = Date.now();
- const changeList = [];
- const messageList = [];
- const messageTemplate = {
- containerId: task.id,
- creatorId: attrs.updaterId,
- createdTs: ts,
- updaterId: attrs.updaterId,
- lastUpdatedTs: ts,
- status: "DELIVERED",
- workspaceId: WORKSPACE_ID,
- };
- if (attrs.name) {
- if (task.name != attrs.name) {
- changeList.push({
- fieldId: TaskBuiltinFieldId.NAME,
- oldValue: task.name,
- newValue: attrs.name,
- });
- }
- }
+ if (!task) {
+ return new Response(
+ 404,
+ {},
+ { errors: "Task " + request.params.id + " not found" }
+ );
+ }
- if (attrs.status) {
- if (task.status != attrs.status) {
- changeList.push({
- fieldId: TaskBuiltinFieldId.STATUS,
- oldValue: task.status,
- newValue: attrs.status,
- });
+ const ts = Date.now();
+ const changeList = [];
+ const messageList = [];
+ const messageTemplate = {
+ containerId: task.id,
+ creatorId: attrs.updaterId,
+ createdTs: ts,
+ updaterId: attrs.updaterId,
+ lastUpdatedTs: ts,
+ status: "DELIVERED",
+ workspaceId: WORKSPACE_ID,
+ };
+
+ if (attrs.assigneeId) {
+ if (task.assigneeId != attrs.assigneeId) {
+ changeList.push({
+ fieldId: TaskBuiltinFieldId.ASSIGNEE,
+ oldValue: task.assigneeId,
+ newValue: attrs.assigneeId,
+ });
+ // Send a message to the new assignee
+ messageList.push({
+ ...messageTemplate,
+ type: "bb.msg.task.assign",
+ receiverId: attrs.assigneeId,
+ payload: {
+ taskName: task.name,
+ oldAssigneeId: task.assigneeId,
+ newAssigneeId: attrs.assigneeId,
+ },
+ });
+
+ // Send a message to the old assignee
+ if (
+ task.assigneeId != UNKNOWN_ID &&
+ task.creatorId != task.assigneeId
+ ) {
messageList.push({
...messageTemplate,
- type: "bb.msg.task.updatestatus",
- receiverId: task.creatorId,
+ type: "bb.msg.task.assign",
+ receiverId: task.assigneeId,
payload: {
taskName: task.name,
- oldStatus: task.status,
- newStatus: attrs.status,
+ oldAssigneeId: task.assigneeId,
+ newAssigneeId: attrs.assigneeId,
},
});
-
- if (task.assigneeId) {
- messageList.push({
- ...messageTemplate,
- type: "bb.msg.task.updatestatus",
- receiverId: task.assigneeId,
- });
- }
-
- for (let subscriberId of task.subscriberIdList) {
- if (
- subscriberId != task.creatorId &&
- subscriberId != task.assigneeId
- ) {
- messageList.push({
- ...messageTemplate,
- type: "bb.msg.task.updatestatus",
- receiverId: subscriberId,
- payload: {
- taskName: task.name,
- },
- });
- }
- }
}
- }
- if (attrs.assigneeId) {
- if (task.assigneeId != attrs.assigneeId) {
- changeList.push({
- fieldId: TaskBuiltinFieldId.ASSIGNEE,
- oldValue: task.assigneeId,
- newValue: attrs.assigneeId,
- });
-
- // Send a message to the new assignee
+ // Send a message to the creator
+ if (task.creatorId != attrs.assigneeId) {
messageList.push({
...messageTemplate,
type: "bb.msg.task.assign",
- receiverId: attrs.assigneeId,
+ receiverId: task.creatorId,
payload: {
taskName: task.name,
oldAssigneeId: task.assigneeId,
newAssigneeId: attrs.assigneeId,
},
});
+ }
+ }
+ }
- // Send a message to the old assignee
- if (
- task.assigneeId != UNKNOWN_ID &&
- task.creatorId != task.assigneeId
- ) {
- messageList.push({
- ...messageTemplate,
- type: "bb.msg.task.assign",
- receiverId: task.assigneeId,
- payload: {
- taskName: task.name,
- oldAssigneeId: task.assigneeId,
- newAssigneeId: attrs.assigneeId,
- },
- });
- }
+ // Empty string is valid
+ if (attrs.description !== undefined) {
+ if (task.description != attrs.description) {
+ changeList.push({
+ fieldId: TaskBuiltinFieldId.DESCRIPTION,
+ oldValue: task.description,
+ newValue: attrs.description,
+ });
+ }
+ }
- // Send a message to the creator
- if (task.creatorId != attrs.assigneeId) {
- messageList.push({
- ...messageTemplate,
- type: "bb.msg.task.assign",
- receiverId: task.creatorId,
- payload: {
- taskName: task.name,
- oldAssigneeId: task.assigneeId,
- newAssigneeId: attrs.assigneeId,
- },
- });
- }
- }
+ if (attrs.stage !== undefined) {
+ const stage = task.stageList.find((item) => item.id == attrs.stage.id);
+ if (stage) {
+ changeList.push({
+ fieldId: [TaskBuiltinFieldId.STAGE, stage.id].join("."),
+ oldValue: stage.status,
+ newValue: attrs.stage.status,
+ });
+ stage.status = attrs.stage.status;
+ attrs.stageList = task.stageList;
}
+ }
- // Empty string is valid
- if (attrs.description !== undefined) {
- if (task.description != attrs.description) {
- changeList.push({
- fieldId: TaskBuiltinFieldId.DESCRIPTION,
- oldValue: task.description,
- newValue: attrs.description,
- });
- }
+ if (attrs.subscriberIdList !== undefined) {
+ if (task.subscriberIdList != attrs.subscriberIdList) {
+ changeList.push({
+ fieldId: TaskBuiltinFieldId.SUBSCRIBER_LIST,
+ oldValue: task.subscriberIdList,
+ newValue: attrs.subscriberIdList,
+ });
}
+ }
- if (attrs.stage !== undefined) {
- const stage = task.stageList.find((item) => item.id == attrs.stage.id);
- if (stage) {
- changeList.push({
- fieldId: [TaskBuiltinFieldId.STAGE, stage.id].join("."),
- oldValue: stage.status,
- newValue: attrs.stage.status,
- });
- stage.status = attrs.stage.status;
- attrs.stageList = task.stageList;
- }
+ if (attrs.sql !== undefined) {
+ if (task.sql != attrs.sql) {
+ changeList.push({
+ fieldId: TaskBuiltinFieldId.SQL,
+ oldValue: task.sql,
+ newValue: attrs.sql,
+ });
}
+ }
- if (attrs.subscriberIdList !== undefined) {
- if (task.subscriberIdList != attrs.subscriberIdList) {
- changeList.push({
- fieldId: TaskBuiltinFieldId.SUBSCRIBER_LIST,
- oldValue: task.subscriberIdList,
- newValue: attrs.subscriberIdList,
- });
- }
+ if (attrs.rollbackSql !== undefined) {
+ if (task.rollbackSql != attrs.rollbackSql) {
+ changeList.push({
+ fieldId: TaskBuiltinFieldId.ROLLBACK_SQL,
+ oldValue: task.rollbackSql,
+ newValue: attrs.rollbackSql,
+ });
}
+ }
- if (attrs.sql !== undefined) {
- if (task.sql != attrs.sql) {
- changeList.push({
- fieldId: TaskBuiltinFieldId.SQL,
- oldValue: task.sql,
- newValue: attrs.sql,
- });
- }
+ for (const fieldId in attrs.payload) {
+ const oldValue = task.payload[fieldId];
+ const newValue = attrs.payload[fieldId];
+ if (!isEqual(oldValue, newValue)) {
+ changeList.push({
+ fieldId: fieldId,
+ oldValue: task.payload[fieldId],
+ newValue: attrs.payload[fieldId],
+ });
}
+ }
- if (attrs.rollbackSql !== undefined) {
- if (task.rollbackSql != attrs.rollbackSql) {
- changeList.push({
- fieldId: TaskBuiltinFieldId.ROLLBACK_SQL,
- oldValue: task.rollbackSql,
- newValue: attrs.rollbackSql,
- });
+ if (changeList.length) {
+ const updatedTask = task.update({ ...attrs, lastUpdatedTs: ts });
+
+ const payload = {
+ changeList,
+ };
+
+ schema.activities.create({
+ creatorId: attrs.updaterId,
+ createdTs: ts,
+ updaterId: attrs.updaterId,
+ lastUpdatedTs: ts,
+ actionType: "bytebase.task.field.update",
+ containerId: updatedTask.id,
+ comment: attrs.comment,
+ payload,
+ workspaceId: WORKSPACE_ID,
+ });
+
+ if (messageList.length > 0) {
+ for (const message of messageList) {
+ // We only send out message if it's NOT destined to self.
+ if (attrs.updaterId != message.receiverId) {
+ schema.messages.create(message);
+ }
}
}
- for (const fieldId in attrs.payload) {
- const oldValue = task.payload[fieldId];
- const newValue = attrs.payload[fieldId];
- if (!isEqual(oldValue, newValue)) {
- changeList.push({
- fieldId: fieldId,
- oldValue: task.payload[fieldId],
- newValue: attrs.payload[fieldId],
- });
+ return updatedTask;
+ }
+
+ return task;
+ });
+
+ route.patch("/task/:taskId/status", function (schema, request) {
+ const attrs = this.normalizedRequestAttrs("task-status-patch");
+ const task = schema.tasks.find(request.params.taskId);
+
+ if (!task) {
+ return new Response(
+ 404,
+ {},
+ { errors: "Task " + request.params.id + " not found" }
+ );
+ }
+
+ const ts = Date.now();
+
+ if (attrs.status == "DONE") {
+ const stageList = schema.stages.where({ taskId: task.id }).models;
+
+ // We check each of the stage and its steps. Returns error if any of them is not finished.
+ for (let i = 0; i < stageList.length; i++) {
+ if (stage[i].status != "DONE" || stage[i].status != "SKIPPED") {
+ return new Response(
+ 404,
+ {},
+ {
+ errors: `Can't resolve task ${task.name}. Stage ${stage[i].name} is in ${stage[i].status} status`,
+ }
+ );
+ }
+
+ const stepList = schema.steps.where({
+ taskId: task.id,
+ stageId: stage[i].id,
+ }).models;
+
+ for (let j = 0; j < stepList.length; j++) {
+ if (step[j].status != "DONE" || step[j].status != "SKIPPED") {
+ return new Response(
+ 404,
+ {},
+ {
+ errors: `Can't resolve task ${task.name}. Step ${step[j].name} in stage ${stage[i].name} is in ${step[j].status} status`,
+ }
+ );
+ }
}
}
+ }
- if (changeList.length) {
- const updatedTask = task.update({ ...attrs, lastUpdatedTs: ts });
+ const changeList = [];
+ const messageList = [];
+ const messageTemplate = {
+ containerId: task.id,
+ creatorId: attrs.updaterId,
+ createdTs: ts,
+ updaterId: attrs.updaterId,
+ lastUpdatedTs: ts,
+ status: "DELIVERED",
+ workspaceId: WORKSPACE_ID,
+ };
- const payload = {
- changeList,
- };
+ if (attrs.status) {
+ if (task.status != attrs.status) {
+ changeList.push({
+ fieldId: TaskBuiltinFieldId.STATUS,
+ oldValue: task.status,
+ newValue: attrs.status,
+ });
- schema.activities.create({
- creatorId: attrs.updaterId,
- createdTs: ts,
- updaterId: attrs.updaterId,
- lastUpdatedTs: ts,
- actionType: "bytebase.task.field.update",
- containerId: updatedTask.id,
- comment: attrs.comment,
- payload,
- workspaceId: WORKSPACE_ID,
+ messageList.push({
+ ...messageTemplate,
+ type: "bb.msg.task.status.update",
+ receiverId: task.creatorId,
+ payload: {
+ taskName: task.name,
+ oldStatus: task.status,
+ newStatus: attrs.status,
+ },
});
- if (messageList.length > 0) {
- for (const message of messageList) {
- // We only send out message if it's NOT destined to self.
- if (attrs.updaterId != message.receiverId) {
- schema.messages.create(message);
- }
+ if (task.assigneeId) {
+ messageList.push({
+ ...messageTemplate,
+ type: "bb.msg.task.status.update",
+ receiverId: task.assigneeId,
+ });
+ }
+
+ for (let subscriberId of task.subscriberIdList) {
+ if (
+ subscriberId != task.creatorId &&
+ subscriberId != task.assigneeId
+ ) {
+ messageList.push({
+ ...messageTemplate,
+ type: "bb.msg.task.status.update",
+ receiverId: subscriberId,
+ payload: {
+ taskName: task.name,
+ },
+ });
}
}
+ }
+ }
- return updatedTask;
+ if (changeList.length) {
+ const updatedTask = task.update({ ...attrs, lastUpdatedTs: ts });
+
+ const payload = {
+ changeList,
+ };
+
+ schema.activities.create({
+ creatorId: attrs.updaterId,
+ createdTs: ts,
+ updaterId: attrs.updaterId,
+ lastUpdatedTs: ts,
+ actionType: "bytebase.task.status.update",
+ containerId: updatedTask.id,
+ comment: attrs.comment,
+ payload,
+ workspaceId: WORKSPACE_ID,
+ });
+
+ if (messageList.length > 0) {
+ for (const message of messageList) {
+ // We only send out message if it's NOT destined to self.
+ if (attrs.updaterId != message.receiverId) {
+ schema.messages.create(message);
+ }
+ }
}
- return task;
+ return updatedTask;
}
- return new Response(
- 404,
- {},
- { errors: "Task " + request.params.id + " not found" }
- );
+
+ return task;
});
}
diff --git a/frontend/src/miragejs/seeds/index.ts b/frontend/src/miragejs/seeds/index.ts
index be12911292..5fd3ccc8f5 100644
--- a/frontend/src/miragejs/seeds/index.ts
+++ b/frontend/src/miragejs/seeds/index.ts
@@ -194,28 +194,6 @@ const workspacesSeeder = (server: any) => {
workspace: workspace1,
});
- let stage = server.create("stage", {
- creatorId: ws1Dev1.id,
- updaterId: ws1Dev1.id,
- name: "Stage 1",
- type: "bytebase.stage.general",
- status: "PENDING",
- databaseId: databaseList1[0].id,
- task,
- workspace: workspace1,
- });
-
- server.create("step", {
- creatorId: ws1Dev1.id,
- updaterId: ws1Dev1.id,
- name: "Waiting approval",
- type: "bytebase.step.approve",
- status: "PENDING",
- task,
- stage,
- workspace: workspace1,
- });
-
const createdActivity = server.create("activity", {
actionType: "bytebase.task.create",
containerId: task.id,
@@ -240,7 +218,7 @@ const workspacesSeeder = (server: any) => {
});
} else {
server.create("message", {
- type: "bb.msg.task.updatestatus",
+ type: "bb.msg.task.status.update",
containerId: task.id,
creatorId:
ws1UserList[Math.floor(Math.random() * ws1UserList.length)].id,
@@ -271,7 +249,7 @@ const workspacesSeeder = (server: any) => {
});
} else {
server.create("message", {
- type: "bb.msg.task.updatestatus",
+ type: "bb.msg.task.status.update",
containerId: task.id,
creatorId:
ws1UserList[Math.floor(Math.random() * ws1UserList.length)].id,
@@ -302,7 +280,7 @@ const workspacesSeeder = (server: any) => {
});
} else {
server.create("message", {
- type: "bb.msg.task.updatestatus",
+ type: "bb.msg.task.status.update",
containerId: task.id,
creatorId:
ws1UserList[Math.floor(Math.random() * ws1UserList.length)].id,
@@ -332,7 +310,7 @@ const workspacesSeeder = (server: any) => {
});
} else {
server.create("message", {
- type: "bb.msg.task.updatestatus",
+ type: "bb.msg.task.status.update",
containerId: task.id,
creatorId:
ws1UserList[Math.floor(Math.random() * ws1UserList.length)].id,
@@ -384,7 +362,7 @@ const workspacesSeeder = (server: any) => {
workspace: workspace1,
});
- stage = server.create("stage", {
+ const stage = server.create("stage", {
creatorId: ws1Dev1.id,
updaterId: ws1Dev1.id,
name: "Create database",
diff --git a/frontend/src/plugins/task/DefaultTemplate.ts b/frontend/src/plugins/task/DefaultTemplate.ts
index aa0474be3a..a575996fb7 100644
--- a/frontend/src/plugins/task/DefaultTemplate.ts
+++ b/frontend/src/plugins/task/DefaultTemplate.ts
@@ -1,11 +1,5 @@
-import isEmpty from "lodash-es/isEmpty";
import { TaskNew, UNKNOWN_ID } from "../../types";
-import {
- TaskBuiltinFieldId,
- TaskContext,
- TaskTemplate,
- TemplateContext,
-} from "../types";
+import { TaskTemplate, TemplateContext } from "../types";
const template: TaskTemplate = {
type: "bytebase.general",
@@ -14,14 +8,7 @@ const template: TaskTemplate = {
name: "",
type: "bytebase.general",
description: "",
- stageList: [
- {
- name: "Request",
- type: "bytebase.stage.general",
- databaseId: UNKNOWN_ID,
- stepList: [],
- },
- ],
+ stageList: [],
creatorId: ctx.currentUser.id,
subscriberIdList: [],
payload: {},
diff --git a/frontend/src/plugins/types.ts b/frontend/src/plugins/types.ts
index 94367961b7..6fd503cf07 100644
--- a/frontend/src/plugins/types.ts
+++ b/frontend/src/plugins/types.ts
@@ -27,6 +27,7 @@ export enum TaskBuiltinFieldId {
SQL = "11",
ROLLBACK_SQL = "12",
SUBSCRIBER_LIST = "13",
+ STAGE_STATUS = "14",
}
export const INPUT_CUSTOM_FIELD_ID_BEGIN = "100";
diff --git a/frontend/src/store/modules/stage.ts b/frontend/src/store/modules/stage.ts
index 450b14befb..3c775dafee 100644
--- a/frontend/src/store/modules/stage.ts
+++ b/frontend/src/store/modules/stage.ts
@@ -1,9 +1,12 @@
+import axios from "axios";
import { root } from "postcss";
import {
ResourceIdentifier,
ResourceObject,
Stage,
+ StageId,
StageState,
+ StageStatusPatch,
Step,
Task,
TaskId,
@@ -78,6 +81,30 @@ const getters = {
return result;
},
+
+ async updateStageStatus(
+ { dispatch }: any,
+ {
+ taskId,
+ stageId,
+ stageStatusPatch,
+ }: {
+ taskId: TaskId;
+ stageId: StageId;
+ stageStatusPatch: StageStatusPatch;
+ }
+ ) {
+ const data = (
+ await axios.patch(`/api/task/${taskId}/stage/${stageId}/status`, {
+ data: {
+ type: "stagestatuspatch",
+ attributes: stageStatusPatch,
+ },
+ })
+ ).data;
+
+ dispatch("task/fetchTaskById", taskId, { root: true });
+ },
};
const actions = {};
diff --git a/frontend/src/store/modules/task.ts b/frontend/src/store/modules/task.ts
index 4ce5eebaef..ce61e5238d 100644
--- a/frontend/src/store/modules/task.ts
+++ b/frontend/src/store/modules/task.ts
@@ -13,6 +13,7 @@ import {
ResourceIdentifier,
ProjectId,
Stage,
+ TaskStatusPatch,
} from "../../types";
function convert(
@@ -202,6 +203,39 @@ const actions = {
return updatedTask;
},
+
+ async updateTaskStatus(
+ { commit, dispatch, rootGetters }: any,
+ {
+ taskId,
+ taskStatusPatch,
+ }: {
+ taskId: TaskId;
+ taskStatusPatch: TaskStatusPatch;
+ }
+ ) {
+ const data = (
+ await axios.patch(
+ `/api/task/${taskId}/status?include=project,stage,step`,
+ {
+ data: {
+ type: "taskstatuspatch",
+ attributes: taskStatusPatch,
+ },
+ }
+ )
+ ).data;
+ const updatedTask = convert(data.data, data.included, rootGetters);
+
+ commit("setTaskById", {
+ taskId: taskId,
+ task: updatedTask,
+ });
+
+ dispatch("activity/fetchActivityListForTask", taskId, { root: true });
+
+ return updatedTask;
+ },
};
const mutations = {
diff --git a/frontend/src/types/bytebase.ts b/frontend/src/types/bytebase.ts
index 61c1d36322..7a5b3a78eb 100644
--- a/frontend/src/types/bytebase.ts
+++ b/frontend/src/types/bytebase.ts
@@ -180,7 +180,7 @@ export const unknown = (
updater: UNKNOWN_PRINCIPAL,
lastUpdatedTs: 0,
name: "<<Unknown stage>>",
- type: "bytebase.stage.general",
+ type: "bytebase.stage.unknown",
status: "PENDING",
task: UNKNOWN_TASK,
database: UNKNOWN_DATABASE,
@@ -196,7 +196,7 @@ export const unknown = (
updater: UNKNOWN_PRINCIPAL,
lastUpdatedTs: 0,
name: "<<Unknown step>>",
- type: "bytebase.step.general",
+ type: "bytebase.step.unknown",
status: "PENDING",
};
@@ -270,6 +270,33 @@ export const unknown = (
}
};
+export const FINAL_STAGE: Stage = {
+ id: "0",
+ creator: unknown("PRINCIPAL") as Principal,
+ createdTs: 0,
+ updater: unknown("PRINCIPAL") as Principal,
+ lastUpdatedTs: 0,
+ name: "Final stage",
+ type: "bytebase.stage.final",
+ status: "PENDING",
+ task: unknown("TASK") as Task,
+ database: unknown("DATABASE") as Database,
+ stepList: [],
+};
+
+export const FINAL_STEP: Step = {
+ id: "0",
+ task: unknown("TASK") as Task,
+ stage: FINAL_STAGE,
+ creator: unknown("PRINCIPAL") as Principal,
+ createdTs: 0,
+ updater: unknown("PRINCIPAL") as Principal,
+ lastUpdatedTs: 0,
+ name: "Final step",
+ type: "bytebase.step.final",
+ status: "PENDING",
+};
+
// These ID format may change in the future, so we encapsulate with a type.
// Also good for readability.
@@ -635,18 +662,24 @@ export type TaskPatch = {
// Domain specific fields
name?: string;
- status?: TaskStatus;
description?: string;
subscriberIdList?: PrincipalId[];
sql?: string;
rollbackSql?: string;
assigneeId?: PrincipalId;
- stage?: StageProgressPatch;
payload?: TaskPayload;
+};
+
+export type TaskStatusPatch = {
+ // Standard fields
+ updaterId: PrincipalId;
+
+ // Domain specific fields
+ status: TaskStatus;
comment?: string;
};
-export type TaskStatusTransitionType = "RESOLVE" | "ABORT" | "REOPEN";
+export type TaskStatusTransitionType = "NEXT" | "RESOLVE" | "ABORT" | "REOPEN";
export interface TaskStatusTransition {
type: TaskStatusTransitionType;
@@ -658,6 +691,14 @@ export const TASK_STATUS_TRANSITION_LIST: Map<
TaskStatusTransitionType,
TaskStatusTransition
> = new Map([
+ [
+ "NEXT",
+ {
+ type: "NEXT",
+ actionName: "Next",
+ to: "OPEN",
+ },
+ ],
[
"RESOLVE",
{
@@ -684,9 +725,30 @@ export const TASK_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<
+ TaskStatus,
+ TaskStatusTransitionType[]
+> = new Map([
+ ["OPEN", ["ABORT"]],
+ ["DONE", ["REOPEN"]],
+ ["CANCELED", ["REOPEN"]],
+]);
+
+export const ASSIGNEE_APPLICABLE_ACTION_LIST: Map<
+ TaskStatus,
+ TaskStatusTransitionType[]
+> = new Map([
+ ["OPEN", ["NEXT", "RESOLVE", "ABORT"]],
+ ["DONE", ["REOPEN"]],
+ ["CANCELED", ["REOPEN"]],
+]);
+
// Stage
export type StageType =
- | "bytebase.stage.general"
+ | "bytebase.stage.unknown"
+ | "bytebase.stage.final"
| "bytebase.stage.transition"
| "bytebase.stage.database.create"
| "bytebase.stage.database.grant"
@@ -732,9 +794,10 @@ export type StageNew = {
type: StageType;
};
-export type StageProgressPatch = {
- id: StageId;
+export type StageStatusPatch = {
+ updaterId: PrincipalId;
status: StageStatus;
+ comment?: string;
};
export type StageStatusTransitionType = "RUN" | "RETRY" | "STOP" | "SKIP";
@@ -790,7 +853,9 @@ export const STAGE_TRANSITION_LIST: Map<
// Step
export type StepType =
- | "bytebase.step.general"
+ | "bytebase.step.unknown"
+ | "bytebase.step.final"
+ | "bytebase.step.resolve"
| "bytebase.step.approve"
| "bytebase.step.database.schema.update";
@@ -841,7 +906,9 @@ export type StepPatch = {
export type TaskActionType =
| "bytebase.task.create"
| "bytebase.task.comment.create"
- | "bytebase.task.field.update";
+ | "bytebase.task.field.update"
+ | "bytebase.task.status.update"
+ | "bytebase.task.stage.status.update";
export type ActionType = TaskActionType;
@@ -926,7 +993,8 @@ export type InstanceMessageType =
export type TaskMessageType =
| "bb.msg.task.assign"
- | "bb.msg.task.updatestatus"
+ | "bb.msg.task.status.update"
+ | "bb.msg.task.stage.status.update"
| "bb.msg.task.comment";
export type MessageType =
diff --git a/frontend/src/utils/task.ts b/frontend/src/utils/task.ts
index e8d1fb7639..b5e56feaea 100644
--- a/frontend/src/utils/task.ts
+++ b/frontend/src/utils/task.ts
@@ -1,5 +1,12 @@
-import { Task, StageId, Stage, EnvironmentId, DatabaseId } from "../types";
-import { templateForType } from "../plugins";
+import {
+ Task,
+ StageId,
+ Stage,
+ EnvironmentId,
+ DatabaseId,
+ Step,
+ FINAL_STAGE,
+} from "../types";
export function stageName(task: Task, stageId: StageId): string {
for (const stage of task.stageList) {
@@ -10,13 +17,9 @@ export function stageName(task: Task, stageId: StageId): string {
return "<<Unknown stage>>";
}
-// Returns true if the last stage of the task is DONE or SKIPPED
+// Returns true if the active step is the last step in the entire task
export function pendingResolve(task: Task): boolean {
- const lastStage = task.stageList[task.stageList.length - 1];
- if (activeStage(task) == lastStage) {
- return lastStage.status === "DONE" || lastStage.status === "SKIPPED";
- }
- return false;
+ return activeStage(task).type == "bytebase.stage.final";
}
export function activeStage(task: Task): Stage {
@@ -31,7 +34,7 @@ export function activeStage(task: Task): Stage {
return stage;
}
}
- return task.stageList[task.stageList.length - 1];
+ return FINAL_STAGE;
}
export function activeStageIsRunning(task: Task): boolean {
diff --git a/frontend/src/views/Inbox.vue b/frontend/src/views/Inbox.vue
index 90453dc761..747e7f0466 100644
--- a/frontend/src/views/Inbox.vue
+++ b/frontend/src/views/Inbox.vue
@@ -121,7 +121,7 @@
</router-link>
</template>
<template
- v-else-if="message.type == 'bb.msg.task.updatestatus'"
+ v-else-if="message.type == 'bb.msg.task.status.update'"
>
<router-link
:to="`/task/${message.containerId}`"
@@ -334,7 +334,7 @@ export default {
}
return "assigned task";
}
- case "bb.msg.task.updatestatus": {
+ case "bb.msg.task.status.update": {
const payload = message.payload as TaskUpdateStatusMessagePayload;
return (
"changed task status from " +
@@ -343,6 +343,15 @@ export default {
payload.newStatus
);
}
+ case "bb.msg.task.stage.status.update": {
+ const payload = message.payload as TaskUpdateStatusMessagePayload;
+ return (
+ "changed task stage status from " +
+ payload.oldStatus +
+ " to " +
+ payload.newStatus
+ );
+ }
case "bb.msg.task.comment":
return "commented task";
}
diff --git a/frontend/src/views/TaskActivityPanel.vue b/frontend/src/views/TaskActivityPanel.vue
index 76b9dd4b8c..4a91908555 100644
--- a/frontend/src/views/TaskActivityPanel.vue
+++ b/frontend/src/views/TaskActivityPanel.vue
@@ -486,7 +486,9 @@ export default {
return "created task";
case "bytebase.task.comment.create":
return "commented";
- case "bytebase.task.field.update": {
+ case "bytebase.task.field.update":
+ case "bytebase.task.status.update":
+ case "bytebase.task.stage.status.update": {
const updateInfoList: string[] = [];
for (const update of (activity.payload as ActionTaskFieldUpdatePayload)
?.changeList || []) {
@@ -501,6 +503,10 @@ export default {
name = "status";
oldValue = update.oldValue;
newValue = update.newValue;
+ } else if (update.fieldId == TaskBuiltinFieldId.STAGE_STATUS) {
+ name = "stage status";
+ oldValue = update.oldValue;
+ newValue = update.newValue;
} else if (update.fieldId == TaskBuiltinFieldId.ASSIGNEE) {
name = "assignee";
if (update.oldValue) {
diff --git a/frontend/src/views/TaskDetail.vue b/frontend/src/views/TaskDetail.vue
index 0e936eb7ea..639b08d494 100644
--- a/frontend/src/views/TaskDetail.vue
+++ b/frontend/src/views/TaskDetail.vue
@@ -37,6 +37,8 @@
index == 0
? transition.type == 'RESOLVE'
? 'btn-success'
+ : transition.type == 'NEXT'
+ ? 'btn-primary'
: 'btn-normal'
: 'btn-normal mr-2'
"
@@ -152,13 +154,9 @@
:transition="updateStatusModalState.payload.transition"
:outputFieldList="outputFieldList"
@submit="
- (outputValueList, comment) => {
+ (comment) => {
updateStatusModalState.show = false;
- doTaskStatusTransition(
- updateStatusModalState.payload,
- outputValueList,
- comment
- );
+ doTaskStatusTransition(updateStatusModalState.payload, comment);
}
"
@cancel="
@@ -185,7 +183,7 @@ import { useRouter } from "vue-router";
import cloneDeep from "lodash-es/cloneDeep";
import isEmpty from "lodash-es/isEmpty";
import isEqual from "lodash-es/isEqual";
-import { idFromSlug, taskSlug, isDemo } from "../utils";
+import { idFromSlug, taskSlug, isDemo, pendingResolve } from "../utils";
import TaskHighlightPanel from "../views/TaskHighlightPanel.vue";
import TaskStageFlow from "./TaskStageFlow.vue";
import TaskOutputPanel from "../views/TaskOutputPanel.vue";
@@ -199,13 +197,17 @@ import {
TaskNew,
TaskType,
TaskPatch,
- TaskStatus,
TaskStatusTransition,
TaskStatusTransitionType,
- StageProgressPatch,
+ StageStatusPatch,
PrincipalId,
TASK_STATUS_TRANSITION_LIST,
Database,
+ ASSIGNEE_APPLICABLE_ACTION_LIST,
+ CREATOR_APPLICABLE_ACTION_LIST,
+ TaskStatusPatch,
+ StageStatus,
+ StageId,
} from "../types";
import {
defaulTemplate,
@@ -215,25 +217,7 @@ import {
TaskContext,
} from "../plugins";
-// 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.
-const CREATOR_APPLICABLE_ACTION_LIST: Map<
- TaskStatus,
- TaskStatusTransitionType[]
-> = new Map([
- ["OPEN", ["ABORT"]],
- ["DONE", ["REOPEN"]],
- ["CANCELED", ["REOPEN"]],
-]);
-
-const ASSIGNEE_APPLICABLE_ACTION_LIST: Map<
- TaskStatus,
- TaskStatusTransitionType[]
-> = new Map([
- ["OPEN", ["RESOLVE", "ABORT"]],
- ["DONE", ["REOPEN"]],
- ["CANCELED", ["REOPEN"]],
-]);
+type WorkflowType = "SINGLE_STEP" | "SINGLE_STAGE" | "MULTI_STAGE";
type UpdateStatusModalStatePayload = {
transition: TaskStatusTransition;
@@ -504,10 +488,17 @@ export default {
const allowTransition = (transition: TaskStatusTransition): boolean => {
const task: Task = state.task as Task;
if (transition.type == "RESOLVE") {
- // if (pendingResolve(task)) {
- return allowResolve.value;
- // }
- // return false;
+ if (pendingResolve(task)) {
+ // Returns false if any of the required output fields is not provided.
+ for (let i = 0; i < outputFieldList.value.length; i++) {
+ const field = outputFieldList.value[i];
+ if (field.required && !field.resolved(taskContext.value)) {
+ return false;
+ }
+ }
+ return true;
+ }
+ return false;
}
return true;
};
@@ -540,26 +531,20 @@ export default {
const doTaskStatusTransition = (
payload: UpdateStatusModalStatePayload,
- outputValueList: string[],
comment?: string
) => {
- let payloadChanged = false;
- for (let i = 0; i < outputValueList.length; i++) {
- const field = outputFieldList.value[i];
- if (!isEqual(state.task.payload[field.id], outputValueList[i])) {
- state.task.payload[field.id] = outputValueList[i];
- payloadChanged = true;
- }
- }
+ const taskStatusPatch: TaskStatusPatch = {
+ updaterId: currentUser.value.id,
+ status: payload.transition.to,
+ comment: comment ? comment.trim() : undefined,
+ };
- const theComment = comment ? comment.trim() : undefined;
- patchTask(
- {
- status: payload.transition.to,
- comment: theComment ? theComment : undefined,
- payload: payloadChanged ? state.task.payload : undefined,
- },
- () => {
+ store
+ .dispatch("task/updateTaskStatus", {
+ taskId: (state.task as Task).id,
+ taskStatusPatch,
+ })
+ .then((updatedTask) => {
if (
payload.transition.to == "DONE" &&
taskTemplate.value.type == "bytebase.database.schema.update"
@@ -570,8 +555,25 @@ export default {
});
}
payload.didTransit();
- }
- );
+ });
+ };
+
+ const changeStageStatus = (
+ stageId: StageId,
+ stageStatus: StageStatus,
+ comment?: string
+ ) => {
+ const stageStatusPatch: StageStatusPatch = {
+ updaterId: currentUser.value.id,
+ status: stageStatus,
+ comment: comment ? comment.trim() : undefined,
+ };
+
+ store.dispatch("stage/updateStageStatus", {
+ taskId: (state.task as Task).id,
+ stageId,
+ stageStatusPatch,
+ });
};
const updateAssigneeId = (newAssigneeId: PrincipalId) => {
@@ -635,12 +637,20 @@ export default {
});
};
- const changeStageStatus = (stage: StageProgressPatch, comment?: string) => {
- patchTask({
- stage,
- comment,
- });
- };
+ const workflowType = computed(
+ (): WorkflowType => {
+ if (state.task.stageList.length > 1) {
+ return "MULTI_STAGE";
+ }
+ if (
+ state.task.stageList.length == 1 &&
+ state.task.stageList[0].stepList.length > 1
+ ) {
+ return "SINGLE_STAGE";
+ }
+ return "SINGLE_STEP";
+ }
+ );
const allowCreate = computed(() => {
const newTask = state.task as TaskNew;
@@ -668,16 +678,6 @@ export default {
return true;
});
- const allowResolve = computed(() => {
- for (let i = 0; i < outputFieldList.value.length; i++) {
- const field = outputFieldList.value[i];
- if (field.required && !field.resolved(taskContext.value)) {
- return false;
- }
- }
- return true;
- });
-
const allowEditSidebar = computed(() => {
// For now, we only allow assignee to update the field when the task
// is 'OPEN'. This reduces flexibility as creator must ask assignee to
@@ -714,7 +714,7 @@ export default {
});
const showTaskStageFlowBar = computed(() => {
- return !state.new && state.task.stageList.length > 0;
+ return !state.new && workflowType.value != "SINGLE_STEP";
});
const showTaskOutputPanel = computed(() => {
@@ -749,10 +749,24 @@ export default {
}
});
}
- return list.map(
- (type: TaskStatusTransitionType) =>
- TASK_STATUS_TRANSITION_LIST.get(type)!
- );
+
+ return list
+ .filter((item) => {
+ if (pendingResolve(state.task as Task)) {
+ if (item == "NEXT") {
+ return false;
+ }
+ } else {
+ if (item == "RESOLVE") {
+ return false;
+ }
+ }
+ return true;
+ })
+ .map(
+ (type: TaskStatusTransitionType) =>
+ TASK_STATUS_TRANSITION_LIST.get(type)!
+ );
}
);
@@ -771,6 +785,7 @@ export default {
updateCustomField,
doCreate,
changeStageStatus,
+ workflowType,
allowCreate,
currentUser,
taskTemplate,
diff --git a/frontend/src/views/TaskStageFlow.vue b/frontend/src/views/TaskStageFlow.vue
index 5ae20684a4..a71c2a8eac 100644
--- a/frontend/src/views/TaskStageFlow.vue
+++ b/frontend/src/views/TaskStageFlow.vue
@@ -90,7 +90,7 @@
<button
class="btn-icon"
@click.prevent="
- tryChangeStageStatus(applicableStageTransitionList[0])
+ tryChangeStageStatus(stage.id, applicableStageTransitionList[0])
"
>
<template v-if="applicableStageTransitionList[0].type == 'RUN'">
@@ -189,7 +189,7 @@
:key="index"
>
<a
- @click.prevent="tryChangeStageStatus(transition)"
+ @click.prevent="tryChangeStageStatus(stage.id, transition)"
class="menu-item"
role="menuitem"
>
@@ -236,7 +236,7 @@
@submit="
(transition, comment) => {
modalState.show = false;
- doChangeStageStatus(transition, comment);
+ doChangeStageStatus(modalState.stageId, transition, comment);
}
"
@cancel="
@@ -259,6 +259,7 @@ import {
StageStatusTransitionType,
StageStatusTransition,
STAGE_TRANSITION_LIST,
+ UNKNOWN_ID,
} from "../types";
import { activeStage } from "../utils";
@@ -294,6 +295,7 @@ interface FlowItem {
}
interface ModalState {
+ stageId: StageId;
show: boolean;
okText: string;
title: string;
@@ -314,6 +316,7 @@ export default {
const store = useStore();
const modalState = reactive<ModalState>({
+ stageId: UNKNOWN_ID,
show: false,
okText: "OK",
title: "",
@@ -397,7 +400,11 @@ export default {
.map((type) => STAGE_TRANSITION_LIST.get(type));
});
- const tryChangeStageStatus = (transition: StageStatusTransition) => {
+ const tryChangeStageStatus = (
+ stageId: StageId,
+ transition: StageStatusTransition
+ ) => {
+ modalState.stageId = stageId;
modalState.okText = transition.actionName;
modalState.title =
transition.actionName +
@@ -409,17 +416,11 @@ export default {
};
const doChangeStageStatus = (
+ stageId: StageId,
transition: StageStatusTransition,
comment?: string
) => {
- emit(
- "change-stage-status",
- {
- id: activeStage(props.task as Task).id,
- status: transition.to,
- },
- comment
- );
+ emit("change-stage-status", stageId, transition.to, comment);
};
return {