@@ -141,8 +141,9 @@ func (org *Organization) LoadTeams(ctx context.Context) ([]*Team, error) {
141141}
142142
143143// GetMembers returns all members of organization.
144- func (org * Organization ) GetMembers (ctx context.Context ) (user_model.UserList , map [int64 ]bool , error ) {
144+ func (org * Organization ) GetMembers (ctx context.Context , doer * user_model. User ) (user_model.UserList , map [int64 ]bool , error ) {
145145 return FindOrgMembers (ctx , & FindOrgMembersOpts {
146+ Doer : doer ,
146147 OrgID : org .ID ,
147148 })
148149}
@@ -195,16 +196,22 @@ func (org *Organization) CanCreateRepo() bool {
195196// FindOrgMembersOpts represensts find org members conditions
196197type FindOrgMembersOpts struct {
197198 db.ListOptions
198- OrgID int64
199- PublicOnly bool
199+ Doer * user_model.User
200+ IsMember bool
201+ OrgID int64
202+ }
203+
204+ func (opts FindOrgMembersOpts ) PublicOnly () bool {
205+ return opts .Doer == nil || ! opts .IsMember && ! opts .Doer .IsAdmin
200206}
201207
202208// CountOrgMembers counts the organization's members
203209func CountOrgMembers (ctx context.Context , opts * FindOrgMembersOpts ) (int64 , error ) {
204210 sess := db .GetEngine (ctx ).Where ("org_id=?" , opts .OrgID )
205- if opts .PublicOnly {
211+ if opts .PublicOnly () {
206212 sess .And ("is_public = ?" , true )
207213 }
214+
208215 return sess .Count (new (OrgUser ))
209216}
210217
@@ -525,9 +532,10 @@ func GetOrgsCanCreateRepoByUserID(ctx context.Context, userID int64) ([]*Organiz
525532// GetOrgUsersByOrgID returns all organization-user relations by organization ID.
526533func GetOrgUsersByOrgID (ctx context.Context , opts * FindOrgMembersOpts ) ([]* OrgUser , error ) {
527534 sess := db .GetEngine (ctx ).Where ("org_id=?" , opts .OrgID )
528- if opts .PublicOnly {
535+ if opts .PublicOnly () {
529536 sess .And ("is_public = ?" , true )
530537 }
538+
531539 if opts .ListOptions .PageSize > 0 {
532540 sess = db .SetSessionPagination (sess , opts )
533541
0 commit comments