1
1
mirror of https://github.com/go-gitea/gitea synced 2025-07-22 18:28:37 +00:00

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
This commit is contained in:
David Svantesson
2019-10-25 16:46:37 +02:00
committed by Lunny Xiao
parent c34e58fc00
commit 6aa3f8bc29
23 changed files with 333 additions and 216 deletions

View File

@@ -28,8 +28,9 @@ const (
mailAuthResetPassword base.TplName = "auth/reset_passwd"
mailAuthRegisterNotify base.TplName = "auth/register_notify"
mailIssueComment base.TplName = "issue/comment"
mailIssueMention base.TplName = "issue/mention"
mailIssueComment base.TplName = "issue/comment"
mailIssueMention base.TplName = "issue/mention"
mailIssueAssigned base.TplName = "issue/assigned"
mailNotifyCollaborator base.TplName = "notify/collaborator"
)
@@ -183,6 +184,7 @@ func composeIssueCommentMessage(issue *models.Issue, doer *models.User, content
data = composeTplData(subject, body, issue.HTMLURL())
}
data["Doer"] = doer
data["Issue"] = issue
var mailBody bytes.Buffer
@@ -220,3 +222,8 @@ func SendIssueMentionMail(issue *models.Issue, doer *models.User, content string
}
SendAsync(composeIssueCommentMessage(issue, doer, content, comment, mailIssueMention, tos, "issue mention"))
}
// SendIssueAssignedMail composes and sends issue assigned email
func SendIssueAssignedMail(issue *models.Issue, doer *models.User, content string, comment *models.Comment, tos []string) {
SendAsync(composeIssueCommentMessage(issue, doer, content, comment, mailIssueAssigned, tos, "issue assigned"))
}

View File

@@ -10,7 +10,6 @@ import (
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/references"
"code.gitea.io/gitea/modules/setting"
"github.com/unknwon/com"
)
@@ -24,9 +23,6 @@ func mailSubject(issue *models.Issue) string {
// 1. Repository watchers and users who are participated in comments.
// 2. Users who are not in 1. but get mentioned in current issue/comment.
func mailIssueCommentToParticipants(issue *models.Issue, doer *models.User, content string, comment *models.Comment, mentions []string) error {
if !setting.Service.EnableNotifyMail {
return nil
}
watchers, err := models.GetWatchers(issue.RepoID)
if err != nil {