|
|
@ -68,10 +68,35 @@ func (org *User) GetTeams() error { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// GetMembers returns all members of organization.
|
|
|
|
// GetMembers returns all members of organization.
|
|
|
|
func (org *User) GetMembers() error { |
|
|
|
func (org *User) GetMembers() (err error) { |
|
|
|
ous, err := GetOrgUsersByOrgID(org.ID) |
|
|
|
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 { |
|
|
|
if err != nil { |
|
|
|
return err |
|
|
|
return nil, nil, err |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var ids = make([]int64, len(ous)) |
|
|
|
var ids = make([]int64, len(ous)) |
|
|
@ -80,9 +105,12 @@ func (org *User) GetMembers() error { |
|
|
|
ids[i] = ou.UID |
|
|
|
ids[i] = ou.UID |
|
|
|
idsIsPublic[ou.UID] = ou.IsPublic |
|
|
|
idsIsPublic[ou.UID] = ou.IsPublic |
|
|
|
} |
|
|
|
} |
|
|
|
org.MembersIsPublic = idsIsPublic |
|
|
|
|
|
|
|
org.Members, err = GetUsersByIDs(ids) |
|
|
|
users, err := GetUsersByIDs(ids) |
|
|
|
return err |
|
|
|
if err != nil { |
|
|
|
|
|
|
|
return nil, nil, err |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return users, idsIsPublic, nil |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// AddMember adds new member to organization.
|
|
|
|
// 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.
|
|
|
|
// GetOrgUsersByOrgID returns all organization-user relations by organization ID.
|
|
|
|
func GetOrgUsersByOrgID(orgID int64) ([]*OrgUser, error) { |
|
|
|
func GetOrgUsersByOrgID(orgID int64, publicOnly bool, start, limit int) ([]*OrgUser, error) { |
|
|
|
return getOrgUsersByOrgID(x, orgID) |
|
|
|
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) |
|
|
|
ous := make([]*OrgUser, 0, 10) |
|
|
|
err := e. |
|
|
|
sess := e.Where("org_id=?", orgID) |
|
|
|
Where("org_id=?", orgID). |
|
|
|
if publicOnly { |
|
|
|
Find(&ous) |
|
|
|
sess.And("is_public = ?", true) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if limit > 0 { |
|
|
|
|
|
|
|
sess.Limit(limit, start) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
err := sess.Find(&ous) |
|
|
|
return ous, err |
|
|
|
return ous, err |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|