move invite by mail to services package (#21513)
followup #20307 close #21511 -> make it easy to also add API equivalent later ...
This commit is contained in:
parent
fe442dba4b
commit
bd272e416a
@ -27,7 +27,6 @@ import (
|
|||||||
"code.gitea.io/gitea/modules/web"
|
"code.gitea.io/gitea/modules/web"
|
||||||
"code.gitea.io/gitea/routers/utils"
|
"code.gitea.io/gitea/routers/utils"
|
||||||
"code.gitea.io/gitea/services/forms"
|
"code.gitea.io/gitea/services/forms"
|
||||||
"code.gitea.io/gitea/services/mailer"
|
|
||||||
org_service "code.gitea.io/gitea/services/org"
|
org_service "code.gitea.io/gitea/services/org"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -132,8 +131,7 @@ func TeamsAction(ctx *context.Context) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
if user_model.IsErrUserNotExist(err) {
|
if user_model.IsErrUserNotExist(err) {
|
||||||
if setting.MailService != nil && user_model.ValidateEmail(uname) == nil {
|
if setting.MailService != nil && user_model.ValidateEmail(uname) == nil {
|
||||||
invite, err := org_model.CreateTeamInvite(ctx, ctx.Doer, ctx.Org.Team, uname)
|
if err := org_service.CreateTeamInvite(ctx, ctx.Doer, ctx.Org.Team, uname); err != nil {
|
||||||
if err != nil {
|
|
||||||
if org_model.IsErrTeamInviteAlreadyExist(err) {
|
if org_model.IsErrTeamInviteAlreadyExist(err) {
|
||||||
ctx.Flash.Error(ctx.Tr("form.duplicate_invite_to_team"))
|
ctx.Flash.Error(ctx.Tr("form.duplicate_invite_to_team"))
|
||||||
} else if org_model.IsErrUserEmailAlreadyAdded(err) {
|
} else if org_model.IsErrUserEmailAlreadyAdded(err) {
|
||||||
@ -142,9 +140,6 @@ func TeamsAction(ctx *context.Context) {
|
|||||||
ctx.ServerError("CreateTeamInvite", err)
|
ctx.ServerError("CreateTeamInvite", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
} else if err := mailer.MailTeamInvite(ctx, ctx.Doer, ctx.Org.Team, invite); err != nil {
|
|
||||||
ctx.ServerError("MailTeamInvite", err)
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
ctx.Flash.Error(ctx.Tr("form.user_not_exist"))
|
ctx.Flash.Error(ctx.Tr("form.user_not_exist"))
|
||||||
|
23
services/org/team_invite.go
Normal file
23
services/org/team_invite.go
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
// 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 org
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
org_model "code.gitea.io/gitea/models/organization"
|
||||||
|
user_model "code.gitea.io/gitea/models/user"
|
||||||
|
"code.gitea.io/gitea/services/mailer"
|
||||||
|
)
|
||||||
|
|
||||||
|
// CreateTeamInvite make a persistent invite in db and mail it
|
||||||
|
func CreateTeamInvite(ctx context.Context, inviter *user_model.User, team *org_model.Team, uname string) error {
|
||||||
|
invite, err := org_model.CreateTeamInvite(ctx, inviter, team, uname)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return mailer.MailTeamInvite(ctx, inviter, team, invite)
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user