Skip to content

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

Refactor logic to send notification when issue/task status changes.

天舟506db2876bf4
diff --git a/frontend/src/miragejs/routes/issue.js b/frontend/src/miragejs/routes/issue.js
index 772f15a58c..4fcb94793d 100644
--- a/frontend/src/miragejs/routes/issue.js
+++ b/frontend/src/miragejs/routes/issue.js
@@ -3,6 +3,7 @@ import isEqual from "lodash-es/isEqual";
import { WORKSPACE_ID } from "./index";
import { IssueBuiltinFieldId } from "../../plugins";
import { UNKNOWN_ID, DEFAULT_PROJECT_ID } from "../../types";
+import { postIssueMessageToReceiver } from "../utils";
export default function configureIssue(route) {
route.get("/issue", function (schema, request) {
@@ -126,16 +127,17 @@ export default function configureIssue(route) {
newValue: attrs.assigneeId,
});
+ messageTemplate.type = "bb.msg.issue.assign";
+ messageTemplate.payload = {
+ issueName: issue.name,
+ oldAssigneeId: issue.assigneeId,
+ newAssigneeId: attrs.assigneeId,
+ };
+
// Send a message to the new assignee
messageList.push({
...messageTemplate,
- type: "bb.msg.issue.assign",
receiverId: attrs.assigneeId,
- payload: {
- issueName: issue.name,
- oldAssigneeId: issue.assigneeId,
- newAssigneeId: attrs.assigneeId,
- },
});
// Send a message to the old assignee
@@ -145,13 +147,7 @@ export default function configureIssue(route) {
) {
messageList.push({
...messageTemplate,
- type: "bb.msg.issue.assign",
receiverId: issue.assigneeId,
- payload: {
- issueName: issue.name,
- oldAssigneeId: issue.assigneeId,
- newAssigneeId: attrs.assigneeId,
- },
});
}
@@ -159,13 +155,7 @@ export default function configureIssue(route) {
if (issue.creatorId != attrs.assigneeId) {
messageList.push({
...messageTemplate,
- type: "bb.msg.issue.assign",
receiverId: issue.creatorId,
- payload: {
- issueName: issue.name,
- oldAssigneeId: issue.assigneeId,
- newAssigneeId: attrs.assigneeId,
- },
});
}
}
@@ -331,49 +321,19 @@ export default function configureIssue(route) {
workspaceId: WORKSPACE_ID,
};
- if (attrs.status) {
- if (issue.status != attrs.status) {
- changeList.push({
- fieldId: IssueBuiltinFieldId.STATUS,
- oldValue: issue.status,
- newValue: attrs.status,
- });
-
- messageList.push({
- ...messageTemplate,
- type: "bb.msg.issue.status.update",
- receiverId: issue.creatorId,
- payload: {
- issueName: issue.name,
- oldStatus: issue.status,
- newStatus: attrs.status,
- },
- });
-
- if (issue.assigneeId) {
- messageList.push({
- ...messageTemplate,
- type: "bb.msg.issue.status.update",
- receiverId: issue.assigneeId,
- });
- }
+ if (attrs.status && issue.status != attrs.status) {
+ changeList.push({
+ fieldId: IssueBuiltinFieldId.STATUS,
+ oldValue: issue.status,
+ newValue: attrs.status,
+ });
- for (let subscriberId of issue.subscriberIdList) {
- if (
- subscriberId != issue.creatorId &&
- subscriberId != issue.assigneeId
- ) {
- messageList.push({
- ...messageTemplate,
- type: "bb.msg.issue.status.update",
- receiverId: subscriberId,
- payload: {
- issueName: issue.name,
- },
- });
- }
- }
- }
+ messageTemplate.type = "bb.msg.issue.status.update";
+ messageTemplate.payload = {
+ issueName: issue.name,
+ oldStatus: issue.status,
+ newStatus: attrs.status,
+ };
}
if (changeList.length) {
@@ -395,14 +355,12 @@ export default function configureIssue(route) {
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);
- }
- }
- }
+ postIssueMessageToReceiver(
+ schema,
+ updatedIssue,
+ attrs.updaterId,
+ messageTemplate
+ );
return updatedIssue;
}
diff --git a/frontend/src/miragejs/routes/task.js b/frontend/src/miragejs/routes/task.js
index f36910c4c0..05df53c323 100644
--- a/frontend/src/miragejs/routes/task.js
+++ b/frontend/src/miragejs/routes/task.js
@@ -62,49 +62,19 @@ export default function configureTask(route) {
workspaceId: WORKSPACE_ID,
};
- if (attrs.status) {
- if (issue.status != attrs.status) {
- changeList.push({
- fieldId: IssueBuiltinFieldId.TASK_STATUS,
- oldValue: issue.status,
- newValue: attrs.status,
- });
-
- messageList.push({
- ...messageTemplate,
- type: "bb.msg.issue.task.status.update",
- receiverId: issue.creatorId,
- payload: {
- issueName: issue.name,
- oldStatus: issue.status,
- newStatus: attrs.status,
- },
- });
-
- if (issue.assigneeId) {
- messageList.push({
- ...messageTemplate,
- type: "bb.msg.issue.task.status.update",
- receiverId: issue.assigneeId,
- });
- }
+ if (attrs.status && task.status != attrs.status) {
+ changeList.push({
+ fieldId: IssueBuiltinFieldId.TASK_STATUS,
+ oldValue: task.status,
+ newValue: attrs.status,
+ });
- for (let subscriberId of issue.subscriberIdList) {
- if (
- subscriberId != issue.creatorId &&
- subscriberId != issue.assigneeId
- ) {
- messageList.push({
- ...messageTemplate,
- type: "bb.msg.issue.task.status.update",
- receiverId: subscriberId,
- payload: {
- issueName: issue.name,
- },
- });
- }
- }
- }
+ messageTemplate.type = "bb.msg.issue.task.status.update";
+ messageTemplate.payload = {
+ issueName: task.name,
+ oldAssigneeId: task.status,
+ newAssigneeId: attrs.status,
+ };
}
if (changeList.length) {
@@ -126,6 +96,13 @@ export default function configureTask(route) {
workspaceId: WORKSPACE_ID,
});
+ postIssueMessageToReceiver(
+ schema,
+ updatedIssue,
+ attrs.updaterId,
+ messageTemplate
+ );
+
if (messageList.length > 0) {
for (const message of messageList) {
// We only send out message if it's NOT destined to self.
diff --git a/frontend/src/miragejs/utils.js b/frontend/src/miragejs/utils.js
index 8a726fcc43..fd76b44403 100644
--- a/frontend/src/miragejs/utils.js
+++ b/frontend/src/miragejs/utils.js
@@ -1,3 +1,4 @@
+import { UNKNOWN_ID } from "../types";
import { WORKSPACE_ID } from "./routes/index";
export const randomNumber = (quantity) =>
@@ -30,3 +31,40 @@ export const postMessageToOwnerAndDBA = function (
}
}
};
+
+export const postIssueMessageToReceiver = function (
+ schema,
+ issue,
+ creatorId,
+ messageTemplate
+) {
+ const messageList = [];
+
+ messageList.push({
+ ...messageTemplate,
+ receiverId: issue.creatorId,
+ });
+
+ if (issue.assigneeId != UNKNOWN_ID && issue.assigneeId != issue.creatorId) {
+ messageList.push({
+ ...messageTemplate,
+ receiverId: issue.assigneeId,
+ });
+ }
+
+ for (let subscriberId of issue.subscriberIdList) {
+ if (subscriberId != issue.creatorId && subscriberId != issue.assigneeId) {
+ messageList.push({
+ ...messageTemplate,
+ receiverId: subscriberId,
+ });
+ }
+ }
+
+ for (const message of messageList) {
+ // We only send out message if it's NOT destined to self.
+ if (creatorId != message.receiverId) {
+ schema.messages.create(message);
+ }
+ }
+};