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 3.0 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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 org
  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. func listUserOrgs(ctx *context.APIContext, u *models.User, all bool) {
  13. if err := u.GetOrganizations(all); err != nil {
  14. ctx.Error(500, "GetOrganizations", err)
  15. return
  16. }
  17. apiOrgs := make([]*api.Organization, len(u.Orgs))
  18. for i := range u.Orgs {
  19. apiOrgs[i] = convert.ToOrganization(u.Orgs[i])
  20. }
  21. ctx.JSON(200, &apiOrgs)
  22. }
  23. // ListMyOrgs list all my orgs
  24. func ListMyOrgs(ctx *context.APIContext) {
  25. // swagger:operation GET /user/orgs organization orgListCurrentUserOrgs
  26. // ---
  27. // summary: List the current user's organizations
  28. // produces:
  29. // - application/json
  30. // responses:
  31. // "200":
  32. // "$ref": "#/responses/OrganizationList"
  33. listUserOrgs(ctx, ctx.User, true)
  34. }
  35. // ListUserOrgs list user's orgs
  36. func ListUserOrgs(ctx *context.APIContext) {
  37. // swagger:operation GET /user/{username}/orgs organization orgListUserOrgs
  38. // ---
  39. // summary: List a user's organizations
  40. // produces:
  41. // - application/json
  42. // parameters:
  43. // - name: username
  44. // in: path
  45. // description: username of user
  46. // type: string
  47. // responses:
  48. // "200":
  49. // "$ref": "#/responses/OrganizationList"
  50. u := user.GetUserByParams(ctx)
  51. if ctx.Written() {
  52. return
  53. }
  54. listUserOrgs(ctx, u, false)
  55. }
  56. // Get get an organization
  57. func Get(ctx *context.APIContext) {
  58. // swagger:operation GET /orgs/{org} organization orgGet
  59. // ---
  60. // summary: Get an organization
  61. // produces:
  62. // - application/json
  63. // parameters:
  64. // - name: org
  65. // in: path
  66. // description: name of the organization to get
  67. // type: string
  68. // required: true
  69. // responses:
  70. // "200":
  71. // "$ref": "#/responses/Organization"
  72. ctx.JSON(200, convert.ToOrganization(ctx.Org.Organization))
  73. }
  74. // Edit change an organization's information
  75. func Edit(ctx *context.APIContext, form api.EditOrgOption) {
  76. // swagger:operation PATCH /orgs/{org} organization orgEdit
  77. // ---
  78. // summary: Edit an organization
  79. // consumes:
  80. // - application/json
  81. // produces:
  82. // - application/json
  83. // parameters:
  84. // - name: org
  85. // in: path
  86. // description: name of the organization to edit
  87. // type: string
  88. // required: true
  89. // - name: body
  90. // in: body
  91. // schema:
  92. // "$ref": "#/definitions/EditOrgOption"
  93. // responses:
  94. // "200":
  95. // "$ref": "#/responses/Organization"
  96. org := ctx.Org.Organization
  97. org.FullName = form.FullName
  98. org.Description = form.Description
  99. org.Website = form.Website
  100. org.Location = form.Location
  101. if err := models.UpdateUserCols(org, "full_name", "description", "website", "location"); err != nil {
  102. ctx.Error(500, "UpdateUser", err)
  103. return
  104. }
  105. ctx.JSON(200, convert.ToOrganization(org))
  106. }