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.

148 lines
4.0 KiB

API add/generalize pagination (#9452) * paginate results * fixed deadlock * prevented breaking change * updated swagger * go fmt * fixed find topic * go mod tidy * go mod vendor with go1.13.5 * fixed repo find topics * fixed unit test * added Limit method to Engine struct; use engine variable when provided; fixed gitignore * use ItemsPerPage for default pagesize; fix GetWatchers, getOrgUsersByOrgID and GetStargazers; fix GetAllCommits headers; reverted some changed behaviors * set Page value on Home route * improved memory allocations * fixed response headers * removed logfiles * fixed import order * import order * improved swagger * added function to get models.ListOptions from context * removed pagesize diff on unit test * fixed imports * removed unnecessary struct field * fixed go fmt * scoped PR * code improvements * code improvements * go mod tidy * fixed import order * fixed commit statuses session * fixed files headers * fixed headers; added pagination for notifications * go mod tidy * go fmt * removed Private from user search options; added setting.UI.IssuePagingNum as default valeu on repo's issues list * Apply suggestions from code review Co-Authored-By: 6543 <6543@obermui.de> Co-Authored-By: zeripath <art27@cantab.net> * fixed build error * CI.restart() * fixed merge conflicts resolve * fixed conflicts resolve * improved FindTrackedTimesOptions.ToOptions() method * added backwards compatibility on ListReleases request; fixed issue tracked time ToSession * fixed build error; fixed swagger template * fixed swagger template * fixed ListReleases backwards compatibility * added page to user search route Co-authored-by: techknowlogick <matti@mdranta.net> Co-authored-by: 6543 <6543@obermui.de> Co-authored-by: zeripath <art27@cantab.net>
4 years ago
API add/generalize pagination (#9452) * paginate results * fixed deadlock * prevented breaking change * updated swagger * go fmt * fixed find topic * go mod tidy * go mod vendor with go1.13.5 * fixed repo find topics * fixed unit test * added Limit method to Engine struct; use engine variable when provided; fixed gitignore * use ItemsPerPage for default pagesize; fix GetWatchers, getOrgUsersByOrgID and GetStargazers; fix GetAllCommits headers; reverted some changed behaviors * set Page value on Home route * improved memory allocations * fixed response headers * removed logfiles * fixed import order * import order * improved swagger * added function to get models.ListOptions from context * removed pagesize diff on unit test * fixed imports * removed unnecessary struct field * fixed go fmt * scoped PR * code improvements * code improvements * go mod tidy * fixed import order * fixed commit statuses session * fixed files headers * fixed headers; added pagination for notifications * go mod tidy * go fmt * removed Private from user search options; added setting.UI.IssuePagingNum as default valeu on repo's issues list * Apply suggestions from code review Co-Authored-By: 6543 <6543@obermui.de> Co-Authored-By: zeripath <art27@cantab.net> * fixed build error * CI.restart() * fixed merge conflicts resolve * fixed conflicts resolve * improved FindTrackedTimesOptions.ToOptions() method * added backwards compatibility on ListReleases request; fixed issue tracked time ToSession * fixed build error; fixed swagger template * fixed swagger template * fixed ListReleases backwards compatibility * added page to user search route Co-authored-by: techknowlogick <matti@mdranta.net> Co-authored-by: 6543 <6543@obermui.de> Co-authored-by: zeripath <art27@cantab.net>
4 years ago
API add/generalize pagination (#9452) * paginate results * fixed deadlock * prevented breaking change * updated swagger * go fmt * fixed find topic * go mod tidy * go mod vendor with go1.13.5 * fixed repo find topics * fixed unit test * added Limit method to Engine struct; use engine variable when provided; fixed gitignore * use ItemsPerPage for default pagesize; fix GetWatchers, getOrgUsersByOrgID and GetStargazers; fix GetAllCommits headers; reverted some changed behaviors * set Page value on Home route * improved memory allocations * fixed response headers * removed logfiles * fixed import order * import order * improved swagger * added function to get models.ListOptions from context * removed pagesize diff on unit test * fixed imports * removed unnecessary struct field * fixed go fmt * scoped PR * code improvements * code improvements * go mod tidy * fixed import order * fixed commit statuses session * fixed files headers * fixed headers; added pagination for notifications * go mod tidy * go fmt * removed Private from user search options; added setting.UI.IssuePagingNum as default valeu on repo's issues list * Apply suggestions from code review Co-Authored-By: 6543 <6543@obermui.de> Co-Authored-By: zeripath <art27@cantab.net> * fixed build error * CI.restart() * fixed merge conflicts resolve * fixed conflicts resolve * improved FindTrackedTimesOptions.ToOptions() method * added backwards compatibility on ListReleases request; fixed issue tracked time ToSession * fixed build error; fixed swagger template * fixed swagger template * fixed ListReleases backwards compatibility * added page to user search route Co-authored-by: techknowlogick <matti@mdranta.net> Co-authored-by: 6543 <6543@obermui.de> Co-authored-by: zeripath <art27@cantab.net>
4 years ago
API add/generalize pagination (#9452) * paginate results * fixed deadlock * prevented breaking change * updated swagger * go fmt * fixed find topic * go mod tidy * go mod vendor with go1.13.5 * fixed repo find topics * fixed unit test * added Limit method to Engine struct; use engine variable when provided; fixed gitignore * use ItemsPerPage for default pagesize; fix GetWatchers, getOrgUsersByOrgID and GetStargazers; fix GetAllCommits headers; reverted some changed behaviors * set Page value on Home route * improved memory allocations * fixed response headers * removed logfiles * fixed import order * import order * improved swagger * added function to get models.ListOptions from context * removed pagesize diff on unit test * fixed imports * removed unnecessary struct field * fixed go fmt * scoped PR * code improvements * code improvements * go mod tidy * fixed import order * fixed commit statuses session * fixed files headers * fixed headers; added pagination for notifications * go mod tidy * go fmt * removed Private from user search options; added setting.UI.IssuePagingNum as default valeu on repo's issues list * Apply suggestions from code review Co-Authored-By: 6543 <6543@obermui.de> Co-Authored-By: zeripath <art27@cantab.net> * fixed build error * CI.restart() * fixed merge conflicts resolve * fixed conflicts resolve * improved FindTrackedTimesOptions.ToOptions() method * added backwards compatibility on ListReleases request; fixed issue tracked time ToSession * fixed build error; fixed swagger template * fixed swagger template * fixed ListReleases backwards compatibility * added page to user search route Co-authored-by: techknowlogick <matti@mdranta.net> Co-authored-by: 6543 <6543@obermui.de> Co-authored-by: zeripath <art27@cantab.net>
4 years ago
API add/generalize pagination (#9452) * paginate results * fixed deadlock * prevented breaking change * updated swagger * go fmt * fixed find topic * go mod tidy * go mod vendor with go1.13.5 * fixed repo find topics * fixed unit test * added Limit method to Engine struct; use engine variable when provided; fixed gitignore * use ItemsPerPage for default pagesize; fix GetWatchers, getOrgUsersByOrgID and GetStargazers; fix GetAllCommits headers; reverted some changed behaviors * set Page value on Home route * improved memory allocations * fixed response headers * removed logfiles * fixed import order * import order * improved swagger * added function to get models.ListOptions from context * removed pagesize diff on unit test * fixed imports * removed unnecessary struct field * fixed go fmt * scoped PR * code improvements * code improvements * go mod tidy * fixed import order * fixed commit statuses session * fixed files headers * fixed headers; added pagination for notifications * go mod tidy * go fmt * removed Private from user search options; added setting.UI.IssuePagingNum as default valeu on repo's issues list * Apply suggestions from code review Co-Authored-By: 6543 <6543@obermui.de> Co-Authored-By: zeripath <art27@cantab.net> * fixed build error * CI.restart() * fixed merge conflicts resolve * fixed conflicts resolve * improved FindTrackedTimesOptions.ToOptions() method * added backwards compatibility on ListReleases request; fixed issue tracked time ToSession * fixed build error; fixed swagger template * fixed swagger template * fixed ListReleases backwards compatibility * added page to user search route Co-authored-by: techknowlogick <matti@mdranta.net> Co-authored-by: 6543 <6543@obermui.de> Co-authored-by: zeripath <art27@cantab.net>
4 years ago
API add/generalize pagination (#9452) * paginate results * fixed deadlock * prevented breaking change * updated swagger * go fmt * fixed find topic * go mod tidy * go mod vendor with go1.13.5 * fixed repo find topics * fixed unit test * added Limit method to Engine struct; use engine variable when provided; fixed gitignore * use ItemsPerPage for default pagesize; fix GetWatchers, getOrgUsersByOrgID and GetStargazers; fix GetAllCommits headers; reverted some changed behaviors * set Page value on Home route * improved memory allocations * fixed response headers * removed logfiles * fixed import order * import order * improved swagger * added function to get models.ListOptions from context * removed pagesize diff on unit test * fixed imports * removed unnecessary struct field * fixed go fmt * scoped PR * code improvements * code improvements * go mod tidy * fixed import order * fixed commit statuses session * fixed files headers * fixed headers; added pagination for notifications * go mod tidy * go fmt * removed Private from user search options; added setting.UI.IssuePagingNum as default valeu on repo's issues list * Apply suggestions from code review Co-Authored-By: 6543 <6543@obermui.de> Co-Authored-By: zeripath <art27@cantab.net> * fixed build error * CI.restart() * fixed merge conflicts resolve * fixed conflicts resolve * improved FindTrackedTimesOptions.ToOptions() method * added backwards compatibility on ListReleases request; fixed issue tracked time ToSession * fixed build error; fixed swagger template * fixed swagger template * fixed ListReleases backwards compatibility * added page to user search route Co-authored-by: techknowlogick <matti@mdranta.net> Co-authored-by: 6543 <6543@obermui.de> Co-authored-by: zeripath <art27@cantab.net>
4 years ago
  1. // Copyright 2017 The Gitea 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 user
  5. import (
  6. "net/http"
  7. "code.gitea.io/gitea/models"
  8. "code.gitea.io/gitea/modules/context"
  9. api "code.gitea.io/gitea/modules/structs"
  10. "code.gitea.io/gitea/routers/api/v1/utils"
  11. )
  12. // listUserRepos - List the repositories owned by the given user.
  13. func listUserRepos(ctx *context.APIContext, u *models.User, private bool) {
  14. repos, err := models.GetUserRepositories(&models.SearchRepoOptions{
  15. Actor: u,
  16. Private: private,
  17. ListOptions: utils.GetListOptions(ctx),
  18. })
  19. if err != nil {
  20. ctx.Error(http.StatusInternalServerError, "GetUserRepositories", err)
  21. return
  22. }
  23. apiRepos := make([]*api.Repository, 0, len(repos))
  24. for i := range repos {
  25. access, err := models.AccessLevel(ctx.User, repos[i])
  26. if err != nil {
  27. ctx.Error(http.StatusInternalServerError, "AccessLevel", err)
  28. return
  29. }
  30. if ctx.IsSigned && ctx.User.IsAdmin || access >= models.AccessModeRead {
  31. apiRepos = append(apiRepos, repos[i].APIFormat(access))
  32. }
  33. }
  34. ctx.JSON(http.StatusOK, &apiRepos)
  35. }
  36. // ListUserRepos - list the repos owned by the given user.
  37. func ListUserRepos(ctx *context.APIContext) {
  38. // swagger:operation GET /users/{username}/repos user userListRepos
  39. // ---
  40. // summary: List the repos owned by the given user
  41. // produces:
  42. // - application/json
  43. // parameters:
  44. // - name: username
  45. // in: path
  46. // description: username of user
  47. // type: string
  48. // required: true
  49. // - name: page
  50. // in: query
  51. // description: page number of results to return (1-based)
  52. // type: integer
  53. // - name: limit
  54. // in: query
  55. // description: page size of results, maximum page size is 50
  56. // type: integer
  57. // responses:
  58. // "200":
  59. // "$ref": "#/responses/RepositoryList"
  60. user := GetUserByParams(ctx)
  61. if ctx.Written() {
  62. return
  63. }
  64. private := ctx.IsSigned
  65. listUserRepos(ctx, user, private)
  66. }
  67. // ListMyRepos - list the repositories you own or have access to.
  68. func ListMyRepos(ctx *context.APIContext) {
  69. // swagger:operation GET /user/repos user userCurrentListRepos
  70. // ---
  71. // summary: List the repos that the authenticated user owns or has access to
  72. // produces:
  73. // - application/json
  74. // parameters:
  75. // - name: page
  76. // in: query
  77. // description: page number of results to return (1-based)
  78. // type: integer
  79. // - name: limit
  80. // in: query
  81. // description: page size of results, maximum page size is 50
  82. // type: integer
  83. // responses:
  84. // "200":
  85. // "$ref": "#/responses/RepositoryList"
  86. ownRepos, err := models.GetUserRepositories(&models.SearchRepoOptions{
  87. Actor: ctx.User,
  88. Private: true,
  89. ListOptions: utils.GetListOptions(ctx),
  90. })
  91. if err != nil {
  92. ctx.Error(http.StatusInternalServerError, "GetUserRepositories", err)
  93. return
  94. }
  95. accessibleReposMap, err := ctx.User.GetRepositoryAccesses()
  96. if err != nil {
  97. ctx.Error(http.StatusInternalServerError, "GetRepositoryAccesses", err)
  98. return
  99. }
  100. apiRepos := make([]*api.Repository, len(ownRepos)+len(accessibleReposMap))
  101. for i := range ownRepos {
  102. apiRepos[i] = ownRepos[i].APIFormat(models.AccessModeOwner)
  103. }
  104. i := len(ownRepos)
  105. for repo, access := range accessibleReposMap {
  106. apiRepos[i] = repo.APIFormat(access)
  107. i++
  108. }
  109. ctx.JSON(http.StatusOK, &apiRepos)
  110. }
  111. // ListOrgRepos - list the repositories of an organization.
  112. func ListOrgRepos(ctx *context.APIContext) {
  113. // swagger:operation GET /orgs/{org}/repos organization orgListRepos
  114. // ---
  115. // summary: List an organization's repos
  116. // produces:
  117. // - application/json
  118. // parameters:
  119. // - name: org
  120. // in: path
  121. // description: name of the organization
  122. // type: string
  123. // required: true
  124. // - name: page
  125. // in: query
  126. // description: page number of results to return (1-based)
  127. // type: integer
  128. // - name: limit
  129. // in: query
  130. // description: page size of results, maximum page size is 50
  131. // type: integer
  132. // responses:
  133. // "200":
  134. // "$ref": "#/responses/RepositoryList"
  135. listUserRepos(ctx, ctx.Org.Organization, ctx.IsSigned)
  136. }