Browse Source

add collaborator

pull/2039/head
Kim Lindhardt Madsen 9 years ago
parent
commit
418ee3a8b3
  1. 2
      cmd/web.go
  2. 33
      routers/api/v1/repo.go

2
cmd/web.go

@ -244,6 +244,8 @@ func runWeb(ctx *cli.Context) {
m.Post("/forks", bind(api.ForkRepoOption{}), v1.ForkRepo)
m.Combo("/collaboration").Post(bind(api.CollaboratorOption{}), v1.AddCollaborator)
m.Get("/commits/:commitid", middleware.RepoRef(), v1.CommitByID)
m.Get("/commits/head", middleware.RepoRef(), v1.HEADCommit)
m.Get("/commits/branch/*", middleware.RepoRef(), v1.ListCommits)

33
routers/api/v1/repo.go

@ -16,6 +16,7 @@ import (
"github.com/gogits/gogs/modules/log"
"github.com/gogits/gogs/modules/middleware"
"github.com/gogits/gogs/modules/setting"
"github.com/gogits/gogs/modules/mailer"
)
// ToApiRepository converts repository to API format.
@ -235,6 +236,38 @@ func forkRepoTo(ctx *middleware.Context, targetUser *models.User, name string, d
ctx.JSON(201, ToApiRepository(ctx.User, forkedRepo, api.Permission{true, true, true}))
}
func AddCollaborator(ctx *middleware.Context, opt api.CollaboratorOption) {
u, err := models.GetUserByName(opt.UserName)
if err != nil {
if models.IsErrUserNotExist(err) {
ctx.APIError(422, "", err)
} else {
ctx.Handle(500, "GetUserByName", err)
}
return
}
// Check if user is organization member.
if ctx.Repo.Owner.IsOrganization() && ctx.Repo.Owner.IsOrgMember(u.Id) {
ctx.APIError(422, "", "User is organization member")
return
}
if err = ctx.Repo.Repository.AddCollaborator(u); err != nil {
ctx.Handle(500, "AddCollaborator", err)
return
}
if setting.Service.EnableNotifyMail {
if err = mailer.SendCollaboratorMail(ctx.Render, u, ctx.User, ctx.Repo.Repository); err != nil {
ctx.Handle(500, "SendCollaboratorMail", err)
return
}
}
ctx.Status(201)
}
func MigrateRepo(ctx *middleware.Context, form auth.MigrateRepoForm) {
ctxUser := ctx.User

Loading…
Cancel
Save