summaryrefslogtreecommitdiffstats
path: root/services
diff options
context:
space:
mode:
authorKN4CK3R <admin@oldschoolhack.me>2022-10-19 14:40:28 +0200
committerGitHub <noreply@github.com>2022-10-19 14:40:28 +0200
commitc3b2e44392e7f6c9a77a46664788c0bb9a6f33cb (patch)
tree6fe65807cd30770951ede4396a149ce03fb56b96 /services
parent7d1aed83f4d0cdf096ec8758ff8a85ddccf1328d (diff)
downloadgitea-c3b2e44392e7f6c9a77a46664788c0bb9a6f33cb.tar.gz
gitea-c3b2e44392e7f6c9a77a46664788c0bb9a6f33cb.zip
Add team member invite by email (#20307)
Allows to add (not registered) team members by email. related #5353 Invite by mail: ![grafik](https://user-images.githubusercontent.com/1666336/178154779-adcc547f-c0b7-4a2a-a131-4e41a3d9d3ad.png) Pending invitations: ![grafik](https://user-images.githubusercontent.com/1666336/178154882-9d739bb8-2b04-46c1-a025-c1f4be26af98.png) Email: ![grafik](https://user-images.githubusercontent.com/1666336/178164716-f2f90893-7ba6-4a5e-a3db-42538a660258.png) Join form: ![grafik](https://user-images.githubusercontent.com/1666336/178154840-aaab983a-d922-4414-b01a-9b1a19c5cef7.png) Co-authored-by: Jack Hay <jjphay@gmail.com>
Diffstat (limited to 'services')
-rw-r--r--services/mailer/mail_release.go2
-rw-r--r--services/mailer/mail_team_invite.go62
2 files changed, 63 insertions, 1 deletions
diff --git a/services/mailer/mail_release.go b/services/mailer/mail_release.go
index 7c44f93929..6df3fbbf1d 100644
--- a/services/mailer/mail_release.go
+++ b/services/mailer/mail_release.go
@@ -23,7 +23,7 @@ const (
tplNewReleaseMail base.TplName = "release"
)
-// MailNewRelease send new release notify to all all repo watchers.
+// MailNewRelease send new release notify to all repo watchers.
func MailNewRelease(ctx context.Context, rel *repo_model.Release) {
if setting.MailService == nil {
// No mail service configured
diff --git a/services/mailer/mail_team_invite.go b/services/mailer/mail_team_invite.go
new file mode 100644
index 0000000000..c2b2a00e76
--- /dev/null
+++ b/services/mailer/mail_team_invite.go
@@ -0,0 +1,62 @@
+// Copyright 2022 The Gitea Authors. All rights reserved.
+// Use of this source code is governed by a MIT-style
+// license that can be found in the LICENSE file.
+
+package mailer
+
+import (
+ "bytes"
+ "context"
+
+ org_model "code.gitea.io/gitea/models/organization"
+ 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/setting"
+ "code.gitea.io/gitea/modules/templates"
+ "code.gitea.io/gitea/modules/translation"
+)
+
+const (
+ tplTeamInviteMail base.TplName = "team_invite"
+)
+
+// MailTeamInvite sends team invites
+func MailTeamInvite(ctx context.Context, inviter *user_model.User, team *org_model.Team, invite *org_model.TeamInvite) error {
+ if setting.MailService == nil {
+ return nil
+ }
+
+ org, err := user_model.GetUserByIDCtx(ctx, team.OrgID)
+ if err != nil {
+ return err
+ }
+
+ locale := translation.NewLocale(inviter.Language)
+
+ subject := locale.Tr("mail.team_invite.subject", inviter.DisplayName(), org.DisplayName())
+ mailMeta := map[string]interface{}{
+ "Inviter": inviter,
+ "Organization": org,
+ "Team": team,
+ "Invite": invite,
+ "Subject": subject,
+ // helper
+ "locale": locale,
+ "Str2html": templates.Str2html,
+ "DotEscape": templates.DotEscape,
+ }
+
+ var mailBody bytes.Buffer
+ if err := bodyTemplates.ExecuteTemplate(&mailBody, string(tplTeamInviteMail), mailMeta); err != nil {
+ log.Error("ExecuteTemplate [%s]: %v", string(tplTeamInviteMail)+"/body", err)
+ return err
+ }
+
+ msg := NewMessage([]string{invite.Email}, subject, mailBody.String())
+ msg.Info = subject
+
+ SendAsync(msg)
+
+ return nil
+}