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

45 lines
1.2 KiB

8 years ago
  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. // see https://github.com/gogits/go-gogs-client/wiki/Administration-Organizations#create-a-new-organization
  14. func CreateOrg(ctx *context.APIContext, form api.CreateOrgOption) {
  15. u := user.GetUserByParams(ctx)
  16. if ctx.Written() {
  17. return
  18. }
  19. org := &models.User{
  20. Name: form.UserName,
  21. FullName: form.FullName,
  22. Description: form.Description,
  23. Website: form.Website,
  24. Location: form.Location,
  25. IsActive: true,
  26. Type: models.UserTypeOrganization,
  27. }
  28. if err := models.CreateOrganization(org, u); err != nil {
  29. if models.IsErrUserAlreadyExist(err) ||
  30. models.IsErrNameReserved(err) ||
  31. models.IsErrNamePatternNotAllowed(err) {
  32. ctx.Error(422, "", err)
  33. } else {
  34. ctx.Error(500, "CreateOrganization", err)
  35. }
  36. return
  37. }
  38. ctx.JSON(201, convert.ToOrganization(org))
  39. }