diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2019-12-06 13:34:54 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-12-06 13:34:54 +0800 |
commit | e3081c667a44db469fac1e1de2d03b2d3106f100 (patch) | |
tree | b2d0bbefd1f1aef55adf1570c8782949a34ad819 /routers/org | |
parent | 77730db25768036a12e16cef9839b9492218303f (diff) | |
download | gitea-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/org')
-rw-r--r-- | routers/org/members.go | 40 |
1 files changed, 35 insertions, 5 deletions
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) } |