diff options
author | zeripath <art27@cantab.net> | 2020-05-16 21:07:01 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-16 23:07:01 +0300 |
commit | c86bc8e061b91d3d3778d9b97ba16e373250d8f6 (patch) | |
tree | 560fc03cd8647efb79a7c0cb4f5ee5e77b5f52d6 /models/repo_list.go | |
parent | c3d9a5f8464e0921fc4063d903ecf2063fa152fa (diff) | |
download | gitea-c86bc8e061b91d3d3778d9b97ba16e373250d8f6.tar.gz gitea-c86bc8e061b91d3d3778d9b97ba16e373250d8f6.zip |
Add paging and archive/private repository filtering to dashboard list (#11321)
* Add archived options to SearchRepository
Signed-off-by: Andrew Thornton <art27@cantab.net>
* Add only-private search
Signed-off-by: Andrew Thornton <art27@cantab.net>
* Add filter options and paging to dashboard repository page
Signed-off-by: Andrew Thornton <art27@cantab.net>
* swagger generate
Signed-off-by: Andrew Thornton <art27@cantab.net>
* fix-swagger-again
Signed-off-by: Andrew Thornton <art27@cantab.net>
* as per @mrsdizzie also remember state
Signed-off-by: Andrew Thornton <art27@cantab.net>
Co-authored-by: Lauris BH <lauris@nix.lv>
Diffstat (limited to 'models/repo_list.go')
-rw-r--r-- | models/repo_list.go | 37 |
1 files changed, 29 insertions, 8 deletions
diff --git a/models/repo_list.go b/models/repo_list.go index 1632e64eb9..a676ae5c46 100644 --- a/models/repo_list.go +++ b/models/repo_list.go @@ -140,6 +140,7 @@ type SearchRepoOptions struct { PriorityOwnerID int64 OrderBy SearchOrderBy Private bool // Include private repositories in results + OnlyPrivate bool // Include only private repositories in results StarredByID int64 AllPublic bool // Include also all public repositories of users and public organisations AllLimited bool // Include also all public repositories of limited organisations @@ -159,6 +160,10 @@ type SearchRepoOptions struct { // True -> include just mirrors // False -> include just non-mirrors Mirror util.OptionalBool + // None -> include archived AND non-archived + // True -> include just archived + // False -> include just non-archived + Archived util.OptionalBool // only search topic name TopicOnly bool // include description in keyword search @@ -205,14 +210,26 @@ func SearchRepositoryCondition(opts *SearchRepoOptions) builder.Cond { } } else { // Not looking at private organisations - // We should be able to see all non-private repositories that either: - cond = cond.And(builder.Eq{"is_private": false}) - accessCond := builder.Or( - // A. Aren't in organisations __OR__ - builder.NotIn("owner_id", builder.Select("id").From("`user`").Where(builder.Eq{"type": UserTypeOrganization})), - // B. Isn't a private or limited organisation. - builder.NotIn("owner_id", builder.Select("id").From("`user`").Where(builder.Or(builder.Eq{"visibility": structs.VisibleTypeLimited}, builder.Eq{"visibility": structs.VisibleTypePrivate})))) - cond = cond.And(accessCond) + // We should be able to see all non-private repositories that + // isn't in a private or limited organisation. + cond = cond.And( + builder.Eq{"is_private": false}, + builder.NotIn("owner_id", builder.Select("id").From("`user`").Where( + builder.And( + builder.Eq{"type": UserTypeOrganization}, + builder.Or(builder.Eq{"visibility": structs.VisibleTypeLimited}, builder.Eq{"visibility": structs.VisibleTypePrivate}), + )))) + } + + if opts.OnlyPrivate { + cond = cond.And( + builder.Or( + builder.Eq{"is_private": true}, + builder.In("owner_id", builder.Select("id").From("`user`").Where( + builder.And( + builder.Eq{"type": UserTypeOrganization}, + builder.Or(builder.Eq{"visibility": structs.VisibleTypeLimited}, builder.Eq{"visibility": structs.VisibleTypePrivate}), + ))))) } if opts.Template != util.OptionalBoolNone { @@ -299,6 +316,10 @@ func SearchRepositoryCondition(opts *SearchRepoOptions) builder.Cond { cond = cond.And(accessibleRepositoryCondition(opts.Actor)) } + if opts.Archived != util.OptionalBoolNone { + cond = cond.And(builder.Eq{"is_archived": opts.Archived == util.OptionalBoolTrue}) + } + switch opts.HasMilestones { case util.OptionalBoolTrue: cond = cond.And(builder.Gt{"num_milestones": 0}) |