summaryrefslogtreecommitdiffstats
path: root/models/org.go
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 /models/org.go
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 'models/org.go')
-rw-r--r--models/org.go57
1 files changed, 45 insertions, 12 deletions
diff --git a/models/org.go b/models/org.go
index f14dad1dbb..dbc71761f2 100644
--- a/models/org.go
+++ b/models/org.go
@@ -68,10 +68,35 @@ func (org *User) GetTeams() error {
}
// GetMembers returns all members of organization.
-func (org *User) GetMembers() error {
- ous, err := GetOrgUsersByOrgID(org.ID)
+func (org *User) GetMembers() (err error) {
+ org.Members, org.MembersIsPublic, err = FindOrgMembers(FindOrgMembersOpts{
+ OrgID: org.ID,
+ })
+ return
+}
+
+// FindOrgMembersOpts represensts find org members condtions
+type FindOrgMembersOpts struct {
+ OrgID int64
+ PublicOnly bool
+ Start int
+ Limit int
+}
+
+// CountOrgMembers counts the organization's members
+func CountOrgMembers(opts FindOrgMembersOpts) (int64, error) {
+ sess := x.Where("org_id=?", opts.OrgID)
+ if opts.PublicOnly {
+ sess.And("is_public = ?", true)
+ }
+ return sess.Count(new(OrgUser))
+}
+
+// FindOrgMembers loads organization members according conditions
+func FindOrgMembers(opts FindOrgMembersOpts) (UserList, map[int64]bool, error) {
+ ous, err := GetOrgUsersByOrgID(opts.OrgID, opts.PublicOnly, opts.Start, opts.Limit)
if err != nil {
- return err
+ return nil, nil, err
}
var ids = make([]int64, len(ous))
@@ -80,9 +105,12 @@ func (org *User) GetMembers() error {
ids[i] = ou.UID
idsIsPublic[ou.UID] = ou.IsPublic
}
- org.MembersIsPublic = idsIsPublic
- org.Members, err = GetUsersByIDs(ids)
- return err
+
+ users, err := GetUsersByIDs(ids)
+ if err != nil {
+ return nil, nil, err
+ }
+ return users, idsIsPublic, nil
}
// AddMember adds new member to organization.
@@ -467,15 +495,20 @@ func GetOrgUsersByUserID(uid int64, all bool) ([]*OrgUser, error) {
}
// GetOrgUsersByOrgID returns all organization-user relations by organization ID.
-func GetOrgUsersByOrgID(orgID int64) ([]*OrgUser, error) {
- return getOrgUsersByOrgID(x, orgID)
+func GetOrgUsersByOrgID(orgID int64, publicOnly bool, start, limit int) ([]*OrgUser, error) {
+ return getOrgUsersByOrgID(x, orgID, publicOnly, start, limit)
}
-func getOrgUsersByOrgID(e Engine, orgID int64) ([]*OrgUser, error) {
+func getOrgUsersByOrgID(e Engine, orgID int64, publicOnly bool, start, limit int) ([]*OrgUser, error) {
ous := make([]*OrgUser, 0, 10)
- err := e.
- Where("org_id=?", orgID).
- Find(&ous)
+ sess := e.Where("org_id=?", orgID)
+ if publicOnly {
+ sess.And("is_public = ?", true)
+ }
+ if limit > 0 {
+ sess.Limit(limit, start)
+ }
+ err := sess.Find(&ous)
return ous, err
}