org_team.go 932 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. // Copyright 2016 The Gogs Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package admin
  5. import (
  6. api "github.com/gogits/go-gogs-client"
  7. "github.com/gogits/gogs/models"
  8. "github.com/gogits/gogs/modules/context"
  9. "github.com/gogits/gogs/routers/api/v1/convert"
  10. "github.com/gogits/gogs/routers/api/v1/user"
  11. )
  12. func CreateTeam(ctx *context.APIContext, form api.CreateTeamOption) {
  13. org := user.GetUserByParamsName(ctx, ":orgname")
  14. if ctx.Written() {
  15. return
  16. }
  17. team := &models.Team{
  18. OrgID: org.Id,
  19. Name: form.Name,
  20. Description: form.Description,
  21. Authorize: models.ParseAccessMode(form.Permission),
  22. }
  23. if err := models.NewTeam(team); err != nil {
  24. if models.IsErrTeamAlreadyExist(err) {
  25. ctx.Error(422, "", err)
  26. } else {
  27. ctx.Error(500, "NewTeam", err)
  28. }
  29. return
  30. }
  31. ctx.JSON(201, convert.ToTeam(team))
  32. }