You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

org.go 1.4 kB

9 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. // Copyright 2015 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 "code.gitea.io/sdk/gitea"
  7. "code.gitea.io/gitea/models"
  8. "code.gitea.io/gitea/modules/context"
  9. "code.gitea.io/gitea/routers/api/v1/convert"
  10. "code.gitea.io/gitea/routers/api/v1/user"
  11. )
  12. // CreateOrg api for create organization
  13. func CreateOrg(ctx *context.APIContext, form api.CreateOrgOption) {
  14. // swagger:route POST /admin/users/{username}/orgs admin adminCreateOrg
  15. //
  16. // Consumes:
  17. // - application/json
  18. //
  19. // Produces:
  20. // - application/json
  21. //
  22. // Responses:
  23. // 201: Organization
  24. // 403: forbidden
  25. // 422: validationError
  26. // 500: error
  27. u := user.GetUserByParams(ctx)
  28. if ctx.Written() {
  29. return
  30. }
  31. org := &models.User{
  32. Name: form.UserName,
  33. FullName: form.FullName,
  34. Description: form.Description,
  35. Website: form.Website,
  36. Location: form.Location,
  37. IsActive: true,
  38. Type: models.UserTypeOrganization,
  39. }
  40. if err := models.CreateOrganization(org, u); err != nil {
  41. if models.IsErrUserAlreadyExist(err) ||
  42. models.IsErrNameReserved(err) ||
  43. models.IsErrNamePatternNotAllowed(err) {
  44. ctx.Error(422, "", err)
  45. } else {
  46. ctx.Error(500, "CreateOrganization", err)
  47. }
  48. return
  49. }
  50. ctx.JSON(201, convert.ToOrganization(org))
  51. }