#2854 fix no mail notification when issue is closed/reopened
This commit is contained in:
parent
7ca5f8f119
commit
f1b8d52eb3
26 changed files with 438 additions and 347 deletions
|
@ -17,7 +17,6 @@ import (
|
|||
"github.com/gogits/gogs/modules/base"
|
||||
"github.com/gogits/gogs/modules/context"
|
||||
"github.com/gogits/gogs/modules/cron"
|
||||
"github.com/gogits/gogs/modules/mailer"
|
||||
"github.com/gogits/gogs/modules/process"
|
||||
"github.com/gogits/gogs/modules/setting"
|
||||
)
|
||||
|
@ -178,7 +177,7 @@ func Dashboard(ctx *context.Context) {
|
|||
func SendTestMail(ctx *context.Context) {
|
||||
email := ctx.Query("email")
|
||||
// Send a test email to the user's email address and redirect back to Config
|
||||
if err := mailer.SendTestMail(email); err != nil {
|
||||
if err := models.SendTestMail(email); err != nil {
|
||||
ctx.Flash.Error(ctx.Tr("admin.config.test_mail_failed", email, err))
|
||||
} else {
|
||||
ctx.Flash.Info(ctx.Tr("admin.config.test_mail_sent", email))
|
||||
|
|
|
@ -14,7 +14,6 @@ import (
|
|||
"github.com/gogits/gogs/modules/base"
|
||||
"github.com/gogits/gogs/modules/context"
|
||||
"github.com/gogits/gogs/modules/log"
|
||||
"github.com/gogits/gogs/modules/mailer"
|
||||
"github.com/gogits/gogs/modules/setting"
|
||||
"github.com/gogits/gogs/routers"
|
||||
)
|
||||
|
@ -115,9 +114,9 @@ func NewUserPost(ctx *context.Context, form auth.AdminCrateUserForm) {
|
|||
}
|
||||
log.Trace("Account created by admin (%s): %s", ctx.User.Name, u.Name)
|
||||
|
||||
// Send e-mail notification.
|
||||
// Send email notification.
|
||||
if form.SendNotify && setting.MailService != nil {
|
||||
mailer.SendRegisterNotifyMail(ctx.Context, u)
|
||||
models.SendRegisterNotifyMail(ctx.Context, u)
|
||||
}
|
||||
|
||||
ctx.Flash.Success(ctx.Tr("admin.users.new_success", u.Name))
|
||||
|
|
|
@ -10,7 +10,6 @@ import (
|
|||
"github.com/gogits/gogs/models"
|
||||
"github.com/gogits/gogs/modules/context"
|
||||
"github.com/gogits/gogs/modules/log"
|
||||
"github.com/gogits/gogs/modules/mailer"
|
||||
"github.com/gogits/gogs/modules/setting"
|
||||
"github.com/gogits/gogs/routers/api/v1/convert"
|
||||
"github.com/gogits/gogs/routers/api/v1/user"
|
||||
|
@ -64,9 +63,9 @@ func CreateUser(ctx *context.APIContext, form api.CreateUserOption) {
|
|||
}
|
||||
log.Trace("Account created by admin (%s): %s", ctx.User.Name, u.Name)
|
||||
|
||||
// Send e-mail notification.
|
||||
// Send email notification.
|
||||
if form.SendNotify && setting.MailService != nil {
|
||||
mailer.SendRegisterNotifyMail(ctx.Context.Context, u)
|
||||
models.SendRegisterNotifyMail(ctx.Context.Context, u)
|
||||
}
|
||||
|
||||
ctx.JSON(201, convert.ToUser(u))
|
||||
|
|
|
@ -14,7 +14,6 @@ import (
|
|||
"github.com/gogits/gogs/modules/context"
|
||||
"github.com/gogits/gogs/modules/setting"
|
||||
"github.com/gogits/gogs/routers/api/v1/convert"
|
||||
"github.com/gogits/gogs/routers/repo"
|
||||
)
|
||||
|
||||
func ListIssues(ctx *context.APIContext) {
|
||||
|
@ -80,9 +79,6 @@ func CreateIssue(ctx *context.APIContext, form api.CreateIssueOption) {
|
|||
if err := models.NewIssue(ctx.Repo.Repository, issue, form.Labels, nil); err != nil {
|
||||
ctx.Error(500, "NewIssue", err)
|
||||
return
|
||||
} else if err := repo.MailWatchersAndMentions(ctx.Context, issue); err != nil {
|
||||
ctx.Error(500, "MailWatchersAndMentions", err)
|
||||
return
|
||||
}
|
||||
|
||||
if form.Closed {
|
||||
|
|
|
@ -22,7 +22,6 @@ import (
|
|||
"github.com/gogits/gogs/modules/base"
|
||||
"github.com/gogits/gogs/modules/context"
|
||||
"github.com/gogits/gogs/modules/log"
|
||||
"github.com/gogits/gogs/modules/mailer"
|
||||
"github.com/gogits/gogs/modules/markdown"
|
||||
"github.com/gogits/gogs/modules/setting"
|
||||
)
|
||||
|
@ -395,46 +394,6 @@ func ValidateRepoMetas(ctx *context.Context, form auth.CreateIssueForm) ([]int64
|
|||
return labelIDs, milestoneID, assigneeID
|
||||
}
|
||||
|
||||
func MailWatchersAndMentions(ctx *context.Context, issue *models.Issue) error {
|
||||
// Update mentions
|
||||
mentions := markdown.MentionPattern.FindAllString(issue.Content, -1)
|
||||
if len(mentions) > 0 {
|
||||
for i := range mentions {
|
||||
mentions[i] = strings.TrimSpace(mentions[i])[1:]
|
||||
}
|
||||
|
||||
if err := models.UpdateMentions(mentions, issue.ID); err != nil {
|
||||
return fmt.Errorf("UpdateMentions: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
repo := ctx.Repo.Repository
|
||||
|
||||
// Mail watchers and mentions.
|
||||
if setting.Service.EnableNotifyMail {
|
||||
tos, err := mailer.SendIssueNotifyMail(ctx.User, ctx.Repo.Owner, repo, issue)
|
||||
if err != nil {
|
||||
return fmt.Errorf("SendIssueNotifyMail: %v", err)
|
||||
}
|
||||
|
||||
tos = append(tos, ctx.User.LowerName)
|
||||
newTos := make([]string, 0, len(mentions))
|
||||
for _, m := range mentions {
|
||||
if com.IsSliceContainsStr(tos, m) {
|
||||
continue
|
||||
}
|
||||
|
||||
newTos = append(newTos, m)
|
||||
}
|
||||
if err = mailer.SendIssueMentionMail(ctx.Render, ctx.User, ctx.Repo.Owner,
|
||||
repo, issue, models.GetUserEmailsByNames(newTos)); err != nil {
|
||||
return fmt.Errorf("SendIssueMentionMail: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func NewIssuePost(ctx *context.Context, form auth.CreateIssueForm) {
|
||||
ctx.Data["Title"] = ctx.Tr("repo.issues.new")
|
||||
ctx.Data["PageIsIssueList"] = true
|
||||
|
@ -471,9 +430,6 @@ func NewIssuePost(ctx *context.Context, form auth.CreateIssueForm) {
|
|||
if err := models.NewIssue(repo, issue, labelIDs, attachments); err != nil {
|
||||
ctx.Handle(500, "NewIssue", err)
|
||||
return
|
||||
} else if err := MailWatchersAndMentions(ctx, issue); err != nil {
|
||||
ctx.Handle(500, "MailWatchersAndMentions", err)
|
||||
return
|
||||
}
|
||||
|
||||
log.Trace("Issue created: %d/%d", repo.ID, issue.ID)
|
||||
|
@ -933,16 +889,6 @@ func NewComment(ctx *context.Context, form auth.CreateCommentForm) {
|
|||
return
|
||||
}
|
||||
|
||||
MailWatchersAndMentions(ctx, &models.Issue{
|
||||
ID: issue.ID,
|
||||
Index: issue.Index,
|
||||
Name: issue.Name,
|
||||
Content: form.Content,
|
||||
})
|
||||
if ctx.Written() {
|
||||
return
|
||||
}
|
||||
|
||||
log.Trace("Comment created: %d/%d/%d", ctx.Repo.Repository.ID, issue.ID, comment.ID)
|
||||
}
|
||||
|
||||
|
@ -1024,7 +970,6 @@ func UpdateLabel(ctx *context.Context, form auth.CreateLabelForm) {
|
|||
return
|
||||
}
|
||||
|
||||
fmt.Println(form.Title, form.Color)
|
||||
l.Name = form.Title
|
||||
l.Color = form.Color
|
||||
if err := models.UpdateLabel(l); err != nil {
|
||||
|
|
|
@ -681,9 +681,6 @@ func CompareAndPullRequestPost(ctx *context.Context, form auth.CreateIssueForm)
|
|||
} else if err := pullRequest.PushToBaseRepo(); err != nil {
|
||||
ctx.Handle(500, "PushToBaseRepo", err)
|
||||
return
|
||||
} else if err := MailWatchersAndMentions(ctx, pullIssue); err != nil {
|
||||
ctx.Handle(500, "MailWatchersAndMentions", err)
|
||||
return
|
||||
}
|
||||
|
||||
log.Trace("Pull request created: %d/%d", repo.ID, pullIssue.ID)
|
||||
|
|
|
@ -15,7 +15,6 @@ import (
|
|||
"github.com/gogits/gogs/modules/base"
|
||||
"github.com/gogits/gogs/modules/context"
|
||||
"github.com/gogits/gogs/modules/log"
|
||||
"github.com/gogits/gogs/modules/mailer"
|
||||
"github.com/gogits/gogs/modules/setting"
|
||||
)
|
||||
|
||||
|
@ -325,10 +324,7 @@ func CollaborationPost(ctx *context.Context) {
|
|||
}
|
||||
|
||||
if setting.Service.EnableNotifyMail {
|
||||
if err = mailer.SendCollaboratorMail(ctx.Render, u, ctx.User, ctx.Repo.Repository); err != nil {
|
||||
ctx.Handle(500, "SendCollaboratorMail", err)
|
||||
return
|
||||
}
|
||||
models.SendCollaboratorMail(u, ctx.User, ctx.Repo.Repository)
|
||||
}
|
||||
|
||||
ctx.Flash.Success(ctx.Tr("repo.settings.add_collaborator_success"))
|
||||
|
|
|
@ -15,7 +15,6 @@ import (
|
|||
"github.com/gogits/gogs/modules/base"
|
||||
"github.com/gogits/gogs/modules/context"
|
||||
"github.com/gogits/gogs/modules/log"
|
||||
"github.com/gogits/gogs/modules/mailer"
|
||||
"github.com/gogits/gogs/modules/setting"
|
||||
)
|
||||
|
||||
|
@ -220,9 +219,9 @@ func SignUpPost(ctx *context.Context, cpt *captcha.Captcha, form auth.RegisterFo
|
|||
}
|
||||
}
|
||||
|
||||
// Send confirmation e-mail, no need for social account.
|
||||
// Send confirmation email, no need for social account.
|
||||
if setting.Service.RegisterEmailConfirm && u.Id > 1 {
|
||||
mailer.SendActivateAccountMail(ctx.Context, u)
|
||||
models.SendActivateAccountMail(ctx.Context, u)
|
||||
ctx.Data["IsSendRegisterMail"] = true
|
||||
ctx.Data["Email"] = u.Email
|
||||
ctx.Data["Hours"] = setting.Service.ActiveCodeLives / 60
|
||||
|
@ -245,13 +244,13 @@ func Activate(ctx *context.Context) {
|
|||
ctx.Error(404)
|
||||
return
|
||||
}
|
||||
// Resend confirmation e-mail.
|
||||
// Resend confirmation email.
|
||||
if setting.Service.RegisterEmailConfirm {
|
||||
if ctx.Cache.IsExist("MailResendLimit_" + ctx.User.LowerName) {
|
||||
ctx.Data["ResendLimited"] = true
|
||||
} else {
|
||||
ctx.Data["Hours"] = setting.Service.ActiveCodeLives / 60
|
||||
mailer.SendActivateAccountMail(ctx.Context, ctx.User)
|
||||
models.SendActivateAccountMail(ctx.Context, ctx.User)
|
||||
|
||||
if err := ctx.Cache.Put("MailResendLimit_"+ctx.User.LowerName, ctx.User.LowerName, 180); err != nil {
|
||||
log.Error(4, "Set cache(MailResendLimit) fail: %v", err)
|
||||
|
@ -355,7 +354,7 @@ func ForgotPasswdPost(ctx *context.Context) {
|
|||
return
|
||||
}
|
||||
|
||||
mailer.SendResetPasswordMail(ctx.Context, u)
|
||||
models.SendResetPasswordMail(ctx.Context, u)
|
||||
if err = ctx.Cache.Put("MailResendLimit_"+u.LowerName, u.LowerName, 180); err != nil {
|
||||
log.Error(4, "Set cache(MailResendLimit) fail: %v", err)
|
||||
}
|
||||
|
|
|
@ -17,7 +17,6 @@ import (
|
|||
"github.com/gogits/gogs/modules/base"
|
||||
"github.com/gogits/gogs/modules/context"
|
||||
"github.com/gogits/gogs/modules/log"
|
||||
"github.com/gogits/gogs/modules/mailer"
|
||||
"github.com/gogits/gogs/modules/setting"
|
||||
)
|
||||
|
||||
|
@ -239,12 +238,12 @@ func SettingsEmailPost(ctx *context.Context, form auth.AddEmailForm) {
|
|||
return
|
||||
}
|
||||
|
||||
e := &models.EmailAddress{
|
||||
email := &models.EmailAddress{
|
||||
UID: ctx.User.Id,
|
||||
Email: form.Email,
|
||||
IsActivated: !setting.Service.RegisterEmailConfirm,
|
||||
}
|
||||
if err := models.AddEmailAddress(e); err != nil {
|
||||
if err := models.AddEmailAddress(email); err != nil {
|
||||
if models.IsErrEmailAlreadyUsed(err) {
|
||||
ctx.RenderWithErr(ctx.Tr("form.email_been_used"), SETTINGS_EMAILS, &form)
|
||||
return
|
||||
|
@ -253,19 +252,19 @@ func SettingsEmailPost(ctx *context.Context, form auth.AddEmailForm) {
|
|||
return
|
||||
}
|
||||
|
||||
// Send confirmation e-mail
|
||||
// Send confirmation email
|
||||
if setting.Service.RegisterEmailConfirm {
|
||||
mailer.SendActivateEmailMail(ctx.Context, ctx.User, e)
|
||||
models.SendActivateEmailMail(ctx.Context, ctx.User, email)
|
||||
|
||||
if err := ctx.Cache.Put("MailResendLimit_"+ctx.User.LowerName, ctx.User.LowerName, 180); err != nil {
|
||||
log.Error(4, "Set cache(MailResendLimit) fail: %v", err)
|
||||
}
|
||||
ctx.Flash.Info(ctx.Tr("settings.add_email_confirmation_sent", e.Email, setting.Service.ActiveCodeLives/60))
|
||||
ctx.Flash.Info(ctx.Tr("settings.add_email_confirmation_sent", email.Email, setting.Service.ActiveCodeLives/60))
|
||||
} else {
|
||||
ctx.Flash.Success(ctx.Tr("settings.add_email_success"))
|
||||
}
|
||||
|
||||
log.Trace("Email address added: %s", e.Email)
|
||||
log.Trace("Email address added: %s", email.Email)
|
||||
ctx.Redirect(setting.AppSubUrl + "/user/settings/email")
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue