1
0
Fork 0

CB/feat: Hide users from explore view who have no repos

(unless searched for)

CB: Fix rebased user-no-repo search

Co-authored-by: fnetX <git@fralix.ovh>
codeberg-1.18
Andreas Shimokawa 2021-05-09 00:11:35 +02:00 committed by fnetx
parent 4bcd2dc592
commit 3625fc3a31
No known key found for this signature in database
GPG Key ID: 03870C95EE9F2661
3 changed files with 20 additions and 5 deletions

View File

@ -35,6 +35,8 @@ type SearchUserOptions struct {
IsProhibitLogin util.OptionalBool
ExtraParamStrings map[string]string
// Codeberg-specific
HideNoRepos util.OptionalBool
}
func (opts *SearchUserOptions) toSearchQueryBase() *xorm.Session {
@ -79,6 +81,11 @@ func (opts *SearchUserOptions) toSearchQueryBase() *xorm.Session {
cond = cond.And(builder.Eq{"prohibit_login": opts.IsProhibitLogin.IsTrue()})
}
// Codeberg specific
if opts.HideNoRepos.IsTrue() {
cond = cond.And(builder.Expr("num_repos > 0"))
}
e := db.GetEngine(db.DefaultContext)
if opts.IsTwoFactorEnabled.IsNone() {
return e.Where(cond)

View File

@ -11,6 +11,7 @@ import (
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/structs"
"code.gitea.io/gitea/modules/util"
)
const (
@ -36,5 +37,6 @@ func Organizations(ctx *context.Context) {
Type: user_model.UserTypeOrganization,
ListOptions: db.ListOptions{PageSize: setting.UI.ExplorePagingNum},
Visible: visibleTypes,
HideNoRepos: util.OptionalBoolTrue,
}, tplExploreOrganizations)
}

View File

@ -25,7 +25,7 @@ const (
)
// UserSearchDefaultSortType is the default sort type for user search
const UserSearchDefaultSortType = "alphabetically"
const UserSearchDefaultSortType = "recentupdate" // codeberg-specific
var nullByte = []byte{0x00}
@ -60,11 +60,11 @@ func RenderUserSearch(ctx *context.Context, opts *user_model.SearchUserOptions,
ctx.Data["SortType"] = ctx.FormString("sort")
switch ctx.FormString("sort") {
case "newest":
// codeberg specific
opts.HideNoRepos = util.OptionalBoolFalse
orderBy = "`user`.id DESC"
case "oldest":
orderBy = "`user`.id ASC"
case "recentupdate":
orderBy = "`user`.updated_unix DESC"
case "leastupdate":
orderBy = "`user`.updated_unix ASC"
case "reversealphabetically":
@ -73,9 +73,14 @@ func RenderUserSearch(ctx *context.Context, opts *user_model.SearchUserOptions,
orderBy = "`user`.last_login_unix ASC"
case "reverselastlogin":
orderBy = "`user`.last_login_unix DESC"
case UserSearchDefaultSortType: // "alphabetically"
default:
case "alphabetically":
orderBy = "`user`.name ASC"
case UserSearchDefaultSortType: // "recentupdate" (codeberg)
fallthrough
default:
// codeberg specific
opts.HideNoRepos = util.OptionalBoolFalse
orderBy = "`user`.updated_unix DESC"
ctx.Data["SortType"] = UserSearchDefaultSortType
}
@ -134,5 +139,6 @@ func Users(ctx *context.Context) {
ListOptions: db.ListOptions{PageSize: setting.UI.ExplorePagingNum},
IsActive: util.OptionalBoolTrue,
Visible: []structs.VisibleType{structs.VisibleTypePublic, structs.VisibleTypeLimited, structs.VisibleTypePrivate},
HideNoRepos: util.OptionalBoolTrue,
}, tplExploreUsers)
}