summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKN4CK3R <admin@oldschoolhack.me>2022-07-21 12:41:50 +0200
committerGitHub <noreply@github.com>2022-07-21 11:41:50 +0100
commit7690de56f7bdcc5065af2c9478e8572d318a84f3 (patch)
tree1379bc7b5532bdb74b22ac08aaaaca8fe32c7a82
parente5ef7c2a91db0454b216ce2c1f5188363b1448a3 (diff)
downloadgitea-7690de56f7bdcc5065af2c9478e8572d318a84f3.tar.gz
gitea-7690de56f7bdcc5065af2c9478e8572d318a84f3.zip
Simplify visibility checks (#20406)
Was looking into the visibility checks because I need them for something different and noticed the checks are more complicated than they have to be. The rule is just: user/org is visible if - The doer is a member of the org, regardless of the org visibility - The doer is not restricted and the user/org is public or limited
-rw-r--r--models/user/search.go15
1 files changed, 4 insertions, 11 deletions
diff --git a/models/user/search.go b/models/user/search.go
index 1b65dcb12d..76ff55ea26 100644
--- a/models/user/search.go
+++ b/models/user/search.go
@@ -59,25 +59,18 @@ func (opts *SearchUserOptions) toSearchQueryBase() *xorm.Session {
}
if opts.Actor != nil {
- exprCond := builder.Expr("org_user.org_id = `user`.id")
-
// If Admin - they see all users!
if !opts.Actor.IsAdmin {
- // Force visibility for privacy
- var accessCond builder.Cond
+ // Users can see an organization they are a member of
+ accessCond := builder.In("id", builder.Select("org_id").From("org_user").Where(builder.Eq{"uid": opts.Actor.ID}))
if !opts.Actor.IsRestricted {
- accessCond = builder.Or(
- builder.In("id", builder.Select("org_id").From("org_user").LeftJoin("`user`", exprCond).Where(builder.And(builder.Eq{"uid": opts.Actor.ID}, builder.Eq{"visibility": structs.VisibleTypePrivate}))),
- builder.In("visibility", structs.VisibleTypePublic, structs.VisibleTypeLimited))
- } else {
- // restricted users only see orgs they are a member of
- accessCond = builder.In("id", builder.Select("org_id").From("org_user").LeftJoin("`user`", exprCond).Where(builder.And(builder.Eq{"uid": opts.Actor.ID})))
+ // Not-Restricted users can see public and limited users/organizations
+ accessCond = accessCond.Or(builder.In("visibility", structs.VisibleTypePublic, structs.VisibleTypeLimited))
}
// Don't forget about self
accessCond = accessCond.Or(builder.Eq{"id": opts.Actor.ID})
cond = cond.And(accessCond)
}
-
} else {
// Force visibility for privacy
// Not logged in - only public users