org_team.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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/gogs/go-gogs-client"
  7. "github.com/gogs/gogs/models"
  8. "github.com/gogs/gogs/pkg/context"
  9. "github.com/gogs/gogs/routes/api/v1/convert"
  10. "github.com/gogs/gogs/routes/api/v1/user"
  11. )
  12. func CreateTeam(c *context.APIContext, form api.CreateTeamOption) {
  13. team := &models.Team{
  14. OrgID: c.Org.Organization.ID,
  15. Name: form.Name,
  16. Description: form.Description,
  17. Authorize: models.ParseAccessMode(form.Permission),
  18. }
  19. if err := models.NewTeam(team); err != nil {
  20. if models.IsErrTeamAlreadyExist(err) {
  21. c.Error(422, "", err)
  22. } else {
  23. c.Error(500, "NewTeam", err)
  24. }
  25. return
  26. }
  27. c.JSON(201, convert.ToTeam(team))
  28. }
  29. func AddTeamMember(c *context.APIContext) {
  30. u := user.GetUserByParams(c)
  31. if c.Written() {
  32. return
  33. }
  34. if err := c.Org.Team.AddMember(u.ID); err != nil {
  35. c.Error(500, "AddMember", err)
  36. return
  37. }
  38. c.Status(204)
  39. }
  40. func RemoveTeamMember(c *context.APIContext) {
  41. u := user.GetUserByParams(c)
  42. if c.Written() {
  43. return
  44. }
  45. if err := c.Org.Team.RemoveMember(u.ID); err != nil {
  46. c.Error(500, "RemoveMember", err)
  47. return
  48. }
  49. c.Status(204)
  50. }