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: create activity on external approval rejected (#3608)
p0ny056d45bb367a
diff --git a/api/activity.go b/api/activity.goindex b760f867a2..f3181e3290 100644--- a/api/activity.go+++ b/api/activity.go@@ -89,6 +89,8 @@ type ActivityIssueCreatePayload struct {// ActivityIssueCommentCreatePayload is the API message payloads for creating issue comments.type ActivityIssueCommentCreatePayload struct {+ ExternalApprovalEvent *ExternalApprovalEvent `json:"externalApprovalEvent"`+// Used by inbox to display info without paying the join costIssueName string `json:"issueName"`}diff --git a/api/external_approval.go b/api/external_approval.goindex 409c01e9bc..5aa6730c7a 100644--- a/api/external_approval.go+++ b/api/external_approval.go@@ -33,9 +33,11 @@ type ExternalApprovalPayloadFeishu struct {StageID intAssigneeID int- // feishu+ // FeishuInstanceCode stringRequesterID string+ // Rejected tells if the approval has been rejected on Feishu.+ Rejected bool}// ExternalApprovalCreate is the API message for creating an ExternalApproval.@@ -59,4 +61,23 @@ type ExternalApprovalFind struct {type ExternalApprovalPatch struct {ID intRowStatus RowStatus++ Payload *string+}++// ExternalApprovalEventActionType is the type of the action which the user took.+type ExternalApprovalEventActionType string++const (+ // ExternalApprovalEventActionApprove means that the user approves via the external approval.+ ExternalApprovalEventActionApprove ExternalApprovalEventActionType = "APPROVE"+ // ExternalApprovalEventActionReject means that the user rejects via the external approval.+ ExternalApprovalEventActionReject ExternalApprovalEventActionType = "REJECT"+)++// ExternalApprovalEvent is the API message for describing an ExternalApproval.+type ExternalApprovalEvent struct {+ Type ExternalApprovalType `json:"type"`+ Action ExternalApprovalEventActionType `json:"action"`+ StageName string `json:"stageName"`}diff --git a/frontend/src/components/Issue/activity/ActionSentence.vue b/frontend/src/components/Issue/activity/ActionSentence.vueindex 8752a3be06..a31e210135 100644--- a/frontend/src/components/Issue/activity/ActionSentence.vue+++ b/frontend/src/components/Issue/activity/ActionSentence.vue@@ -6,6 +6,7 @@import { h, PropType } from "vue";import {Activity,+ ActivityIssueCommentCreatePayload,ActivityTaskEarliestAllowedTimeUpdatePayload,ActivityTaskFileCommitPayload,ActivityTaskStatementUpdatePayload,@@ -34,6 +35,23 @@ const { t } = useI18n();const renderActionSentence = () => {const { activity, issue } = props;if (activity.type.startsWith("bb.issue.")) {+ if (activity.type === "bb.issue.comment.create") {+ const payload = activity.payload as ActivityIssueCommentCreatePayload;+ if (payload.externalApprovalEvent) {+ if (payload.externalApprovalEvent.action == "REJECT") {+ let imName = "";+ switch (payload.externalApprovalEvent.type) {+ case "bb.plugin.app.feishu":+ imName = t("common.feishu");+ break;+ }+ return t("activity.sentence.external-approval-rejected", {+ stageName: payload.externalApprovalEvent.stageName,+ imName: imName,+ });+ }+ }+ }const [tid, params] = issueActivityActionSentence(activity);return t(tid, params);}diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.jsonindex cdc503f38d..50393515e6 100644--- a/frontend/src/locales/en-US.json+++ b/frontend/src/locales/en-US.json@@ -438,7 +438,8 @@"project-member-delete": "delete project member","project-member-role-update": "change project member role","pipeline-task-earliest-allowed-time-update": "update earliest allowed time",- "database-recovery-pitr-done": "restore database to point in time"+ "database-recovery-pitr-done": "restore database to point in time",+ "external-approval-rejected": "external approval rejected"},"sentence": {"created-issue": "created issue",@@ -464,8 +465,9 @@"completed": "completed","failed": "failed","task-name": " task {name}",- "committed-to-at": "committed {file} to{branch}{'@'}{repo}",- "dismissed-stale-approval": "dismissed stale approvals of {task}"+ "committed-to-at": "committed {file} to {branch}{'@'}{repo}",+ "dismissed-stale-approval": "dismissed stale approvals of {task}",+ "external-approval-rejected": "rejected external approval from {imName} of stage \"{stageName}\""},"subject-prefix": {"task": "Task"diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.jsonindex d7641b35d8..1b28e86e08 100644--- a/frontend/src/locales/zh-CN.json+++ b/frontend/src/locales/zh-CN.json@@ -438,7 +438,8 @@"project-member-delete": "删除项目成员","project-member-role-update": "变更项目成员角色","pipeline-task-earliest-allowed-time-update": "更新最早允许执行时间",- "database-recovery-pitr-done": "将数据库恢复到指定时间点"+ "database-recovery-pitr-done": "将数据库恢复到指定时间点",+ "external-approval-rejected": "拒绝外部审批"},"sentence": {"created-issue": "创建工单",@@ -465,7 +466,8 @@"failed": "失败","task-name": "任务 {name}","committed-to-at": "提交 {file} 到 {branch}{'@'}{repo}",- "dismissed-stale-approval": "更新了{task},此前的批准已被撤销"+ "dismissed-stale-approval": "更新了{task},此前的批准已被撤销",+ "external-approval-rejected": "拒绝阶段 \"{stageName}\" 的{imName}外部审批"},"subject-prefix": {"task": "任务"diff --git a/frontend/src/types/activity.ts b/frontend/src/types/activity.tsindex 302faaf2c3..d0311d4a98 100644--- a/frontend/src/types/activity.ts+++ b/frontend/src/types/activity.ts@@ -1,3 +1,4 @@+import { ExternalApprovalEvent } from "./externalApproval";import { FieldId } from "../plugins";import {ActivityId,@@ -99,6 +100,7 @@ export type ActivityIssueCreatePayload = {};export type ActivityIssueCommentCreatePayload = {+ externalApprovalEvent: ExternalApprovalEvent;issueName: string;};diff --git a/frontend/src/types/externalApproval.ts b/frontend/src/types/externalApproval.tsnew file mode 100644index 0000000000..89e49b5cc4--- /dev/null+++ b/frontend/src/types/externalApproval.ts@@ -0,0 +1,9 @@+export type ExternalApprovalType = "bb.plugin.app.feishu";++export type ExternalApprovalEvent = {+ type: ExternalApprovalType;+ action: ExternalApprovalEventActionType;+ stageName: string;+};++export type ExternalApprovalEventActionType = "APPROVE" | "REJECT";diff --git a/frontend/src/types/index.ts b/frontend/src/types/index.tsindex ea051337a5..a5a6662cad 100644--- a/frontend/src/types/index.ts+++ b/frontend/src/types/index.ts@@ -50,3 +50,4 @@ export * from "./sqlReview";export * from "./utils";export * from "./onboardingGuide";export * from "./UIEditor";+export * from "./externalApproval";diff --git a/server/application_runner.go b/server/application_runner.goindex ea981ed658..deb75523e9 100644--- a/server/application_runner.go+++ b/server/application_runner.go@@ -94,6 +94,10 @@ func (r *ApplicationRunner) Run(ctx context.Context, wg *sync.WaitGroup) {continue}+ if payload.Rejected {+ continue+ }+issue, err := r.store.GetIssueByID(ctx, externalApproval.IssueID)if err != nil {log.Error("failed to get issue by issue id", zap.Int("issueID", externalApproval.IssueID), zap.Error(err))@@ -122,7 +126,8 @@ func (r *ApplicationRunner) Run(ctx context.Context, wg *sync.WaitGroup) {continue}- if status == feishu.ApprovalStatusApproved {+ switch status {+ case feishu.ApprovalStatusApproved:// double checkif stage.ID == payload.StageID && payload.AssigneeID == issue.AssigneeID {// approve stage@@ -161,8 +166,59 @@ func (r *ApplicationRunner) Run(ctx context.Context, wg *sync.WaitGroup) {continue}}+ case feishu.ApprovalStatusRejected:+ if err := func() error {+ payload := payload+ payload.Rejected = true+ bytes, err := json.Marshal(payload)+ if err != nil {+ return errors.Wrapf(err, "failed to marshal payload %+v", payload)+ }+ payloadString := string(bytes)++ if _, err := r.store.PatchExternalApproval(ctx, &api.ExternalApprovalPatch{+ ID: externalApproval.ID,+ RowStatus: api.Normal,+ Payload: &payloadString,+ }); err != nil {+ return errors.Wrap(err, "failed to patch external approval")+ }++ stageName := "UNKNOWN"+ for _, stage := range issue.Pipeline.StageList {+ if stage.ID == payload.StageID {+ stageName = stage.Name+ break+ }+ }+ activityPayload, err := json.Marshal(api.ActivityIssueCommentCreatePayload{+ ExternalApprovalEvent: &api.ExternalApprovalEvent{+ Type: api.ExternalApprovalTypeFeishu,+ Action: api.ExternalApprovalEventActionReject,+ StageName: stageName,+ },+ })+ if err != nil {+ return errors.Wrap(err, "failed to marshal ActivityIssueExternalApprovalRejectPayload")+ }++ activityCreate := &api.ActivityCreate{+ CreatorID: payload.AssigneeID,+ ContainerID: issue.ID,+ Type: api.ActivityIssueCommentCreate,+ Level: api.ActivityInfo,+ Comment: "",+ Payload: string(activityPayload),+ }++ if _, err = r.activityManager.CreateActivity(ctx, activityCreate, &ActivityMeta{}); err != nil {+ return errors.Wrap(err, "failed to create activity after external approval rejected")+ }+ return nil+ }(); err != nil {+ log.Error("failed to handle rejected feishu approval", zap.Error(err))+ }}- // Do nothing for ApprovalStatusRejecteddefault:log.Error("Unknown ExternalApproval.Type", zap.Any("ExternalApproval", externalApproval))}@@ -410,6 +466,7 @@ func (r *ApplicationRunner) createExternalApproval(ctx context.Context, issue *aAssigneeID: issue.AssigneeID,InstanceCode: instanceCode,RequesterID: users[issue.Creator.Email],+ Rejected: false,}b, err := json.Marshal(payload)if err != nil {diff --git a/server/issue.go b/server/issue.goindex 34706a072a..bd171ae71b 100644--- a/server/issue.go+++ b/server/issue.go@@ -1303,10 +1303,9 @@ func (s *Server) changeIssueStatus(ctx context.Context, issue *api.Issue, newStaPayload: string(payload),}- _, err = s.ActivityManager.CreateActivity(ctx, activityCreate, &ActivityMeta{+ if _, err = s.ActivityManager.CreateActivity(ctx, activityCreate, &ActivityMeta{issue: updatedIssue,- })- if err != nil {+ }); err != nil {return nil, errors.Wrapf(err, "failed to create activity after changing the issue status: %v", issue.Name)}diff --git a/store/external_approval.go b/store/external_approval.goindex 50413a35be..34aae03739 100644--- a/store/external_approval.go+++ b/store/external_approval.go@@ -270,13 +270,19 @@ func (*Store) findExternalApprovalImpl(ctx context.Context, tx *Tx, find *api.Exfunc (*Store) patchExternalApprovalImpl(ctx context.Context, tx *Tx, patch *api.ExternalApprovalPatch) (*externalApprovalRaw, error) {var raw externalApprovalRaw- query := `+ set, args := []string{"row_status = $1"}, []interface{}{patch.RowStatus}+ if v := patch.Payload; v != nil {+ set, args = append(set, fmt.Sprintf("payload = $%d", len(args)+1)), append(args, *v)+ }+ args = append(args, patch.ID)++ query := fmt.Sprintf(`UPDATE external_approval- SET row_status = $1- WHERE id = $2+ SET `+strings.Join(set, ", ")+`+ WHERE id = $%dRETURNING id, row_status, created_ts, updated_ts, issue_id, requester_id, approver_id, type, payload- `- if err := tx.QueryRowContext(ctx, query, patch.RowStatus, patch.ID).Scan(+ `, len(args))+ if err := tx.QueryRowContext(ctx, query, args...).Scan(&raw.ID,&raw.RowStatus,&raw.CreatedTs,