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.

133 lines
3.1 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
Restricted users (#6274) * Restricted users (#4334): initial implementation * Add User.IsRestricted & UI to edit it * Pass user object instead of user id to places where IsRestricted flag matters * Restricted users: maintain access rows for all referenced repos (incl public) * Take logged in user & IsRestricted flag into account in org/repo listings, searches and accesses * Add basic repo access tests for restricted users Signed-off-by: Manush Dodunekov <manush@stendahls.se> * Mention restricted users in the faq Signed-off-by: Manush Dodunekov <manush@stendahls.se> * Revert unnecessary change `.isUserPartOfOrg` -> `.IsUserPartOfOrg` Signed-off-by: Manush Dodunekov <manush@stendahls.se> * Remove unnecessary `org.IsOrganization()` call Signed-off-by: Manush Dodunekov <manush@stendahls.se> * Revert to an `int64` keyed `accessMap` * Add type `userAccess` * Add convenience func updateUserAccess() * Turn accessMap into a `map[int64]userAccess` Signed-off-by: Manush Dodunekov <manush@stendahls.se> * or even better: `map[int64]*userAccess` * updateUserAccess(): use tighter syntax as suggested by lafriks * even tighter * Avoid extra loop * Don't disclose limited orgs to unauthenticated users * Don't assume block only applies to orgs * Use an array of `VisibleType` for filtering * fix yet another thinko * Ok - no need for u * Revert "Ok - no need for u" This reverts commit 5c3e886aabd5acd997a3b35687d322439732c200. Co-authored-by: Antoine GIRARD <sapk@users.noreply.github.com> Co-authored-by: Lauris BH <lauris@nix.lv>
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 2019 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 org
  5. import (
  6. "strings"
  7. "code.gitea.io/gitea/models"
  8. "code.gitea.io/gitea/modules/base"
  9. "code.gitea.io/gitea/modules/context"
  10. "code.gitea.io/gitea/modules/setting"
  11. )
  12. const (
  13. tplOrgHome base.TplName = "org/home"
  14. )
  15. // Home show organization home page
  16. func Home(ctx *context.Context) {
  17. ctx.SetParams(":org", ctx.Params(":username"))
  18. context.HandleOrgAssignment(ctx)
  19. if ctx.Written() {
  20. return
  21. }
  22. org := ctx.Org.Organization
  23. if !models.HasOrgVisible(org, ctx.User) {
  24. ctx.NotFound("HasOrgVisible", nil)
  25. return
  26. }
  27. ctx.Data["Title"] = org.DisplayName()
  28. var orderBy models.SearchOrderBy
  29. ctx.Data["SortType"] = ctx.Query("sort")
  30. switch ctx.Query("sort") {
  31. case "newest":
  32. orderBy = models.SearchOrderByNewest
  33. case "oldest":
  34. orderBy = models.SearchOrderByOldest
  35. case "recentupdate":
  36. orderBy = models.SearchOrderByRecentUpdated
  37. case "leastupdate":
  38. orderBy = models.SearchOrderByLeastUpdated
  39. case "reversealphabetically":
  40. orderBy = models.SearchOrderByAlphabeticallyReverse
  41. case "alphabetically":
  42. orderBy = models.SearchOrderByAlphabetically
  43. case "moststars":
  44. orderBy = models.SearchOrderByStarsReverse
  45. case "feweststars":
  46. orderBy = models.SearchOrderByStars
  47. case "mostforks":
  48. orderBy = models.SearchOrderByForksReverse
  49. case "fewestforks":
  50. orderBy = models.SearchOrderByForks
  51. default:
  52. ctx.Data["SortType"] = "recentupdate"
  53. orderBy = models.SearchOrderByRecentUpdated
  54. }
  55. keyword := strings.Trim(ctx.Query("q"), " ")
  56. ctx.Data["Keyword"] = keyword
  57. page := ctx.QueryInt("page")
  58. if page <= 0 {
  59. page = 1
  60. }
  61. var (
  62. repos []*models.Repository
  63. count int64
  64. err error
  65. )
  66. repos, count, err = models.SearchRepository(&models.SearchRepoOptions{
  67. ListOptions: models.ListOptions{
  68. PageSize: setting.UI.User.RepoPagingNum,
  69. Page: page,
  70. },
  71. Keyword: keyword,
  72. OwnerID: org.ID,
  73. OrderBy: orderBy,
  74. Private: ctx.IsSigned,
  75. Actor: ctx.User,
  76. IncludeDescription: setting.UI.SearchRepoDescription,
  77. })
  78. if err != nil {
  79. ctx.ServerError("SearchRepository", err)
  80. return
  81. }
  82. var opts = models.FindOrgMembersOpts{
  83. OrgID: org.ID,
  84. PublicOnly: true,
  85. ListOptions: models.ListOptions{Page: 1, PageSize: 25},
  86. }
  87. if ctx.User != nil {
  88. isMember, err := org.IsOrgMember(ctx.User.ID)
  89. if err != nil {
  90. ctx.Error(500, "IsOrgMember")
  91. return
  92. }
  93. opts.PublicOnly = !isMember && !ctx.User.IsAdmin
  94. }
  95. members, _, err := models.FindOrgMembers(&opts)
  96. if err != nil {
  97. ctx.ServerError("FindOrgMembers", err)
  98. return
  99. }
  100. membersCount, err := models.CountOrgMembers(opts)
  101. if err != nil {
  102. ctx.ServerError("CountOrgMembers", err)
  103. return
  104. }
  105. ctx.Data["Repos"] = repos
  106. ctx.Data["Total"] = count
  107. ctx.Data["MembersTotal"] = membersCount
  108. ctx.Data["Members"] = members
  109. ctx.Data["Teams"] = org.Teams
  110. pager := context.NewPagination(int(count), setting.UI.User.RepoPagingNum, page, 5)
  111. pager.SetDefaultParams(ctx)
  112. ctx.Data["Page"] = pager
  113. ctx.HTML(200, tplOrgHome)
  114. }