summaryrefslogtreecommitdiffstats
path: root/routers
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2019-12-06 13:34:54 +0800
committerGitHub <noreply@github.com>2019-12-06 13:34:54 +0800
commite3081c667a44db469fac1e1de2d03b2d3106f100 (patch)
treeb2d0bbefd1f1aef55adf1570c8782949a34ad819 /routers
parent77730db25768036a12e16cef9839b9492218303f (diff)
downloadgitea-e3081c667a44db469fac1e1de2d03b2d3106f100.tar.gz
gitea-e3081c667a44db469fac1e1de2d03b2d3106f100.zip
Only show part of members on orgnization dashboard and add paging for orgnization members page (#9092)
* Only show part of members on orgnization dashboard and add paging for orgnization members page * fix test * fix typo
Diffstat (limited to 'routers')
-rw-r--r--routers/api/v1/org/member.go31
-rw-r--r--routers/org/members.go40
-rw-r--r--routers/user/home.go29
3 files changed, 68 insertions, 32 deletions
diff --git a/routers/api/v1/org/member.go b/routers/api/v1/org/member.go
index be47b6963f..45519e5606 100644
--- a/routers/api/v1/org/member.go
+++ b/routers/api/v1/org/member.go
@@ -18,30 +18,13 @@ import (
// listMembers list an organization's members
func listMembers(ctx *context.APIContext, publicOnly bool) {
var members []*models.User
- if publicOnly {
- orgUsers, err := models.GetOrgUsersByOrgID(ctx.Org.Organization.ID)
- if err != nil {
- ctx.Error(500, "GetOrgUsersByOrgID", err)
- return
- }
-
- memberIDs := make([]int64, 0, len(orgUsers))
- for _, orgUser := range orgUsers {
- if orgUser.IsPublic {
- memberIDs = append(memberIDs, orgUser.UID)
- }
- }
-
- if members, err = models.GetUsersByIDs(memberIDs); err != nil {
- ctx.Error(500, "GetUsersByIDs", err)
- return
- }
- } else {
- if err := ctx.Org.Organization.GetMembers(); err != nil {
- ctx.Error(500, "GetMembers", err)
- return
- }
- members = ctx.Org.Organization.Members
+ members, _, err := models.FindOrgMembers(models.FindOrgMembersOpts{
+ OrgID: ctx.Org.Organization.ID,
+ PublicOnly: publicOnly,
+ })
+ if err != nil {
+ ctx.Error(500, "GetUsersByIDs", err)
+ return
}
apiMembers := make([]*api.User, len(members))
diff --git a/routers/org/members.go b/routers/org/members.go
index f9cb275e83..b9805c2c03 100644
--- a/routers/org/members.go
+++ b/routers/org/members.go
@@ -25,14 +25,44 @@ func Members(ctx *context.Context) {
ctx.Data["Title"] = org.FullName
ctx.Data["PageIsOrgMembers"] = true
- if err := org.GetMembers(); err != nil {
+ page := ctx.QueryInt("page")
+ if page <= 1 {
+ page = 1
+ }
+
+ var opts = models.FindOrgMembersOpts{
+ OrgID: org.ID,
+ PublicOnly: true,
+ }
+
+ if ctx.User != nil {
+ isMember, err := ctx.Org.Organization.IsOrgMember(ctx.User.ID)
+ if err != nil {
+ ctx.Error(500, "IsOrgMember")
+ return
+ }
+ opts.PublicOnly = !isMember
+ }
+
+ total, err := models.CountOrgMembers(opts)
+ if err != nil {
+ ctx.Error(500, "CountOrgMembers")
+ return
+ }
+
+ pager := context.NewPagination(int(total), setting.UI.MembersPagingNum, page, 5)
+ opts.Start = (page - 1) * setting.UI.MembersPagingNum
+ opts.Limit = setting.UI.MembersPagingNum
+ members, membersIsPublic, err := models.FindOrgMembers(opts)
+ if err != nil {
ctx.ServerError("GetMembers", err)
return
}
- ctx.Data["Members"] = org.Members
- ctx.Data["MembersIsPublicMember"] = org.MembersIsPublic
- ctx.Data["MembersIsUserOrgOwner"] = org.Members.IsUserOrgOwner(org.ID)
- ctx.Data["MembersTwoFaStatus"] = org.Members.GetTwoFaStatus()
+ ctx.Data["Page"] = pager
+ ctx.Data["Members"] = members
+ ctx.Data["MembersIsPublicMember"] = membersIsPublic
+ ctx.Data["MembersIsUserOrgOwner"] = members.IsUserOrgOwner(org.ID)
+ ctx.Data["MembersTwoFaStatus"] = members.GetTwoFaStatus()
ctx.HTML(200, tplMembers)
}
diff --git a/routers/user/home.go b/routers/user/home.go
index 8465216bcf..2eff889105 100644
--- a/routers/user/home.go
+++ b/routers/user/home.go
@@ -537,14 +537,37 @@ func showOrgProfile(ctx *context.Context) {
return
}
- if err := org.GetMembers(); err != nil {
- ctx.ServerError("GetMembers", err)
+ var opts = models.FindOrgMembersOpts{
+ OrgID: org.ID,
+ PublicOnly: true,
+ Limit: 25,
+ }
+
+ if ctx.User != nil {
+ isMember, err := org.IsOrgMember(ctx.User.ID)
+ if err != nil {
+ ctx.Error(500, "IsOrgMember")
+ return
+ }
+ opts.PublicOnly = !isMember
+ }
+
+ members, _, err := models.FindOrgMembers(opts)
+ if err != nil {
+ ctx.ServerError("FindOrgMembers", err)
+ return
+ }
+
+ membersCount, err := models.CountOrgMembers(opts)
+ if err != nil {
+ ctx.ServerError("CountOrgMembers", err)
return
}
ctx.Data["Repos"] = repos
ctx.Data["Total"] = count
- ctx.Data["Members"] = org.Members
+ ctx.Data["MembersTotal"] = membersCount
+ ctx.Data["Members"] = members
ctx.Data["Teams"] = org.Teams
pager := context.NewPagination(int(count), setting.UI.User.RepoPagingNum, page, 5)