From 5497e9e3651be5c890c03078a0980119a0793506 Mon Sep 17 00:00:00 2001 From: chengjoey <30427474+chengjoey@users.noreply.github.com> Date: Fri, 31 Dec 2021 18:53:58 +0800 Subject: [PATCH] issue event get context by org locale (#3563) --- .../dop/services/issuestream/issue_stream.go | 22 +++++++++---------- .../issuestream/issue_stream_template.go | 9 ++++++-- .../issuestream/issue_stream_template_test.go | 2 +- .../services/issuestream/issue_stream_test.go | 2 +- 4 files changed, 20 insertions(+), 15 deletions(-) diff --git a/modules/dop/services/issuestream/issue_stream.go b/modules/dop/services/issuestream/issue_stream.go index 96a33a10caa..2528079d8bf 100644 --- a/modules/dop/services/issuestream/issue_stream.go +++ b/modules/dop/services/issuestream/issue_stream.go @@ -143,15 +143,6 @@ func (s *IssueStream) CreateIssueEvent(req *apistructs.IssueStreamCreateRequest) } var content string var err error - if len(req.StreamTypes) == 0 { - content, err = getDefaultContentForMsgSending(req.StreamType, req.StreamParams) - } else { - content, err = s.groupEventContent(req.StreamTypes, req.StreamParams) - } - if err != nil { - logrus.Errorf("get issue %d content error: %v, content will be empty", req.IssueID, err) - } - logrus.Debugf("old issue content is: %s", content) issue, err := s.db.GetIssue(req.IssueID) if err != nil { return err @@ -174,6 +165,15 @@ func (s *IssueStream) CreateIssueEvent(req *apistructs.IssueStreamCreateRequest) if err != nil { return err } + if len(req.StreamTypes) == 0 { + content, err = getDefaultContentForMsgSending(req.StreamType, req.StreamParams, orgModel.Locale) + } else { + content, err = s.groupEventContent(req.StreamTypes, req.StreamParams, orgModel.Locale) + } + if err != nil { + logrus.Errorf("get issue %d content error: %v, content will be empty", req.IssueID, err) + } + logrus.Debugf("old issue content is: %s", content) ev := &apistructs.EventCreateRequest{ EventHeader: apistructs.EventHeader{ Event: bundle.IssueEvent, @@ -215,11 +215,11 @@ func (s *IssueStream) filterReceiversByOperatorID(receivers []string, operatorID return users } -func (s *IssueStream) groupEventContent(streamTypes []apistructs.IssueStreamType, param apistructs.ISTParam) (string, error) { +func (s *IssueStream) groupEventContent(streamTypes []apistructs.IssueStreamType, param apistructs.ISTParam, locale string) (string, error) { var content string interval := ";" for _, streamType := range streamTypes { - tmp, err := getDefaultContentForMsgSending(streamType, param) + tmp, err := getDefaultContentForMsgSending(streamType, param, locale) if err != nil { return "", err } diff --git a/modules/dop/services/issuestream/issue_stream_template.go b/modules/dop/services/issuestream/issue_stream_template.go index f262aca791d..1c000c6ade6 100644 --- a/modules/dop/services/issuestream/issue_stream_template.go +++ b/modules/dop/services/issuestream/issue_stream_template.go @@ -40,6 +40,12 @@ func getIssueStreamTemplate(locale string, ist apistructs.IssueStreamType) (stri // getIssueStreamTemplateForMsgSending get issue stream template for msg sending func getIssueStreamTemplateForMsgSending(locale string, ist apistructs.IssueStreamType) (string, error) { + if locale == "" || locale == "zh-CN" { + locale = "zh" + } + if locale == "en-US" { + locale = "en" + } templateContent, err := getIssueStreamTemplate(locale, ist) if err != nil { return "", err @@ -70,8 +76,7 @@ func getDefaultContent(ist apistructs.IssueStreamType, param apistructs.ISTParam } // getDefaultContentForMsgSending get rendered msg for sending -func getDefaultContentForMsgSending(ist apistructs.IssueStreamType, param apistructs.ISTParam) (string, error) { - locale := "zh" +func getDefaultContentForMsgSending(ist apistructs.IssueStreamType, param apistructs.ISTParam, locale string) (string, error) { ct, err := getIssueStreamTemplateForMsgSending(locale, ist) if err != nil { return "", err diff --git a/modules/dop/services/issuestream/issue_stream_template_test.go b/modules/dop/services/issuestream/issue_stream_template_test.go index 4259ade0fdd..aa18ded92dc 100644 --- a/modules/dop/services/issuestream/issue_stream_template_test.go +++ b/modules/dop/services/issuestream/issue_stream_template_test.go @@ -238,7 +238,7 @@ func Test_getDefaultContentForMsgSending(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - got, err := getDefaultContentForMsgSending(tt.args.ist, tt.args.param) + got, err := getDefaultContentForMsgSending(tt.args.ist, tt.args.param, "zh") if (err != nil) != tt.wantErr { t.Errorf("getDefaultContentForMsgSending() error = %v, wantErr %v", err, tt.wantErr) return diff --git a/modules/dop/services/issuestream/issue_stream_test.go b/modules/dop/services/issuestream/issue_stream_test.go index d2a4ae20ea0..c21ef79677f 100644 --- a/modules/dop/services/issuestream/issue_stream_test.go +++ b/modules/dop/services/issuestream/issue_stream_test.go @@ -30,7 +30,7 @@ func Test_filterReceiversByOperatorID(t *testing.T) { func Test_groupEventContent(t *testing.T) { svc := IssueStream{} - content, err := svc.groupEventContent([]apistructs.IssueStreamType{apistructs.ISTChangeContent}, apistructs.ISTParam{}) + content, err := svc.groupEventContent([]apistructs.IssueStreamType{apistructs.ISTChangeContent}, apistructs.ISTParam{}, "zh") assert.NoError(t, err) assert.Equal(t, "内容发生变更", content) }