aboutsummaryrefslogtreecommitdiffstats
path: root/services/mailer
diff options
context:
space:
mode:
Diffstat (limited to 'services/mailer')
-rw-r--r--services/mailer/mail.go20
-rw-r--r--services/mailer/mail_comment.go5
-rw-r--r--services/mailer/mail_issue.go17
-rw-r--r--services/mailer/mail_release.go5
-rw-r--r--services/mailer/mail_repo.go5
-rw-r--r--services/mailer/mail_test.go19
6 files changed, 38 insertions, 33 deletions
diff --git a/services/mailer/mail.go b/services/mailer/mail.go
index b579bf383a..a9978be8b1 100644
--- a/services/mailer/mail.go
+++ b/services/mailer/mail.go
@@ -66,7 +66,7 @@ func SendTestMail(email string) error {
}
// sendUserMail sends a mail to the user
-func sendUserMail(language string, u *models.User, tpl base.TplName, code, subject, info string) {
+func sendUserMail(language string, u *user_model.User, tpl base.TplName, code, subject, info string) {
locale := translation.NewLocale(language)
data := map[string]interface{}{
"DisplayName": u.DisplayName(),
@@ -94,7 +94,7 @@ func sendUserMail(language string, u *models.User, tpl base.TplName, code, subje
}
// SendActivateAccountMail sends an activation mail to the user (new user registration)
-func SendActivateAccountMail(locale translation.Locale, u *models.User) {
+func SendActivateAccountMail(locale translation.Locale, u *user_model.User) {
if setting.MailService == nil {
// No mail service configured
return
@@ -103,7 +103,7 @@ func SendActivateAccountMail(locale translation.Locale, u *models.User) {
}
// SendResetPasswordMail sends a password reset mail to the user
-func SendResetPasswordMail(u *models.User) {
+func SendResetPasswordMail(u *user_model.User) {
if setting.MailService == nil {
// No mail service configured
return
@@ -113,7 +113,7 @@ func SendResetPasswordMail(u *models.User) {
}
// SendActivateEmailMail sends confirmation email to confirm new email address
-func SendActivateEmailMail(u *models.User, email *user_model.EmailAddress) {
+func SendActivateEmailMail(u *user_model.User, email *user_model.EmailAddress) {
if setting.MailService == nil {
// No mail service configured
return
@@ -145,7 +145,7 @@ func SendActivateEmailMail(u *models.User, email *user_model.EmailAddress) {
}
// SendRegisterNotifyMail triggers a notify e-mail by admin created a account.
-func SendRegisterNotifyMail(u *models.User) {
+func SendRegisterNotifyMail(u *user_model.User) {
if setting.MailService == nil {
// No mail service configured
return
@@ -176,7 +176,7 @@ func SendRegisterNotifyMail(u *models.User) {
}
// SendCollaboratorMail sends mail notification to new collaborator.
-func SendCollaboratorMail(u, doer *models.User, repo *models.Repository) {
+func SendCollaboratorMail(u, doer *user_model.User, repo *models.Repository) {
if setting.MailService == nil {
// No mail service configured
return
@@ -209,7 +209,7 @@ func SendCollaboratorMail(u, doer *models.User, repo *models.Repository) {
SendAsync(msg)
}
-func composeIssueCommentMessages(ctx *mailCommentContext, lang string, recipients []*models.User, fromMention bool, info string) ([]*Message, error) {
+func composeIssueCommentMessages(ctx *mailCommentContext, lang string, recipients []*user_model.User, fromMention bool, info string) ([]*Message, error) {
var (
subject string
link string
@@ -337,7 +337,7 @@ func createReference(issue *models.Issue, comment *models.Comment) string {
return fmt.Sprintf("%s/%s/%d%s@%s", issue.Repo.FullName(), path, issue.Index, extra, setting.Domain)
}
-func generateAdditionalHeaders(ctx *mailCommentContext, reason string, recipient *models.User) map[string]string {
+func generateAdditionalHeaders(ctx *mailCommentContext, reason string, recipient *user_model.User) map[string]string {
repo := ctx.Issue.Repo
return map[string]string{
@@ -381,7 +381,7 @@ func sanitizeSubject(subject string) string {
}
// SendIssueAssignedMail composes and sends issue assigned email
-func SendIssueAssignedMail(issue *models.Issue, doer *models.User, content string, comment *models.Comment, recipients []*models.User) error {
+func SendIssueAssignedMail(issue *models.Issue, doer *user_model.User, content string, comment *models.Comment, recipients []*user_model.User) error {
if setting.MailService == nil {
// No mail service configured
return nil
@@ -392,7 +392,7 @@ func SendIssueAssignedMail(issue *models.Issue, doer *models.User, content strin
return err
}
- langMap := make(map[string][]*models.User)
+ langMap := make(map[string][]*user_model.User)
for _, user := range recipients {
langMap[user.Language] = append(langMap[user.Language], user)
}
diff --git a/services/mailer/mail_comment.go b/services/mailer/mail_comment.go
index eef71557e7..3662164092 100644
--- a/services/mailer/mail_comment.go
+++ b/services/mailer/mail_comment.go
@@ -6,12 +6,13 @@ package mailer
import (
"code.gitea.io/gitea/models"
+ user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/setting"
)
// MailParticipantsComment sends new comment emails to repository watchers and mentioned people.
-func MailParticipantsComment(c *models.Comment, opType models.ActionType, issue *models.Issue, mentions []*models.User) error {
+func MailParticipantsComment(c *models.Comment, opType models.ActionType, issue *models.Issue, mentions []*user_model.User) error {
if setting.MailService == nil {
// No mail service configured
return nil
@@ -35,7 +36,7 @@ func MailParticipantsComment(c *models.Comment, opType models.ActionType, issue
}
// MailMentionsComment sends email to users mentioned in a code comment
-func MailMentionsComment(pr *models.PullRequest, c *models.Comment, mentions []*models.User) (err error) {
+func MailMentionsComment(pr *models.PullRequest, c *models.Comment, mentions []*user_model.User) (err error) {
if setting.MailService == nil {
// No mail service configured
return nil
diff --git a/services/mailer/mail_issue.go b/services/mailer/mail_issue.go
index 6e63162713..1fbe68e022 100644
--- a/services/mailer/mail_issue.go
+++ b/services/mailer/mail_issue.go
@@ -9,6 +9,7 @@ import (
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/models/unit"
+ user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/setting"
)
@@ -19,7 +20,7 @@ func fallbackMailSubject(issue *models.Issue) string {
type mailCommentContext struct {
Issue *models.Issue
- Doer *models.User
+ Doer *user_model.User
ActionType models.ActionType
Content string
Comment *models.Comment
@@ -34,7 +35,7 @@ const (
// This function sends two list of emails:
// 1. Repository watchers (except for WIP pull requests) and users who are participated in comments.
// 2. Users who are not in 1. but get mentioned in current issue/comment.
-func mailIssueCommentToParticipants(ctx *mailCommentContext, mentions []*models.User) error {
+func mailIssueCommentToParticipants(ctx *mailCommentContext, mentions []*user_model.User) error {
// Required by the mail composer; make sure to load these before calling the async function
if err := ctx.Issue.LoadRepo(); err != nil {
@@ -103,7 +104,7 @@ func mailIssueCommentToParticipants(ctx *mailCommentContext, mentions []*models.
visited[i] = true
}
- unfilteredUsers, err := models.GetMaileableUsersByIDs(unfiltered, false)
+ unfilteredUsers, err := user_model.GetMaileableUsersByIDs(unfiltered, false)
if err != nil {
return err
}
@@ -114,18 +115,18 @@ func mailIssueCommentToParticipants(ctx *mailCommentContext, mentions []*models.
return nil
}
-func mailIssueCommentBatch(ctx *mailCommentContext, users []*models.User, visited map[int64]bool, fromMention bool) error {
+func mailIssueCommentBatch(ctx *mailCommentContext, users []*user_model.User, visited map[int64]bool, fromMention bool) error {
checkUnit := unit.TypeIssues
if ctx.Issue.IsPull {
checkUnit = unit.TypePullRequests
}
- langMap := make(map[string][]*models.User)
+ langMap := make(map[string][]*user_model.User)
for _, user := range users {
// At this point we exclude:
// user that don't have all mails enabled or users only get mail on mention and this is one ...
- if !(user.EmailNotificationsPreference == models.EmailNotificationsEnabled ||
- fromMention && user.EmailNotificationsPreference == models.EmailNotificationsOnMention) {
+ if !(user.EmailNotificationsPreference == user_model.EmailNotificationsEnabled ||
+ fromMention && user.EmailNotificationsPreference == user_model.EmailNotificationsOnMention) {
continue
}
@@ -164,7 +165,7 @@ func mailIssueCommentBatch(ctx *mailCommentContext, users []*models.User, visite
// MailParticipants sends new issue thread created emails to repository watchers
// and mentioned people.
-func MailParticipants(issue *models.Issue, doer *models.User, opType models.ActionType, mentions []*models.User) error {
+func MailParticipants(issue *models.Issue, doer *user_model.User, opType models.ActionType, mentions []*user_model.User) error {
if setting.MailService == nil {
// No mail service configured
return nil
diff --git a/services/mailer/mail_release.go b/services/mailer/mail_release.go
index a6fc28a5ca..72476fe8be 100644
--- a/services/mailer/mail_release.go
+++ b/services/mailer/mail_release.go
@@ -8,6 +8,7 @@ import (
"bytes"
"code.gitea.io/gitea/models"
+ user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/base"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/markup"
@@ -34,9 +35,9 @@ func MailNewRelease(rel *models.Release) {
return
}
- recipients, err := models.GetMaileableUsersByIDs(watcherIDList, false)
+ recipients, err := user_model.GetMaileableUsersByIDs(watcherIDList, false)
if err != nil {
- log.Error("models.GetMaileableUsersByIDs: %v", err)
+ log.Error("user_model.GetMaileableUsersByIDs: %v", err)
return
}
diff --git a/services/mailer/mail_repo.go b/services/mailer/mail_repo.go
index ef85f4aa54..8a2eeac087 100644
--- a/services/mailer/mail_repo.go
+++ b/services/mailer/mail_repo.go
@@ -9,13 +9,14 @@ import (
"fmt"
"code.gitea.io/gitea/models"
+ user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/templates"
"code.gitea.io/gitea/modules/translation"
)
// SendRepoTransferNotifyMail triggers a notification e-mail when a pending repository transfer was created
-func SendRepoTransferNotifyMail(doer, newOwner *models.User, repo *models.Repository) error {
+func SendRepoTransferNotifyMail(doer, newOwner *user_model.User, repo *models.Repository) error {
if setting.MailService == nil {
// No mail service configured
return nil
@@ -45,7 +46,7 @@ func SendRepoTransferNotifyMail(doer, newOwner *models.User, repo *models.Reposi
}
// sendRepoTransferNotifyMail triggers a notification e-mail when a pending repository transfer was created for each language
-func sendRepoTransferNotifyMailPerLang(lang string, newOwner, doer *models.User, emails []string, repo *models.Repository) error {
+func sendRepoTransferNotifyMailPerLang(lang string, newOwner, doer *user_model.User, emails []string, repo *models.Repository) error {
var (
locale = translation.NewLocale(lang)
content bytes.Buffer
diff --git a/services/mailer/mail_test.go b/services/mailer/mail_test.go
index 94ff5a65ae..8e8cd98231 100644
--- a/services/mailer/mail_test.go
+++ b/services/mailer/mail_test.go
@@ -12,6 +12,7 @@ import (
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/models/unittest"
+ user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/setting"
"github.com/stretchr/testify/assert"
@@ -40,7 +41,7 @@ const bodyTpl = `
</html>
`
-func prepareMailerTest(t *testing.T) (doer *models.User, repo *models.Repository, issue *models.Issue, comment *models.Comment) {
+func prepareMailerTest(t *testing.T) (doer *user_model.User, repo *models.Repository, issue *models.Issue, comment *models.Comment) {
assert.NoError(t, unittest.PrepareTestDatabase())
var mailService = setting.Mailer{
From: "test@gitea.com",
@@ -49,7 +50,7 @@ func prepareMailerTest(t *testing.T) (doer *models.User, repo *models.Repository
setting.MailService = &mailService
setting.Domain = "localhost"
- doer = unittest.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
+ doer = unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User)
repo = unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 1, Owner: doer}).(*models.Repository)
issue = unittest.AssertExistsAndLoadBean(t, &models.Issue{ID: 1, Repo: repo, Poster: doer}).(*models.Issue)
assert.NoError(t, issue.LoadRepo())
@@ -64,7 +65,7 @@ func TestComposeIssueCommentMessage(t *testing.T) {
btpl := template.Must(template.New("issue/comment").Parse(bodyTpl))
InitMailRender(stpl, btpl)
- recipients := []*models.User{{Name: "Test", Email: "test@gitea.com"}, {Name: "Test2", Email: "test2@gitea.com"}}
+ recipients := []*user_model.User{{Name: "Test", Email: "test@gitea.com"}, {Name: "Test2", Email: "test2@gitea.com"}}
msgs, err := composeIssueCommentMessages(&mailCommentContext{Issue: issue, Doer: doer, ActionType: models.ActionCommentIssue,
Content: "test body", Comment: comment}, "en-US", recipients, false, "issue comment")
assert.NoError(t, err)
@@ -91,7 +92,7 @@ func TestComposeIssueMessage(t *testing.T) {
btpl := template.Must(template.New("issue/new").Parse(bodyTpl))
InitMailRender(stpl, btpl)
- recipients := []*models.User{{Name: "Test", Email: "test@gitea.com"}, {Name: "Test2", Email: "test2@gitea.com"}}
+ recipients := []*user_model.User{{Name: "Test", Email: "test@gitea.com"}, {Name: "Test2", Email: "test2@gitea.com"}}
msgs, err := composeIssueCommentMessages(&mailCommentContext{Issue: issue, Doer: doer, ActionType: models.ActionCreateIssue,
Content: "test body"}, "en-US", recipients, false, "issue create")
assert.NoError(t, err)
@@ -113,7 +114,7 @@ func TestComposeIssueMessage(t *testing.T) {
func TestTemplateSelection(t *testing.T) {
doer, repo, issue, comment := prepareMailerTest(t)
- recipients := []*models.User{{Name: "Test", Email: "test@gitea.com"}}
+ recipients := []*user_model.User{{Name: "Test", Email: "test@gitea.com"}}
stpl := texttmpl.Must(texttmpl.New("issue/default").Parse("issue/default/subject"))
texttmpl.Must(stpl.New("issue/new").Parse("issue/new/subject"))
@@ -159,14 +160,14 @@ func TestTemplateServices(t *testing.T) {
doer, _, issue, comment := prepareMailerTest(t)
assert.NoError(t, issue.LoadRepo())
- expect := func(t *testing.T, issue *models.Issue, comment *models.Comment, doer *models.User,
+ expect := func(t *testing.T, issue *models.Issue, comment *models.Comment, doer *user_model.User,
actionType models.ActionType, fromMention bool, tplSubject, tplBody, expSubject, expBody string) {
stpl := texttmpl.Must(texttmpl.New("issue/default").Parse(tplSubject))
btpl := template.Must(template.New("issue/default").Parse(tplBody))
InitMailRender(stpl, btpl)
- recipients := []*models.User{{Name: "Test", Email: "test@gitea.com"}}
+ recipients := []*user_model.User{{Name: "Test", Email: "test@gitea.com"}}
msg := testComposeIssueCommentMessage(t, &mailCommentContext{Issue: issue, Doer: doer, ActionType: actionType,
Content: "test body", Comment: comment}, recipients, fromMention, "TestTemplateServices")
@@ -198,7 +199,7 @@ func TestTemplateServices(t *testing.T) {
"//Re: //")
}
-func testComposeIssueCommentMessage(t *testing.T, ctx *mailCommentContext, recipients []*models.User, fromMention bool, info string) *Message {
+func testComposeIssueCommentMessage(t *testing.T, ctx *mailCommentContext, recipients []*user_model.User, fromMention bool, info string) *Message {
msgs, err := composeIssueCommentMessages(ctx, "en-US", recipients, fromMention, info)
assert.NoError(t, err)
assert.Len(t, msgs, 1)
@@ -209,7 +210,7 @@ func TestGenerateAdditionalHeaders(t *testing.T) {
doer, _, issue, _ := prepareMailerTest(t)
ctx := &mailCommentContext{Issue: issue, Doer: doer}
- recipient := &models.User{Name: "Test", Email: "test@gitea.com"}
+ recipient := &user_model.User{Name: "Test", Email: "test@gitea.com"}
headers := generateAdditionalHeaders(ctx, "dummy-reason", recipient)