diff --git a/services/mailer/mail_issue_common.go b/services/mailer/mail_issue_common.go
index a34d8a68c97..bfff706abb4 100644
--- a/services/mailer/mail_issue_common.go
+++ b/services/mailer/mail_issue_common.go
@@ -260,18 +260,18 @@ func actionToTemplate(issue *issues_model.Issue, actionType activities_model.Act
}
}
- template = typeName + "/" + name
+ template = "repo/" + typeName + "/" + name
ok := LoadedTemplates().BodyTemplates.Lookup(template) != nil
if !ok && typeName != "issue" {
- template = "issue/" + name
+ template = "repo/issue/" + name
ok = LoadedTemplates().BodyTemplates.Lookup(template) != nil
}
if !ok {
- template = typeName + "/default"
+ template = "repo/" + typeName + "/default"
ok = LoadedTemplates().BodyTemplates.Lookup(template) != nil
}
if !ok {
- template = "issue/default"
+ template = "repo/issue/default"
}
return typeName, name, template
}
diff --git a/services/mailer/mail_release.go b/services/mailer/mail_release.go
index fd97fb53124..248cf0ab909 100644
--- a/services/mailer/mail_release.go
+++ b/services/mailer/mail_release.go
@@ -19,7 +19,7 @@ import (
sender_service "code.gitea.io/gitea/services/mailer/sender"
)
-const tplNewReleaseMail templates.TplName = "release"
+const tplNewReleaseMail templates.TplName = "repo/release"
func generateMessageIDForRelease(release *repo_model.Release) string {
return fmt.Sprintf("<%s/releases/%d@%s>", release.Repo.FullName(), release.ID, setting.Domain)
diff --git a/services/mailer/mail_repo.go b/services/mailer/mail_repo.go
index 1ec7995ab94..f2b42ba3f53 100644
--- a/services/mailer/mail_repo.go
+++ b/services/mailer/mail_repo.go
@@ -11,13 +11,17 @@ import (
"code.gitea.io/gitea/models/organization"
repo_model "code.gitea.io/gitea/models/repo"
user_model "code.gitea.io/gitea/models/user"
+ "code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/templates"
"code.gitea.io/gitea/modules/translation"
sender_service "code.gitea.io/gitea/services/mailer/sender"
)
-const mailRepoTransferNotify templates.TplName = "notify/repo_transfer"
+const (
+ mailNotifyCollaborator templates.TplName = "repo/collaborator"
+ mailRepoTransferNotify templates.TplName = "repo/transfer"
+)
// SendRepoTransferNotifyMail triggers a notification e-mail when a pending repository transfer was created
func SendRepoTransferNotifyMail(ctx context.Context, doer, newOwner *user_model.User, repo *repo_model.Repository) error {
@@ -91,3 +95,34 @@ func sendRepoTransferNotifyMailPerLang(lang string, newOwner, doer *user_model.U
return nil
}
+
+// SendCollaboratorMail sends mail notification to new collaborator.
+func SendCollaboratorMail(u, doer *user_model.User, repo *repo_model.Repository) {
+ if setting.MailService == nil || !u.IsActive {
+ // No mail service configured OR the user is inactive
+ return
+ }
+ locale := translation.NewLocale(u.Language)
+ repoName := repo.FullName()
+
+ subject := locale.TrString("mail.repo.collaborator.added.subject", doer.DisplayName(), repoName)
+ data := map[string]any{
+ "locale": locale,
+ "Subject": subject,
+ "RepoName": repoName,
+ "Link": repo.HTMLURL(),
+ "Language": locale.Language(),
+ }
+
+ var content bytes.Buffer
+
+ if err := LoadedTemplates().BodyTemplates.ExecuteTemplate(&content, string(mailNotifyCollaborator), data); err != nil {
+ log.Error("Template: %v", err)
+ return
+ }
+
+ msg := sender_service.NewMessage(u.EmailTo(), subject, content.String())
+ msg.Info = fmt.Sprintf("UID: %d, add collaborator", u.ID)
+
+ SendAsync(msg)
+}
diff --git a/services/mailer/mail_team_invite.go b/services/mailer/mail_team_invite.go
index 034dc14e3d7..4819f299425 100644
--- a/services/mailer/mail_team_invite.go
+++ b/services/mailer/mail_team_invite.go
@@ -19,7 +19,7 @@ import (
sender_service "code.gitea.io/gitea/services/mailer/sender"
)
-const tplTeamInviteMail templates.TplName = "team_invite"
+const tplTeamInviteMail templates.TplName = "org/team_invite"
// MailTeamInvite sends team invites
func MailTeamInvite(ctx context.Context, inviter *user_model.User, team *org_model.Team, invite *org_model.TeamInvite) error {
diff --git a/services/mailer/mail_test.go b/services/mailer/mail_test.go
index 24f5d39d50d..b4e95fa144b 100644
--- a/services/mailer/mail_test.go
+++ b/services/mailer/mail_test.go
@@ -116,7 +116,7 @@ func TestComposeIssueComment(t *testing.T) {
setting.IncomingEmail.Enabled = true
defer func() { setting.IncomingEmail.Enabled = false }()
- prepareMailTemplates("issue/comment", subjectTpl, bodyTpl)
+ prepareMailTemplates("repo/issue/comment", subjectTpl, bodyTpl)
recipients := []*user_model.User{{Name: "Test", Email: "test@gitea.com"}, {Name: "Test2", Email: "test2@gitea.com"}}
msgs, err := composeIssueCommentMessages(t.Context(), &mailComment{
@@ -161,7 +161,7 @@ func TestComposeIssueComment(t *testing.T) {
func TestMailMentionsComment(t *testing.T) {
doer, _, issue, comment := prepareMailerTest(t)
comment.Poster = doer
- prepareMailTemplates("issue/comment", subjectTpl, bodyTpl)
+ prepareMailTemplates("repo/issue/comment", subjectTpl, bodyTpl)
mails := 0
defer test.MockVariableValue(&SendAsync, func(msgs ...*sender_service.Message) {
@@ -176,7 +176,7 @@ func TestMailMentionsComment(t *testing.T) {
func TestComposeIssueMessage(t *testing.T) {
doer, _, issue, _ := prepareMailerTest(t)
- prepareMailTemplates("issue/new", subjectTpl, bodyTpl)
+ prepareMailTemplates("repo/issue/new", subjectTpl, bodyTpl)
recipients := []*user_model.User{{Name: "Test", Email: "test@gitea.com"}, {Name: "Test2", Email: "test2@gitea.com"}}
msgs, err := composeIssueCommentMessages(t.Context(), &mailComment{
Issue: issue, Doer: doer, ActionType: activities_model.ActionCreateIssue,
@@ -205,14 +205,14 @@ func TestTemplateSelection(t *testing.T) {
doer, repo, issue, comment := prepareMailerTest(t)
recipients := []*user_model.User{{Name: "Test", Email: "test@gitea.com"}}
- prepareMailTemplates("issue/default", "issue/default/subject", "issue/default/body")
+ prepareMailTemplates("repo/issue/default", "repo/issue/default/subject", "repo/issue/default/body")
- texttmpl.Must(LoadedTemplates().SubjectTemplates.New("issue/new").Parse("issue/new/subject"))
- texttmpl.Must(LoadedTemplates().SubjectTemplates.New("pull/comment").Parse("pull/comment/subject"))
- texttmpl.Must(LoadedTemplates().SubjectTemplates.New("issue/close").Parse("")) // Must default to a fallback subject
- template.Must(LoadedTemplates().BodyTemplates.New("issue/new").Parse("issue/new/body"))
- template.Must(LoadedTemplates().BodyTemplates.New("pull/comment").Parse("pull/comment/body"))
- template.Must(LoadedTemplates().BodyTemplates.New("issue/close").Parse("issue/close/body"))
+ texttmpl.Must(LoadedTemplates().SubjectTemplates.New("repo/issue/new").Parse("repo/issue/new/subject"))
+ texttmpl.Must(LoadedTemplates().SubjectTemplates.New("repo/pull/comment").Parse("repo/pull/comment/subject"))
+ texttmpl.Must(LoadedTemplates().SubjectTemplates.New("repo/issue/close").Parse("")) // Must default to a fallback subject
+ template.Must(LoadedTemplates().BodyTemplates.New("repo/issue/new").Parse("repo/issue/new/body"))
+ template.Must(LoadedTemplates().BodyTemplates.New("repo/pull/comment").Parse("repo/pull/comment/body"))
+ template.Must(LoadedTemplates().BodyTemplates.New("repo/issue/close").Parse("repo/issue/close/body"))
expect := func(t *testing.T, msg *sender_service.Message, expSubject, expBody string) {
subject := msg.ToMessage().GetGenHeader("Subject")
@@ -227,13 +227,13 @@ func TestTemplateSelection(t *testing.T) {
Issue: issue, Doer: doer, ActionType: activities_model.ActionCreateIssue,
Content: "test body",
}, recipients, false, "TestTemplateSelection")
- expect(t, msg, "issue/new/subject", "issue/new/body")
+ expect(t, msg, "repo/issue/new/subject", "repo/issue/new/body")
msg = testComposeIssueCommentMessage(t, &mailComment{
Issue: issue, Doer: doer, ActionType: activities_model.ActionCommentIssue,
Content: "test body", Comment: comment,
}, recipients, false, "TestTemplateSelection")
- expect(t, msg, "issue/default/subject", "issue/default/body")
+ expect(t, msg, "repo/issue/default/subject", "repo/issue/default/body")
pull := unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: 2, Repo: repo, Poster: doer})
comment = unittest.AssertExistsAndLoadBean(t, &issues_model.Comment{ID: 4, Issue: pull})
@@ -241,13 +241,13 @@ func TestTemplateSelection(t *testing.T) {
Issue: pull, Doer: doer, ActionType: activities_model.ActionCommentPull,
Content: "test body", Comment: comment,
}, recipients, false, "TestTemplateSelection")
- expect(t, msg, "pull/comment/subject", "pull/comment/body")
+ expect(t, msg, "repo/pull/comment/subject", "repo/pull/comment/body")
msg = testComposeIssueCommentMessage(t, &mailComment{
Issue: issue, Doer: doer, ActionType: activities_model.ActionCloseIssue,
Content: "test body", Comment: comment,
}, recipients, false, "TestTemplateSelection")
- expect(t, msg, "Re: [user2/repo1] issue1 (#1)", "issue/close/body")
+ expect(t, msg, "Re: [user2/repo1] issue1 (#1)", "repo/issue/close/body")
}
func TestTemplateServices(t *testing.T) {
@@ -257,7 +257,7 @@ func TestTemplateServices(t *testing.T) {
expect := func(t *testing.T, issue *issues_model.Issue, comment *issues_model.Comment, doer *user_model.User,
actionType activities_model.ActionType, fromMention bool, tplSubject, tplBody, expSubject, expBody string,
) {
- prepareMailTemplates("issue/default", tplSubject, tplBody)
+ prepareMailTemplates("repo/issue/default", tplSubject, tplBody)
recipients := []*user_model.User{{Name: "Test", Email: "test@gitea.com"}}
msg := testComposeIssueCommentMessage(t, &mailComment{
Issue: issue, Doer: doer, ActionType: actionType,
@@ -524,7 +524,7 @@ func TestEmbedBase64Images(t *testing.T) {
att2ImgBase64 := fmt.Sprintf(`
`, att2Base64)
t.Run("ComposeMessage", func(t *testing.T) {
- prepareMailTemplates("issue/new", subjectTpl, bodyTpl)
+ prepareMailTemplates("repo/issue/new", subjectTpl, bodyTpl)
issue.Content = fmt.Sprintf(`MSG-BEFORE MSG-AFTER`, att1.UUID)
require.NoError(t, issues_model.UpdateIssueCols(t.Context(), issue, "content"))
diff --git a/services/mailer/mail_user.go b/services/mailer/mail_user.go
index 68df81f6a3a..867a8b2a8f4 100644
--- a/services/mailer/mail_user.go
+++ b/services/mailer/mail_user.go
@@ -7,7 +7,6 @@ import (
"bytes"
"fmt"
- repo_model "code.gitea.io/gitea/models/repo"
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/setting"
@@ -18,11 +17,10 @@ import (
)
const (
- mailAuthActivate templates.TplName = "auth/activate"
- mailAuthActivateEmail templates.TplName = "auth/activate_email"
- mailAuthResetPassword templates.TplName = "auth/reset_passwd"
- mailAuthRegisterNotify templates.TplName = "auth/register_notify"
- mailNotifyCollaborator templates.TplName = "notify/collaborator"
+ mailAuthActivate templates.TplName = "user/auth/activate"
+ mailAuthActivateEmail templates.TplName = "user/auth/activate_email"
+ mailAuthResetPassword templates.TplName = "user/auth/reset_passwd"
+ mailAuthRegisterNotify templates.TplName = "user/auth/register_notify"
)
// sendUserMail sends a mail to the user
@@ -128,34 +126,3 @@ func SendRegisterNotifyMail(u *user_model.User) {
SendAsync(msg)
}
-
-// SendCollaboratorMail sends mail notification to new collaborator.
-func SendCollaboratorMail(u, doer *user_model.User, repo *repo_model.Repository) {
- if setting.MailService == nil || !u.IsActive {
- // No mail service configured OR the user is inactive
- return
- }
- locale := translation.NewLocale(u.Language)
- repoName := repo.FullName()
-
- subject := locale.TrString("mail.repo.collaborator.added.subject", doer.DisplayName(), repoName)
- data := map[string]any{
- "locale": locale,
- "Subject": subject,
- "RepoName": repoName,
- "Link": repo.HTMLURL(),
- "Language": locale.Language(),
- }
-
- var content bytes.Buffer
-
- if err := LoadedTemplates().BodyTemplates.ExecuteTemplate(&content, string(mailNotifyCollaborator), data); err != nil {
- log.Error("Template: %v", err)
- return
- }
-
- msg := sender_service.NewMessage(u.EmailTo(), subject, content.String())
- msg.Info = fmt.Sprintf("UID: %d, add collaborator", u.ID)
-
- SendAsync(msg)
-}
diff --git a/services/mailer/mail_workflow_run.go b/services/mailer/mail_workflow_run.go
index 29b3abda8ee..da791894a53 100644
--- a/services/mailer/mail_workflow_run.go
+++ b/services/mailer/mail_workflow_run.go
@@ -15,12 +15,13 @@ import (
"code.gitea.io/gitea/modules/base"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/setting"
+ "code.gitea.io/gitea/modules/templates"
"code.gitea.io/gitea/modules/translation"
"code.gitea.io/gitea/services/convert"
sender_service "code.gitea.io/gitea/services/mailer/sender"
)
-const tplWorkflowRun = "notify/workflow_run"
+const tplWorkflowRun templates.TplName = "repo/actions/workflow_run"
type convertedWorkflowJob struct {
HTMLURL string
@@ -103,7 +104,7 @@ func composeAndSendActionsWorkflowRunStatusEmail(ctx context.Context, repo *repo
runStatusText = "All jobs have been cancelled"
}
var mailBody bytes.Buffer
- if err := LoadedTemplates().BodyTemplates.ExecuteTemplate(&mailBody, tplWorkflowRun, map[string]any{
+ if err := LoadedTemplates().BodyTemplates.ExecuteTemplate(&mailBody, string(tplWorkflowRun), map[string]any{
"Subject": subject,
"Repo": repo,
"Run": run,
diff --git a/templates/mail/team_invite.tmpl b/templates/mail/org/team_invite.tmpl
similarity index 100%
rename from templates/mail/team_invite.tmpl
rename to templates/mail/org/team_invite.tmpl
diff --git a/templates/mail/notify/workflow_run.devtest.yml b/templates/mail/repo/actions/workflow_run.devtest.yml
similarity index 100%
rename from templates/mail/notify/workflow_run.devtest.yml
rename to templates/mail/repo/actions/workflow_run.devtest.yml
diff --git a/templates/mail/notify/workflow_run.tmpl b/templates/mail/repo/actions/workflow_run.tmpl
similarity index 100%
rename from templates/mail/notify/workflow_run.tmpl
rename to templates/mail/repo/actions/workflow_run.tmpl
diff --git a/templates/mail/notify/collaborator.tmpl b/templates/mail/repo/collaborator.tmpl
similarity index 100%
rename from templates/mail/notify/collaborator.tmpl
rename to templates/mail/repo/collaborator.tmpl
diff --git a/templates/mail/issue/assigned.tmpl b/templates/mail/repo/issue/assigned.tmpl
similarity index 100%
rename from templates/mail/issue/assigned.tmpl
rename to templates/mail/repo/issue/assigned.tmpl
diff --git a/templates/mail/issue/default.tmpl b/templates/mail/repo/issue/default.tmpl
similarity index 100%
rename from templates/mail/issue/default.tmpl
rename to templates/mail/repo/issue/default.tmpl
diff --git a/templates/mail/release.tmpl b/templates/mail/repo/release.tmpl
similarity index 100%
rename from templates/mail/release.tmpl
rename to templates/mail/repo/release.tmpl
diff --git a/templates/mail/notify/repo_transfer.tmpl b/templates/mail/repo/transfer.tmpl
similarity index 100%
rename from templates/mail/notify/repo_transfer.tmpl
rename to templates/mail/repo/transfer.tmpl
diff --git a/templates/mail/auth/activate.devtest.yml b/templates/mail/user/auth/activate.devtest.yml
similarity index 100%
rename from templates/mail/auth/activate.devtest.yml
rename to templates/mail/user/auth/activate.devtest.yml
diff --git a/templates/mail/auth/activate.tmpl b/templates/mail/user/auth/activate.tmpl
similarity index 100%
rename from templates/mail/auth/activate.tmpl
rename to templates/mail/user/auth/activate.tmpl
diff --git a/templates/mail/user/auth/activate_email.devtest.yml b/templates/mail/user/auth/activate_email.devtest.yml
new file mode 100644
index 00000000000..f5519a6f6c0
--- /dev/null
+++ b/templates/mail/user/auth/activate_email.devtest.yml
@@ -0,0 +1,3 @@
+DisplayName: User Display Name
+Code: The-Activation-Code
+ActiveCodeLives: 24h
diff --git a/templates/mail/auth/activate_email.tmpl b/templates/mail/user/auth/activate_email.tmpl
similarity index 100%
rename from templates/mail/auth/activate_email.tmpl
rename to templates/mail/user/auth/activate_email.tmpl
diff --git a/templates/mail/user/auth/register_notify.devtest.yml b/templates/mail/user/auth/register_notify.devtest.yml
new file mode 100644
index 00000000000..8c9d6837d45
--- /dev/null
+++ b/templates/mail/user/auth/register_notify.devtest.yml
@@ -0,0 +1,2 @@
+DisplayName: User Display Name
+Username: Username
diff --git a/templates/mail/auth/register_notify.tmpl b/templates/mail/user/auth/register_notify.tmpl
similarity index 100%
rename from templates/mail/auth/register_notify.tmpl
rename to templates/mail/user/auth/register_notify.tmpl
diff --git a/templates/mail/user/auth/reset_passwd.devtest.yml b/templates/mail/user/auth/reset_passwd.devtest.yml
new file mode 100644
index 00000000000..4c73d6b952d
--- /dev/null
+++ b/templates/mail/user/auth/reset_passwd.devtest.yml
@@ -0,0 +1,3 @@
+DisplayName: User Display Name
+Code: The-Activation-Code
+ResetPwdCodeLives: 24h
diff --git a/templates/mail/auth/reset_passwd.tmpl b/templates/mail/user/auth/reset_passwd.tmpl
similarity index 100%
rename from templates/mail/auth/reset_passwd.tmpl
rename to templates/mail/user/auth/reset_passwd.tmpl