[API] add GET /orgs endpoint (#9560)

* introduce `GET /orgs`

* add TEST

* show also other VisibleType's

* update description

* refactor a lot

* SearchUserOptions by default return only public
This commit is contained in:
6543 2020-01-12 16:43:44 +01:00 committed by Lunny Xiao
parent 497e15fdc2
commit 10055bd2b1
8 changed files with 108 additions and 9 deletions

View file

@ -1469,7 +1469,7 @@ type SearchUserOptions struct {
UID int64
OrderBy SearchOrderBy
Page int
Private bool // Include private orgs in search
Visible []structs.VisibleType
OwnerID int64 // id of user for visibility calculation
PageSize int // Can be smaller than or equal to setting.UI.ExplorePagingNum
IsActive util.OptionalBool
@ -1492,8 +1492,9 @@ func (opts *SearchUserOptions) toConds() builder.Cond {
cond = cond.And(keywordCond)
}
if !opts.Private {
// user not logged in and so they won't be allowed to see non-public orgs
if len(opts.Visible) > 0 {
cond = cond.And(builder.In("visibility", opts.Visible))
} else {
cond = cond.And(builder.In("visibility", structs.VisibleTypePublic))
}