mirror of
https://github.com/go-gitea/gitea
synced 2025-07-22 18:28:37 +00:00
Add team member invite by email (#20307)
Allows to add (not registered) team members by email. related #5353 Invite by mail:  Pending invitations:  Email:  Join form:  Co-authored-by: Jack Hay <jjphay@gmail.com>
This commit is contained in:
@@ -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
|
||||
|
62
services/mailer/mail_team_invite.go
Normal file
62
services/mailer/mail_team_invite.go
Normal file
@@ -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
|
||||
}
|
Reference in New Issue
Block a user