mirror of
https://github.com/go-gitea/gitea
synced 2025-07-22 18:28:37 +00:00
Limit org member view of restricted users (#32211)
currently restricted users can only see the repos of teams in orgs they are part at. they also should only see the users that are also part at the same team. --- *Sponsored by Kithara Software GmbH*
This commit is contained in:
@@ -22,6 +22,7 @@ import (
|
||||
"code.gitea.io/gitea/modules/util"
|
||||
|
||||
"xorm.io/builder"
|
||||
"xorm.io/xorm"
|
||||
)
|
||||
|
||||
// ________ .__ __ .__
|
||||
@@ -205,11 +206,28 @@ func (opts FindOrgMembersOpts) PublicOnly() bool {
|
||||
return opts.Doer == nil || !(opts.IsDoerMember || opts.Doer.IsAdmin)
|
||||
}
|
||||
|
||||
// applyTeamMatesOnlyFilter make sure restricted users only see public team members and there own team mates
|
||||
func (opts FindOrgMembersOpts) applyTeamMatesOnlyFilter(sess *xorm.Session) {
|
||||
if opts.Doer != nil && opts.IsDoerMember && opts.Doer.IsRestricted {
|
||||
teamMates := builder.Select("DISTINCT team_user.uid").
|
||||
From("team_user").
|
||||
Where(builder.In("team_user.team_id", getUserTeamIDsQueryBuilder(opts.OrgID, opts.Doer.ID))).
|
||||
And(builder.Eq{"team_user.org_id": opts.OrgID})
|
||||
|
||||
sess.And(
|
||||
builder.In("org_user.uid", teamMates).
|
||||
Or(builder.Eq{"org_user.is_public": true}),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
// CountOrgMembers counts the organization's members
|
||||
func CountOrgMembers(ctx context.Context, opts *FindOrgMembersOpts) (int64, error) {
|
||||
sess := db.GetEngine(ctx).Where("org_id=?", opts.OrgID)
|
||||
if opts.PublicOnly() {
|
||||
sess.And("is_public = ?", true)
|
||||
sess = sess.And("is_public = ?", true)
|
||||
} else {
|
||||
opts.applyTeamMatesOnlyFilter(sess)
|
||||
}
|
||||
|
||||
return sess.Count(new(OrgUser))
|
||||
@@ -533,7 +551,9 @@ func GetOrgsCanCreateRepoByUserID(ctx context.Context, userID int64) ([]*Organiz
|
||||
func GetOrgUsersByOrgID(ctx context.Context, opts *FindOrgMembersOpts) ([]*OrgUser, error) {
|
||||
sess := db.GetEngine(ctx).Where("org_id=?", opts.OrgID)
|
||||
if opts.PublicOnly() {
|
||||
sess.And("is_public = ?", true)
|
||||
sess = sess.And("is_public = ?", true)
|
||||
} else {
|
||||
opts.applyTeamMatesOnlyFilter(sess)
|
||||
}
|
||||
|
||||
if opts.ListOptions.PageSize > 0 {
|
||||
@@ -664,6 +684,15 @@ func (org *Organization) getUserTeamIDs(ctx context.Context, userID int64) ([]in
|
||||
Find(&teamIDs)
|
||||
}
|
||||
|
||||
func getUserTeamIDsQueryBuilder(orgID, userID int64) *builder.Builder {
|
||||
return builder.Select("team.id").From("team").
|
||||
InnerJoin("team_user", "team_user.team_id = team.id").
|
||||
Where(builder.Eq{
|
||||
"team_user.org_id": orgID,
|
||||
"team_user.uid": userID,
|
||||
})
|
||||
}
|
||||
|
||||
// TeamsWithAccessToRepo returns all teams that have given access level to the repository.
|
||||
func (org *Organization) TeamsWithAccessToRepo(ctx context.Context, repoID int64, mode perm.AccessMode) ([]*Team, error) {
|
||||
return GetTeamsWithAccessToRepo(ctx, org.ID, repoID, mode)
|
||||
|
Reference in New Issue
Block a user