diff options
author | David Svantesson <davidsvantesson@gmail.com> | 2019-10-25 16:46:37 +0200 |
---|---|---|
committer | Lunny Xiao <xiaolunwen@gmail.com> | 2019-10-25 22:46:37 +0800 |
commit | 6aa3f8bc29cb1ed3a1b165cbf526079a751c8c71 (patch) | |
tree | d18aafe7855f9d21fb0d8d7104e7ac7b4aba72b2 /modules | |
parent | c34e58fc008d53a5ec92cadadab2b13fb4e0ae94 (diff) | |
download | gitea-6aa3f8bc29cb1ed3a1b165cbf526079a751c8c71.tar.gz gitea-6aa3f8bc29cb1ed3a1b165cbf526079a751c8c71.zip |
Mail assignee when issue/pull request is assigned (#8546)
* Send email to assigned user
* Only send mail if enabled
* Mail also when assigned through API
* Need to refactor functions from models to issue service
* Refer to issue index rather than ID
* Disable email notifications completly at initalization if global disable
* Check of user enbled mail shall be in mail notification function only
* Initialize notifications from routers init function.
* Use the assigned comment when sending assigned mail
* Refactor so that assignees always added as separate step when new issue/pr.
* Check error from AddAssignees
* Check if user can be assiged to issue or pull request
* Missing return
* Refactor of CanBeAssigned check.
CanBeAssigned shall have same check as UI.
* Clarify function names (toggle rather than update/change), and clean up.
* Fix review comments.
* Flash error if assignees was not added when creating issue/pr
* Generate error if assignee users doesn't exist
Diffstat (limited to 'modules')
-rw-r--r-- | modules/notification/base/notifier.go | 2 | ||||
-rw-r--r-- | modules/notification/base/null.go | 2 | ||||
-rw-r--r-- | modules/notification/mail/mail.go | 10 | ||||
-rw-r--r-- | modules/notification/notification.go | 12 |
4 files changed, 20 insertions, 6 deletions
diff --git a/modules/notification/base/notifier.go b/modules/notification/base/notifier.go index e44f3cc632..c74bb52014 100644 --- a/modules/notification/base/notifier.go +++ b/modules/notification/base/notifier.go @@ -21,7 +21,7 @@ type Notifier interface { NotifyNewIssue(*models.Issue) NotifyIssueChangeStatus(*models.User, *models.Issue, bool) NotifyIssueChangeMilestone(doer *models.User, issue *models.Issue) - NotifyIssueChangeAssignee(doer *models.User, issue *models.Issue, removed bool) + NotifyIssueChangeAssignee(doer *models.User, issue *models.Issue, assignee *models.User, removed bool, comment *models.Comment) NotifyIssueChangeContent(doer *models.User, issue *models.Issue, oldContent string) NotifyIssueClearLabels(doer *models.User, issue *models.Issue) NotifyIssueChangeTitle(doer *models.User, issue *models.Issue, oldTitle string) diff --git a/modules/notification/base/null.go b/modules/notification/base/null.go index 12be1999f9..9fb08884a1 100644 --- a/modules/notification/base/null.go +++ b/modules/notification/base/null.go @@ -83,7 +83,7 @@ func (*NullNotifier) NotifyIssueChangeContent(doer *models.User, issue *models.I } // NotifyIssueChangeAssignee places a place holder function -func (*NullNotifier) NotifyIssueChangeAssignee(doer *models.User, issue *models.Issue, removed bool) { +func (*NullNotifier) NotifyIssueChangeAssignee(doer *models.User, issue *models.Issue, assignee *models.User, removed bool, comment *models.Comment) { } // NotifyIssueClearLabels places a place holder function diff --git a/modules/notification/mail/mail.go b/modules/notification/mail/mail.go index e1ae391f78..0900c6dcdf 100644 --- a/modules/notification/mail/mail.go +++ b/modules/notification/mail/mail.go @@ -5,6 +5,8 @@ package mail import ( + "fmt" + "code.gitea.io/gitea/models" "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/notification/base" @@ -88,3 +90,11 @@ func (m *mailNotifier) NotifyPullRequestReview(pr *models.PullRequest, r *models log.Error("MailParticipants: %v", err) } } + +func (m *mailNotifier) NotifyIssueChangeAssignee(doer *models.User, issue *models.Issue, assignee *models.User, removed bool, comment *models.Comment) { + // mail only sent to added assignees and not self-assignee + if !removed && doer.ID != assignee.ID && assignee.EmailNotifications() == models.EmailNotificationsEnabled { + ct := fmt.Sprintf("Assigned #%d.", issue.Index) + mailer.SendIssueAssignedMail(issue, doer, ct, comment, []string{assignee.Email}) + } +} diff --git a/modules/notification/notification.go b/modules/notification/notification.go index 06220ecb04..0f1b63cf67 100644 --- a/modules/notification/notification.go +++ b/modules/notification/notification.go @@ -12,6 +12,7 @@ import ( "code.gitea.io/gitea/modules/notification/mail" "code.gitea.io/gitea/modules/notification/ui" "code.gitea.io/gitea/modules/notification/webhook" + "code.gitea.io/gitea/modules/setting" ) var ( @@ -24,9 +25,12 @@ func RegisterNotifier(notifier base.Notifier) { notifiers = append(notifiers, notifier) } -func init() { +// NewContext registers notification handlers +func NewContext() { RegisterNotifier(ui.NewNotifier()) - RegisterNotifier(mail.NewNotifier()) + if setting.Service.EnableNotifyMail { + RegisterNotifier(mail.NewNotifier()) + } RegisterNotifier(indexer.NewNotifier()) RegisterNotifier(webhook.NewNotifier()) } @@ -138,9 +142,9 @@ func NotifyIssueChangeContent(doer *models.User, issue *models.Issue, oldContent } // NotifyIssueChangeAssignee notifies change content to notifiers -func NotifyIssueChangeAssignee(doer *models.User, issue *models.Issue, removed bool) { +func NotifyIssueChangeAssignee(doer *models.User, issue *models.Issue, assignee *models.User, removed bool, comment *models.Comment) { for _, notifier := range notifiers { - notifier.NotifyIssueChangeAssignee(doer, issue, removed) + notifier.NotifyIssueChangeAssignee(doer, issue, assignee, removed, comment) } } |