org_team.go 1.3 KB

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