mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-05-25 11:22:16 +00:00
Add mail notify for new collaborator
This commit is contained in:
parent
07c3d497a7
commit
02687cbdf3
7 changed files with 93 additions and 18 deletions
|
@ -13,6 +13,7 @@ import (
|
|||
"github.com/gogits/gogs/models"
|
||||
"github.com/gogits/gogs/modules/base"
|
||||
"github.com/gogits/gogs/modules/log"
|
||||
"github.com/gogits/gogs/modules/mailer"
|
||||
"github.com/gogits/gogs/modules/middleware"
|
||||
)
|
||||
|
||||
|
@ -185,22 +186,30 @@ func CollaborationPost(ctx *middleware.Context) {
|
|||
return
|
||||
}
|
||||
|
||||
isExist, err := models.IsUserExist(name)
|
||||
u, err := models.GetUserByName(name)
|
||||
if err != nil {
|
||||
ctx.Handle(500, "repo.CollaborationPost(IsUserExist)", err)
|
||||
return
|
||||
} else if !isExist {
|
||||
ctx.Flash.Error("Given user does not exist.")
|
||||
ctx.Redirect(ctx.Req.RequestURI)
|
||||
if err == models.ErrUserNotExist {
|
||||
ctx.Flash.Error("Given user does not exist.")
|
||||
ctx.Redirect(ctx.Req.RequestURI)
|
||||
} else {
|
||||
ctx.Handle(500, "repo.CollaborationPost(GetUserByName)", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
if err := models.AddAccess(&models.Access{UserName: name, RepoName: repoLink,
|
||||
if err = models.AddAccess(&models.Access{UserName: name, RepoName: repoLink,
|
||||
Mode: models.AU_WRITABLE}); err != nil {
|
||||
ctx.Handle(500, "repo.CollaborationPost(AddAccess)", err)
|
||||
return
|
||||
}
|
||||
|
||||
if base.Service.NotifyMail {
|
||||
if err = mailer.SendCollaboratorMail(ctx.Render, u, ctx.User, ctx.Repo.Repository); err != nil {
|
||||
ctx.Handle(500, "repo.CollaborationPost(SendCollaboratorMail)", err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
ctx.Flash.Success("New collaborator has been added.")
|
||||
ctx.Redirect(ctx.Req.RequestURI)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue