diff options
author | 6543 <6543@obermui.de> | 2020-12-16 23:39:12 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-12-17 00:39:12 +0100 |
commit | 9e456b5a56c3cf1860ca86be85e19619ad544160 (patch) | |
tree | 2088623e52e885947199b947c1a593ba30ecb9c0 /routers/api/v1/utils | |
parent | 069acf6a215ea05f23ba5bf75e84dcc63ff95044 (diff) | |
download | gitea-9e456b5a56c3cf1860ca86be85e19619ad544160.tar.gz gitea-9e456b5a56c3cf1860ca86be85e19619ad544160.zip |
HotFix: Hide private partisipation in Orgs (#13994)
* HotFix: Hide private partisipation in Orgs
* refactor & add node to fuc GetOrganizations
Diffstat (limited to 'routers/api/v1/utils')
-rw-r--r-- | routers/api/v1/utils/utils.go | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/routers/api/v1/utils/utils.go b/routers/api/v1/utils/utils.go index ad1a136db4..5732ea7f7d 100644 --- a/routers/api/v1/utils/utils.go +++ b/routers/api/v1/utils/utils.go @@ -66,3 +66,22 @@ func GetListOptions(ctx *context.APIContext) models.ListOptions { PageSize: convert.ToCorrectPageSize(ctx.QueryInt("limit")), } } + +// PaginateUserSlice cut a slice of Users as per pagination options +// TODO: make it generic +func PaginateUserSlice(items []*models.User, page, pageSize int) []*models.User { + if page != 0 { + page-- + } + + if page*pageSize >= len(items) { + return items[len(items):] + } + + items = items[page*pageSize:] + + if len(items) > pageSize { + return items[:pageSize] + } + return items +} |