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: added inbox/activity log for earliest allowed time change (#258)
Luke Zhoue0c1f3831b26
diff --git a/api/activity.go b/api/activity.goindex af314239fa..4671854e3f 100644--- a/api/activity.go+++ b/api/activity.go@@ -27,6 +27,8 @@ const (ActivityPipelineTaskFileCommit ActivityType = "bb.pipeline.task.file.commit"// ActivityPipelineTaskStatementUpdate is the type for updating pipeline task SQL statement.ActivityPipelineTaskStatementUpdate ActivityType = "bb.pipeline.task.statement.update"+ // ActivityPipelineTaskEarliestAllowedTimeUpdate is the type for updating pipeline task the earliest allowed time.+ ActivityPipelineTaskEarliestAllowedTimeUpdate ActivityType = "bb.pipeline.task.general.earliest-allowed-time.update"// Member related@@ -180,6 +182,16 @@ type ActivityPipelineTaskStatementUpdatePayload struct {TaskName string `json:"taskName"`}+// ActivityPipelineTaskEarliestAllowedTimeUpdatePayload is the API message payloads for pipeline task the earliest allowed time updates.+type ActivityPipelineTaskEarliestAllowedTimeUpdatePayload struct {+ TaskID int `json:"taskId"`+ OldEarliestAllowedTs int64 `json:"oldEarliestAllowedTs,omitempty"`+ NewEarliestAllowedTs int64 `json:"newEarliestAllowedTs,omitempty"`+ // Used by inbox to display info without paying the join cost+ IssueName string `json:"issueName"`+ TaskName string `json:"taskName"`+}+// ActivityMemberCreatePayload is the API message payloads for creating members.type ActivityMemberCreatePayload struct {PrincipalID int `json:"principalId"`diff --git a/frontend/src/components/InboxList.vue b/frontend/src/components/InboxList.vueindex bce1789b98..abae64db6a 100644--- a/frontend/src/components/InboxList.vue+++ b/frontend/src/components/InboxList.vue@@ -61,6 +61,7 @@ import {ActivityIssueStatusUpdatePayload,ActivityTaskStatusUpdatePayload,ActivityTaskStatementUpdatePayload,+ ActivityTaskEarliestAllowedTimeUpdatePayload,Activity,Inbox,} from "../types";@@ -69,6 +70,7 @@ import { useRouter } from "vue-router";import { isEmpty } from "lodash-es";import { issueActivityActionSentence } from "../utils";import { useI18n } from "vue-i18n";+import moment from "moment";export default defineComponent({name: "InboxList",@@ -100,7 +102,8 @@ export default defineComponent({const showCreator = (activity: Activity): boolean => {return (activity.type.startsWith("bb.issue.") ||- activity.type == "bb.pipeline.task.statement.update"+ activity.type == "bb.pipeline.task.statement.update" ||+ activity.type == "bb.pipeline.task.general.earliest-allowed-time.update");};@@ -169,6 +172,22 @@ export default defineComponent({newValue: payload.newStatement,});}+ case "bb.pipeline.task.general.earliest-allowed-time.update": {+ const payload =+ activity.payload as ActivityTaskEarliestAllowedTimeUpdatePayload;+ const oldTs = payload.oldEarliestAllowedTs;+ const newTs = payload.newEarliestAllowedTs;++ return t("activity.sentence.changed-from-to", {+ name: "earliest allowed time",+ oldValue: oldTs+ ? moment(oldTs * 1000)+ : t("task.earliest-allowed-time-unset"),+ newValue: newTs+ ? moment(newTs * 1000)+ : t("task.earliest-allowed-time-unset"),+ });+ }}return "";diff --git a/frontend/src/components/IssueActivityPanel.vue b/frontend/src/components/IssueActivityPanel.vueindex f7586394bf..70d0ea65c9 100644--- a/frontend/src/components/IssueActivityPanel.vue+++ b/frontend/src/components/IssueActivityPanel.vue@@ -350,6 +350,7 @@ import {ActivityIssueFieldUpdatePayload,ActivityTaskStatusUpdatePayload,ActivityTaskStatementUpdatePayload,+ ActivityTaskEarliestAllowedTimeUpdatePayload,UNKNOWN_ID,EMPTY_ID,SYSTEM_BOT_ID,@@ -366,6 +367,7 @@ import {} from "../utils";import { IssueTemplate, IssueBuiltinFieldId } from "../plugins";import { useI18n } from "vue-i18n";+import moment from "moment";interface LocalState {showDeleteCommentModal: boolean;@@ -580,6 +582,12 @@ export default defineComponent({}} else if (activity.type == "bb.pipeline.task.file.commit") {return "commit";+ } else if (activity.type == "bb.pipeline.task.statement.update") {+ return "update";+ } else if (+ activity.type == "bb.pipeline.task.general.earliest-allowed-time.update"+ ) {+ return "update";}return activity.creator.id == SYSTEM_BOT_ID ? "system" : "avatar";@@ -677,6 +685,17 @@ export default defineComponent({newValue: payload.newStatement,});}+ case "bb.pipeline.task.general.earliest-allowed-time.update": {+ const payload =+ activity.payload as ActivityTaskEarliestAllowedTimeUpdatePayload;+ const newVal = payload.newEarliestAllowedTs;+ const oldVal = payload.oldEarliestAllowedTs;+ return t("activity.sentence.changed-from-to", {+ name: "earliest allowed time",+ oldValue: oldVal ? moment(oldVal * 1000) : "Unset",+ newValue: newVal ? moment(newVal * 1000) : "Unset",+ });+ }}return "";};diff --git a/frontend/src/locales/en.yml b/frontend/src/locales/en.ymlindex fa2b4f2587..3c3818ccb5 100644--- a/frontend/src/locales/en.yml+++ b/frontend/src/locales/en.yml@@ -180,7 +180,8 @@ task:earliest-allowed-time: Earliest allowed timeearliest-allowed-time-hint: >-'@:{'common.when'}' specifies the expected execution timing for this task.- If this field is not specified, the task will be executed once it has passed all other gating criteria.+ If this field is not specified, the task will be executed once it has passed+ all other gating criteria.earliest-allowed-time-unset: Unsetcomment: Commentinvoker: Invoker@@ -287,6 +288,7 @@ activity:project-member-create: add project memberproject-member-delete: delete project memberproject-member-role-update: change project member role+ pipeline-task-earliest-allowed-time-update: update earliest allowed timesentence:created-issue: created issuecommented: commenteddiff --git a/frontend/src/locales/zh-CN.yml b/frontend/src/locales/zh-CN.ymlindex e976e0f703..bcccb51876 100644--- a/frontend/src/locales/zh-CN.yml+++ b/frontend/src/locales/zh-CN.yml@@ -281,6 +281,7 @@ activity:project-member-create: 添加项目成员project-member-delete: 删除项目成员project-member-role-update: 变更项目成员角色+ pipeline-task-earliest-allowed-time-update: 更新最早允许执行时间sentence:created-issue: 创建工单commented: 评论diff --git a/frontend/src/types/activity.ts b/frontend/src/types/activity.tsindex f7b7c7c7cd..c56c4008e8 100644--- a/frontend/src/types/activity.ts+++ b/frontend/src/types/activity.ts@@ -14,7 +14,8 @@ export type IssueActivityType =| "bb.issue.status.update"| "bb.pipeline.task.status.update"| "bb.pipeline.task.file.commit"- | "bb.pipeline.task.statement.update";+ | "bb.pipeline.task.statement.update"+ | "bb.pipeline.task.general.earliest-allowed-time.update";export type MemberActivityType =| "bb.member.create"@@ -50,6 +51,8 @@ export function activityName(type: ActivityType): string {return t("activity.type.pipeline-task-file-commit");case "bb.pipeline.task.statement.update":return t("activity.type.pipeline-task-statement-update");+ case "bb.pipeline.task.general.earliest-allowed-time.update":+ return t("activity.type.pipeline-task-earliest-allowed-time-update");case "bb.member.create":return t("activity.type.member-create");case "bb.member.role.update":@@ -120,6 +123,14 @@ export type ActivityTaskStatementUpdatePayload = {taskName: string;};+export type ActivityTaskEarliestAllowedTimeUpdatePayload = {+ taskId: TaskId;+ oldEarliestAllowedTs: number;+ newEarliestAllowedTs: number;+ issueName: string;+ taskName: string;+};+export type ActivityMemberCreatePayload = {principalId: PrincipalId;principalName: string;@@ -161,6 +172,8 @@ export type ActionPayloadType =| ActivityIssueStatusUpdatePayload| ActivityTaskStatusUpdatePayload| ActivityTaskFileCommitPayload+ | ActivityTaskStatementUpdatePayload+ | ActivityTaskEarliestAllowedTimeUpdatePayload| ActivityMemberCreatePayload| ActivityMemberRoleUpdatePayload| ActivityMemberActivateDeactivatePayloaddiff --git a/frontend/src/views/IssueDetail.vue b/frontend/src/views/IssueDetail.vueindex 9ff16290a0..3d37909fde 100644--- a/frontend/src/views/IssueDetail.vue+++ b/frontend/src/views/IssueDetail.vue@@ -755,7 +755,6 @@ export default defineComponent({earliestAllowedTs: newEarliestAllowedTsMs,};patchTask((selectedTask.value as Task).id, taskPatch);- console.log("selectedTask", selectedTask.value.earliestAllowedTs);}};diff --git a/server/activity_manager.go b/server/activity_manager.goindex 78bc9f26b0..ce36cec013 100644--- a/server/activity_manager.go+++ b/server/activity_manager.go@@ -276,6 +276,8 @@ func shouldPostInbox(activity *api.Activity, createType api.ActivityType) (bool,return true, nilcase api.ActivityPipelineTaskStatementUpdate:return true, nil+ case api.ActivityPipelineTaskEarliestAllowedTimeUpdate:+ return true, nilcase api.ActivityPipelineTaskStatusUpdate:update := new(api.ActivityPipelineTaskStatusUpdatePayload)if err := json.Unmarshal([]byte(activity.Payload), update); err != nil {diff --git a/server/task.go b/server/task.goindex 62513dcf94..f198bbdbc9 100644--- a/server/task.go+++ b/server/task.go@@ -81,17 +81,22 @@ func (s *Server) registerTaskRoutes(g *echo.Group) {return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to update task \"%v\"", task.Name)).SetInternal(err)}- // we only create an activity for statement update for now+ if err := s.composeTaskRelationship(ctx, updatedTask); err != nil {+ return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to fetch updated task \"%v\" relationship", updatedTask.Name)).SetInternal(err)+ }++ // create an activity and trigger task check for statement updateif updatedTask.Type == api.TaskDatabaseSchemaUpdate {oldPayload := &api.TaskDatabaseSchemaUpdatePayload{}newPayload := &api.TaskDatabaseSchemaUpdatePayload{}- if err := json.Unmarshal([]byte(updatedTask.Payload), oldPayload); err != nil {+ if err := json.Unmarshal([]byte(updatedTask.Payload), newPayload); err != nil {return echo.NewHTTPError(http.StatusInternalServerError, "Failed to create activity after updating task statement: %v", updatedTask.Name).SetInternal(err)}- if err := json.Unmarshal([]byte(task.Payload), newPayload); err != nil {+ if err := json.Unmarshal([]byte(task.Payload), oldPayload); err != nil {return echo.NewHTTPError(http.StatusInternalServerError, "Failed to create activity after updating task statement: %v", updatedTask.Name).SetInternal(err)}if oldPayload.Statement != newPayload.Statement {+ // create an activityissueFind := &api.IssueFind{PipelineID: &task.PipelineID,}@@ -114,8 +119,8 @@ func (s *Server) registerTaskRoutes(g *echo.Group) {CreatorID: updatedTask.CreatorID,ContainerID: issue.ID,Type: api.ActivityPipelineTaskStatementUpdate,- Level: api.ActivityInfo,Payload: string(payload),+ Level: api.ActivityInfo,}_, err = s.ActivityManager.CreateActivity(ctx, activityCreate, &ActivityMeta{issue: issue,@@ -123,57 +128,86 @@ func (s *Server) registerTaskRoutes(g *echo.Group) {if err != nil {return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to create activity after updating task statement: %v", updatedTask.Name)).SetInternal(err)}++ // For now, we supported MySQL and TiDB dialect check+ if updatedTask.Database.Instance.Engine == db.MySQL || updatedTask.Database.Instance.Engine == db.TiDB {+ payload, err := json.Marshal(api.TaskCheckDatabaseStatementAdvisePayload{+ Statement: *taskPatch.Statement,+ DbType: updatedTask.Database.Instance.Engine,+ Charset: updatedTask.Database.CharacterSet,+ Collation: updatedTask.Database.Collation,+ })+ if err != nil {+ return echo.NewHTTPError(http.StatusInternalServerError, fmt.Errorf("failed to marshal statement advise payload: %v, err: %w", task.Name, err))+ }+ _, err = s.TaskCheckRunService.CreateTaskCheckRunIfNeeded(ctx, &api.TaskCheckRunCreate{+ CreatorID: api.SystemBotID,+ TaskID: task.ID,+ Type: api.TaskCheckDatabaseStatementSyntax,+ Payload: string(payload),+ SkipIfAlreadyTerminated: false,+ })+ if err != nil {+ // It's OK if we failed to trigger a check, just emit an error log+ s.l.Error("Failed to trigger syntax check after changing task statement",+ zap.Int("task_id", task.ID),+ zap.String("task_name", task.Name),+ zap.Error(err),+ )+ }++ _, err = s.TaskCheckRunService.CreateTaskCheckRunIfNeeded(ctx, &api.TaskCheckRunCreate{+ CreatorID: api.SystemBotID,+ TaskID: task.ID,+ Type: api.TaskCheckDatabaseStatementCompatibility,+ Payload: string(payload),+ SkipIfAlreadyTerminated: false,+ })+ if err != nil {+ // It's OK if we failed to trigger a check, just emit an error log+ s.l.Error("Failed to trigger compatibility check after changing task statement",+ zap.Int("task_id", task.ID),+ zap.String("task_name", task.Name),+ zap.Error(err),+ )+ }+ }}- }- if err := s.composeTaskRelationship(ctx, updatedTask); err != nil {- return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to fetch updated task \"%v\" relationship", updatedTask.Name)).SetInternal(err)}+ // create an activity for earliest allowed time update+ if updatedTask.EarliestAllowedTs != task.EarliestAllowedTs {+ // create an activity+ issueFind := &api.IssueFind{+ PipelineID: &task.PipelineID,+ }+ issue, err := s.IssueService.FindIssue(ctx, issueFind)+ if err != nil {+ return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to fetch issue ID after updating task's earliest allowed time: %v", task.PipelineID)).SetInternal(err)+ }- // If we have updated the statement, then we trigger syntax and compatibility check- if task.Type == api.TaskDatabaseSchemaUpdate && taskPatch.Statement != nil {- // For now we only supported MySQL dialect check- if updatedTask.Database.Instance.Engine == db.MySQL || updatedTask.Database.Instance.Engine == db.TiDB {- payload, err := json.Marshal(api.TaskCheckDatabaseStatementAdvisePayload{- Statement: *taskPatch.Statement,- DbType: updatedTask.Database.Instance.Engine,- Charset: updatedTask.Database.CharacterSet,- Collation: updatedTask.Database.Collation,- })- if err != nil {- return echo.NewHTTPError(http.StatusInternalServerError, fmt.Errorf("failed to marshal statement advise payload: %v, err: %w", task.Name, err))- }- _, err = s.TaskCheckRunService.CreateTaskCheckRunIfNeeded(ctx, &api.TaskCheckRunCreate{- CreatorID: api.SystemBotID,- TaskID: task.ID,- Type: api.TaskCheckDatabaseStatementSyntax,- Payload: string(payload),- SkipIfAlreadyTerminated: false,- })- if err != nil {- // It's OK if we failed to trigger a check, just emit an error log- s.l.Error("Failed to trigger syntax check after changing task statement",- zap.Int("task_id", task.ID),- zap.String("task_name", task.Name),- zap.Error(err),- )- }-- _, err = s.TaskCheckRunService.CreateTaskCheckRunIfNeeded(ctx, &api.TaskCheckRunCreate{- CreatorID: api.SystemBotID,- TaskID: task.ID,- Type: api.TaskCheckDatabaseStatementCompatibility,- Payload: string(payload),- SkipIfAlreadyTerminated: false,- })- if err != nil {- // It's OK if we failed to trigger a check, just emit an error log- s.l.Error("Failed to trigger compatibility check after changing task statement",- zap.Int("task_id", task.ID),- zap.String("task_name", task.Name),- zap.Error(err),- )- }+ payload, err := json.Marshal(api.ActivityPipelineTaskEarliestAllowedTimeUpdatePayload{+ TaskID: updatedTask.ID,+ OldEarliestAllowedTs: task.EarliestAllowedTs,+ NewEarliestAllowedTs: updatedTask.EarliestAllowedTs,+ TaskName: task.Name,+ IssueName: issue.Name,+ })+ if err != nil {+ return echo.NewHTTPError(http.StatusInternalServerError, fmt.Errorf("failed to marshal earliest allowed time activity payload: %v, err: %w", task.Name, err))+ }+ activityCreate := &api.ActivityCreate{+ CreatorID: updatedTask.CreatorID,+ ContainerID: issue.ID,+ Type: api.ActivityPipelineTaskEarliestAllowedTimeUpdate,+ Payload: string(payload),+ Level: api.ActivityInfo,+ }+ _, err = s.ActivityManager.CreateActivity(ctx, activityCreate, &ActivityMeta{+ issue: issue,+ })+ if err != nil {+ return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to create activity after updating task earliest allowed time: %v", updatedTask.Name)).SetInternal(err)}}