Add improved sorting and key-based pagination
This commit is contained in:
@@ -4,7 +4,7 @@ import (
|
||||
"fmt"
|
||||
"github.com/cortezaproject/corteza-server/pkg/auth"
|
||||
"github.com/cortezaproject/corteza-server/pkg/cli"
|
||||
"github.com/cortezaproject/corteza-server/pkg/rh"
|
||||
"github.com/cortezaproject/corteza-server/store"
|
||||
"github.com/cortezaproject/corteza-server/system/service"
|
||||
"github.com/cortezaproject/corteza-server/system/types"
|
||||
"github.com/spf13/cobra"
|
||||
@@ -44,13 +44,9 @@ func Users(app serviceInitializer) *cobra.Command {
|
||||
limit, err = strconv.Atoi(limitFlag)
|
||||
cli.HandleError(err)
|
||||
|
||||
uf := types.UserFilter{
|
||||
Sort: "updated_at",
|
||||
Query: queryFlag,
|
||||
PageFilter: rh.PageFilter{
|
||||
PerPage: uint(limit),
|
||||
},
|
||||
}
|
||||
uf := types.UserFilter{Query: queryFlag}
|
||||
uf.Sort = store.SortExprSet{&store.SortExpr{Column: "updated_at"}}
|
||||
uf.Limit = uint(limit)
|
||||
|
||||
users, _, err := service.DefaultNgStore.SearchUsers(ctx, uf)
|
||||
cli.HandleError(err)
|
||||
|
||||
@@ -255,15 +255,9 @@ endpoints:
|
||||
- type: uint
|
||||
name: limit
|
||||
title: Limit
|
||||
- type: uint
|
||||
name: offset
|
||||
title: Offset
|
||||
- type: uint
|
||||
name: page
|
||||
title: Page number (1-based)
|
||||
- type: uint
|
||||
name: perPage
|
||||
title: Returned items per page (default 50)
|
||||
- type: string
|
||||
name: pageCursor
|
||||
title: Page cursor
|
||||
- type: string
|
||||
name: sort
|
||||
title: Sort items
|
||||
@@ -503,15 +497,9 @@ endpoints:
|
||||
- type: uint
|
||||
name: limit
|
||||
title: Limit
|
||||
- type: uint
|
||||
name: offset
|
||||
title: Offset
|
||||
- type: uint
|
||||
name: page
|
||||
title: Page number (1-based)
|
||||
- type: uint
|
||||
name: perPage
|
||||
title: Returned items per page (default 50)
|
||||
- type: string
|
||||
name: pageCursor
|
||||
title: Page cursor
|
||||
- type: string
|
||||
name: sort
|
||||
title: Sort items
|
||||
@@ -711,15 +699,9 @@ endpoints:
|
||||
- type: uint
|
||||
name: limit
|
||||
title: Limit
|
||||
- type: uint
|
||||
name: offset
|
||||
title: Offset
|
||||
- type: uint
|
||||
name: page
|
||||
title: Page number (1-based)
|
||||
- type: uint
|
||||
name: perPage
|
||||
title: Returned items per page (default 50)
|
||||
- type: string
|
||||
name: pageCursor
|
||||
title: Page cursor
|
||||
- type: string
|
||||
name: sort
|
||||
title: Sort items
|
||||
@@ -924,15 +906,9 @@ endpoints:
|
||||
- type: uint
|
||||
name: limit
|
||||
title: Limit
|
||||
- type: uint
|
||||
name: offset
|
||||
title: Offset
|
||||
- type: uint
|
||||
name: page
|
||||
title: Page number (1-based)
|
||||
- type: uint
|
||||
name: perPage
|
||||
title: Returned items per page (default 50)
|
||||
- type: string
|
||||
name: pageCursor
|
||||
title: Page cursor
|
||||
- type: string
|
||||
name: sort
|
||||
title: Sort items
|
||||
@@ -1205,12 +1181,6 @@ endpoints:
|
||||
- type: uint
|
||||
name: limit
|
||||
title: Limit
|
||||
- type: uint
|
||||
name: offset
|
||||
title: Offset
|
||||
- type: uint
|
||||
name: page
|
||||
title: Page number (1-based)
|
||||
- type: uint
|
||||
name: perPage
|
||||
title: Returned items per page (default 50)
|
||||
- type: string
|
||||
name: pageCursor
|
||||
title: Page cursor
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"github.com/cortezaproject/corteza-server/pkg/actionlog"
|
||||
"github.com/cortezaproject/corteza-server/pkg/payload"
|
||||
"github.com/cortezaproject/corteza-server/pkg/rh"
|
||||
"github.com/cortezaproject/corteza-server/store"
|
||||
"github.com/cortezaproject/corteza-server/system/rest/request"
|
||||
"github.com/cortezaproject/corteza-server/system/service"
|
||||
"github.com/cortezaproject/corteza-server/system/types"
|
||||
@@ -37,14 +38,22 @@ func (Actionlog) New() *Actionlog {
|
||||
}
|
||||
|
||||
func (ctrl *Actionlog) List(ctx context.Context, r *request.ActionlogList) (interface{}, error) {
|
||||
ee, f, err := ctrl.actionSvc.Find(ctx, actionlog.Filter{
|
||||
From: r.From,
|
||||
To: r.To,
|
||||
ActorID: payload.ParseUint64s(r.ActorID),
|
||||
Resource: r.Resource,
|
||||
Action: r.Action,
|
||||
PageFilter: rh.Paging(r),
|
||||
})
|
||||
var (
|
||||
err error
|
||||
f = actionlog.Filter{
|
||||
From: r.From,
|
||||
To: r.To,
|
||||
ActorID: payload.ParseUint64s(r.ActorID),
|
||||
Resource: r.Resource,
|
||||
Action: r.Action,
|
||||
}
|
||||
)
|
||||
|
||||
if f.Paging, err = store.NewPaging(r.Limit, r.PageCursor); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
ee, f, err := ctrl.actionSvc.Find(ctx, f)
|
||||
|
||||
return ctrl.makeFilterPayload(ctx, ee, f, err)
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package rest
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/cortezaproject/corteza-server/store"
|
||||
"github.com/titpetric/factory/resputil"
|
||||
|
||||
"github.com/cortezaproject/corteza-server/pkg/corredor"
|
||||
@@ -60,14 +61,22 @@ func (Application) New() *Application {
|
||||
}
|
||||
|
||||
func (ctrl *Application) List(ctx context.Context, r *request.ApplicationList) (interface{}, error) {
|
||||
f := types.ApplicationFilter{
|
||||
Name: r.Name,
|
||||
Query: r.Query,
|
||||
var (
|
||||
err error
|
||||
f = types.ApplicationFilter{
|
||||
Name: r.Name,
|
||||
Query: r.Query,
|
||||
|
||||
Deleted: rh.FilterState(r.Deleted),
|
||||
Deleted: rh.FilterState(r.Deleted),
|
||||
}
|
||||
)
|
||||
|
||||
Sort: rh.NormalizeSortColumns(r.Sort),
|
||||
PageFilter: rh.Paging(r),
|
||||
if f.Paging, err = store.NewPaging(r.Limit, r.PageCursor); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if f.Sorting, err = store.NewSorting(r.Sort); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
set, filter, err := ctrl.application.Search(ctx, f)
|
||||
|
||||
@@ -2,10 +2,9 @@ package rest
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/cortezaproject/corteza-server/store"
|
||||
"time"
|
||||
|
||||
"github.com/cortezaproject/corteza-server/pkg/rh"
|
||||
|
||||
"github.com/titpetric/factory/resputil"
|
||||
|
||||
"github.com/cortezaproject/corteza-server/pkg/auth"
|
||||
@@ -38,15 +37,24 @@ func (Reminder) New() *Reminder {
|
||||
}
|
||||
|
||||
func (ctrl *Reminder) List(ctx context.Context, r *request.ReminderList) (interface{}, error) {
|
||||
f := types.ReminderFilter{
|
||||
AssignedTo: r.AssignedTo,
|
||||
Resource: r.Resource,
|
||||
ScheduledFrom: r.ScheduledFrom,
|
||||
ScheduledUntil: r.ScheduledUntil,
|
||||
ExcludeDismissed: r.ExcludeDismissed,
|
||||
ScheduledOnly: r.ScheduledOnly,
|
||||
var (
|
||||
err error
|
||||
f = types.ReminderFilter{
|
||||
AssignedTo: r.AssignedTo,
|
||||
Resource: r.Resource,
|
||||
ScheduledFrom: r.ScheduledFrom,
|
||||
ScheduledUntil: r.ScheduledUntil,
|
||||
ExcludeDismissed: r.ExcludeDismissed,
|
||||
ScheduledOnly: r.ScheduledOnly,
|
||||
}
|
||||
)
|
||||
|
||||
PageFilter: rh.Paging(r),
|
||||
if f.Paging, err = store.NewPaging(r.Limit, r.PageCursor); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if f.Sorting, err = store.NewSorting(r.Sort); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
set, filter, err := ctrl.reminder.Find(ctx, f)
|
||||
|
||||
@@ -61,20 +61,10 @@ type (
|
||||
// Limit
|
||||
Limit uint
|
||||
|
||||
// Offset GET parameter
|
||||
// PageCursor GET parameter
|
||||
//
|
||||
// Offset
|
||||
Offset uint
|
||||
|
||||
// Page GET parameter
|
||||
//
|
||||
// Page number (1-based)
|
||||
Page uint
|
||||
|
||||
// PerPage GET parameter
|
||||
//
|
||||
// Returned items per page (default 50)
|
||||
PerPage uint
|
||||
// Page cursor
|
||||
PageCursor string
|
||||
}
|
||||
)
|
||||
|
||||
@@ -86,15 +76,13 @@ func NewActionlogList() *ActionlogList {
|
||||
// Auditable returns all auditable/loggable parameters
|
||||
func (r ActionlogList) Auditable() map[string]interface{} {
|
||||
return map[string]interface{}{
|
||||
"from": r.From,
|
||||
"to": r.To,
|
||||
"resource": r.Resource,
|
||||
"action": r.Action,
|
||||
"actorID": r.ActorID,
|
||||
"limit": r.Limit,
|
||||
"offset": r.Offset,
|
||||
"page": r.Page,
|
||||
"perPage": r.PerPage,
|
||||
"from": r.From,
|
||||
"to": r.To,
|
||||
"resource": r.Resource,
|
||||
"action": r.Action,
|
||||
"actorID": r.ActorID,
|
||||
"limit": r.Limit,
|
||||
"pageCursor": r.PageCursor,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -129,18 +117,8 @@ func (r ActionlogList) GetLimit() uint {
|
||||
}
|
||||
|
||||
// Auditable returns all auditable/loggable parameters
|
||||
func (r ActionlogList) GetOffset() uint {
|
||||
return r.Offset
|
||||
}
|
||||
|
||||
// Auditable returns all auditable/loggable parameters
|
||||
func (r ActionlogList) GetPage() uint {
|
||||
return r.Page
|
||||
}
|
||||
|
||||
// Auditable returns all auditable/loggable parameters
|
||||
func (r ActionlogList) GetPerPage() uint {
|
||||
return r.PerPage
|
||||
func (r ActionlogList) GetPageCursor() string {
|
||||
return r.PageCursor
|
||||
}
|
||||
|
||||
// Fill processes request and fills internal variables
|
||||
@@ -201,20 +179,8 @@ func (r *ActionlogList) Fill(req *http.Request) (err error) {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if val, ok := tmp["offset"]; ok && len(val) > 0 {
|
||||
r.Offset, err = payload.ParseUint(val[0]), nil
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if val, ok := tmp["page"]; ok && len(val) > 0 {
|
||||
r.Page, err = payload.ParseUint(val[0]), nil
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if val, ok := tmp["perPage"]; ok && len(val) > 0 {
|
||||
r.PerPage, err = payload.ParseUint(val[0]), nil
|
||||
if val, ok := tmp["pageCursor"]; ok && len(val) > 0 {
|
||||
r.PageCursor, err = val[0], nil
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -51,20 +51,10 @@ type (
|
||||
// Limit
|
||||
Limit uint
|
||||
|
||||
// Offset GET parameter
|
||||
// PageCursor GET parameter
|
||||
//
|
||||
// Offset
|
||||
Offset uint
|
||||
|
||||
// Page GET parameter
|
||||
//
|
||||
// Page number (1-based)
|
||||
Page uint
|
||||
|
||||
// PerPage GET parameter
|
||||
//
|
||||
// Returned items per page (default 50)
|
||||
PerPage uint
|
||||
// Page cursor
|
||||
PageCursor string
|
||||
|
||||
// Sort GET parameter
|
||||
//
|
||||
@@ -163,14 +153,12 @@ func NewApplicationList() *ApplicationList {
|
||||
// Auditable returns all auditable/loggable parameters
|
||||
func (r ApplicationList) Auditable() map[string]interface{} {
|
||||
return map[string]interface{}{
|
||||
"name": r.Name,
|
||||
"query": r.Query,
|
||||
"deleted": r.Deleted,
|
||||
"limit": r.Limit,
|
||||
"offset": r.Offset,
|
||||
"page": r.Page,
|
||||
"perPage": r.PerPage,
|
||||
"sort": r.Sort,
|
||||
"name": r.Name,
|
||||
"query": r.Query,
|
||||
"deleted": r.Deleted,
|
||||
"limit": r.Limit,
|
||||
"pageCursor": r.PageCursor,
|
||||
"sort": r.Sort,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -195,18 +183,8 @@ func (r ApplicationList) GetLimit() uint {
|
||||
}
|
||||
|
||||
// Auditable returns all auditable/loggable parameters
|
||||
func (r ApplicationList) GetOffset() uint {
|
||||
return r.Offset
|
||||
}
|
||||
|
||||
// Auditable returns all auditable/loggable parameters
|
||||
func (r ApplicationList) GetPage() uint {
|
||||
return r.Page
|
||||
}
|
||||
|
||||
// Auditable returns all auditable/loggable parameters
|
||||
func (r ApplicationList) GetPerPage() uint {
|
||||
return r.PerPage
|
||||
func (r ApplicationList) GetPageCursor() string {
|
||||
return r.PageCursor
|
||||
}
|
||||
|
||||
// Auditable returns all auditable/loggable parameters
|
||||
@@ -255,20 +233,8 @@ func (r *ApplicationList) Fill(req *http.Request) (err error) {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if val, ok := tmp["offset"]; ok && len(val) > 0 {
|
||||
r.Offset, err = payload.ParseUint(val[0]), nil
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if val, ok := tmp["page"]; ok && len(val) > 0 {
|
||||
r.Page, err = payload.ParseUint(val[0]), nil
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if val, ok := tmp["perPage"]; ok && len(val) > 0 {
|
||||
r.PerPage, err = payload.ParseUint(val[0]), nil
|
||||
if val, ok := tmp["pageCursor"]; ok && len(val) > 0 {
|
||||
r.PageCursor, err = val[0], nil
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -72,20 +72,10 @@ type (
|
||||
// Limit
|
||||
Limit uint
|
||||
|
||||
// Offset GET parameter
|
||||
// PageCursor GET parameter
|
||||
//
|
||||
// Offset
|
||||
Offset uint
|
||||
|
||||
// Page GET parameter
|
||||
//
|
||||
// Page number (1-based)
|
||||
Page uint
|
||||
|
||||
// PerPage GET parameter
|
||||
//
|
||||
// Returned items per page (default 50)
|
||||
PerPage uint
|
||||
// Page cursor
|
||||
PageCursor string
|
||||
|
||||
// Sort GET parameter
|
||||
//
|
||||
@@ -192,9 +182,7 @@ func (r ReminderList) Auditable() map[string]interface{} {
|
||||
"scheduledOnly": r.ScheduledOnly,
|
||||
"excludeDismissed": r.ExcludeDismissed,
|
||||
"limit": r.Limit,
|
||||
"offset": r.Offset,
|
||||
"page": r.Page,
|
||||
"perPage": r.PerPage,
|
||||
"pageCursor": r.PageCursor,
|
||||
"sort": r.Sort,
|
||||
}
|
||||
}
|
||||
@@ -240,18 +228,8 @@ func (r ReminderList) GetLimit() uint {
|
||||
}
|
||||
|
||||
// Auditable returns all auditable/loggable parameters
|
||||
func (r ReminderList) GetOffset() uint {
|
||||
return r.Offset
|
||||
}
|
||||
|
||||
// Auditable returns all auditable/loggable parameters
|
||||
func (r ReminderList) GetPage() uint {
|
||||
return r.Page
|
||||
}
|
||||
|
||||
// Auditable returns all auditable/loggable parameters
|
||||
func (r ReminderList) GetPerPage() uint {
|
||||
return r.PerPage
|
||||
func (r ReminderList) GetPageCursor() string {
|
||||
return r.PageCursor
|
||||
}
|
||||
|
||||
// Auditable returns all auditable/loggable parameters
|
||||
@@ -329,20 +307,8 @@ func (r *ReminderList) Fill(req *http.Request) (err error) {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if val, ok := tmp["offset"]; ok && len(val) > 0 {
|
||||
r.Offset, err = payload.ParseUint(val[0]), nil
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if val, ok := tmp["page"]; ok && len(val) > 0 {
|
||||
r.Page, err = payload.ParseUint(val[0]), nil
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if val, ok := tmp["perPage"]; ok && len(val) > 0 {
|
||||
r.PerPage, err = payload.ParseUint(val[0]), nil
|
||||
if val, ok := tmp["pageCursor"]; ok && len(val) > 0 {
|
||||
r.PageCursor, err = val[0], nil
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -50,20 +50,10 @@ type (
|
||||
// Limit
|
||||
Limit uint
|
||||
|
||||
// Offset GET parameter
|
||||
// PageCursor GET parameter
|
||||
//
|
||||
// Offset
|
||||
Offset uint
|
||||
|
||||
// Page GET parameter
|
||||
//
|
||||
// Page number (1-based)
|
||||
Page uint
|
||||
|
||||
// PerPage GET parameter
|
||||
//
|
||||
// Returned items per page (default 50)
|
||||
PerPage uint
|
||||
// Page cursor
|
||||
PageCursor string
|
||||
|
||||
// Sort GET parameter
|
||||
//
|
||||
@@ -221,14 +211,12 @@ func NewRoleList() *RoleList {
|
||||
// Auditable returns all auditable/loggable parameters
|
||||
func (r RoleList) Auditable() map[string]interface{} {
|
||||
return map[string]interface{}{
|
||||
"query": r.Query,
|
||||
"deleted": r.Deleted,
|
||||
"archived": r.Archived,
|
||||
"limit": r.Limit,
|
||||
"offset": r.Offset,
|
||||
"page": r.Page,
|
||||
"perPage": r.PerPage,
|
||||
"sort": r.Sort,
|
||||
"query": r.Query,
|
||||
"deleted": r.Deleted,
|
||||
"archived": r.Archived,
|
||||
"limit": r.Limit,
|
||||
"pageCursor": r.PageCursor,
|
||||
"sort": r.Sort,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -253,18 +241,8 @@ func (r RoleList) GetLimit() uint {
|
||||
}
|
||||
|
||||
// Auditable returns all auditable/loggable parameters
|
||||
func (r RoleList) GetOffset() uint {
|
||||
return r.Offset
|
||||
}
|
||||
|
||||
// Auditable returns all auditable/loggable parameters
|
||||
func (r RoleList) GetPage() uint {
|
||||
return r.Page
|
||||
}
|
||||
|
||||
// Auditable returns all auditable/loggable parameters
|
||||
func (r RoleList) GetPerPage() uint {
|
||||
return r.PerPage
|
||||
func (r RoleList) GetPageCursor() string {
|
||||
return r.PageCursor
|
||||
}
|
||||
|
||||
// Auditable returns all auditable/loggable parameters
|
||||
@@ -313,20 +291,8 @@ func (r *RoleList) Fill(req *http.Request) (err error) {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if val, ok := tmp["offset"]; ok && len(val) > 0 {
|
||||
r.Offset, err = payload.ParseUint(val[0]), nil
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if val, ok := tmp["page"]; ok && len(val) > 0 {
|
||||
r.Page, err = payload.ParseUint(val[0]), nil
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if val, ok := tmp["perPage"]; ok && len(val) > 0 {
|
||||
r.PerPage, err = payload.ParseUint(val[0]), nil
|
||||
if val, ok := tmp["pageCursor"]; ok && len(val) > 0 {
|
||||
r.PageCursor, err = val[0], nil
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -91,20 +91,10 @@ type (
|
||||
// Limit
|
||||
Limit uint
|
||||
|
||||
// Offset GET parameter
|
||||
// PageCursor GET parameter
|
||||
//
|
||||
// Offset
|
||||
Offset uint
|
||||
|
||||
// Page GET parameter
|
||||
//
|
||||
// Page number (1-based)
|
||||
Page uint
|
||||
|
||||
// PerPage GET parameter
|
||||
//
|
||||
// Returned items per page (default 50)
|
||||
PerPage uint
|
||||
// Page cursor
|
||||
PageCursor string
|
||||
|
||||
// Sort GET parameter
|
||||
//
|
||||
@@ -272,9 +262,7 @@ func (r UserList) Auditable() map[string]interface{} {
|
||||
"deleted": r.Deleted,
|
||||
"suspended": r.Suspended,
|
||||
"limit": r.Limit,
|
||||
"offset": r.Offset,
|
||||
"page": r.Page,
|
||||
"perPage": r.PerPage,
|
||||
"pageCursor": r.PageCursor,
|
||||
"sort": r.Sort,
|
||||
}
|
||||
}
|
||||
@@ -340,18 +328,8 @@ func (r UserList) GetLimit() uint {
|
||||
}
|
||||
|
||||
// Auditable returns all auditable/loggable parameters
|
||||
func (r UserList) GetOffset() uint {
|
||||
return r.Offset
|
||||
}
|
||||
|
||||
// Auditable returns all auditable/loggable parameters
|
||||
func (r UserList) GetPage() uint {
|
||||
return r.Page
|
||||
}
|
||||
|
||||
// Auditable returns all auditable/loggable parameters
|
||||
func (r UserList) GetPerPage() uint {
|
||||
return r.PerPage
|
||||
func (r UserList) GetPageCursor() string {
|
||||
return r.PageCursor
|
||||
}
|
||||
|
||||
// Auditable returns all auditable/loggable parameters
|
||||
@@ -458,20 +436,8 @@ func (r *UserList) Fill(req *http.Request) (err error) {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if val, ok := tmp["offset"]; ok && len(val) > 0 {
|
||||
r.Offset, err = payload.ParseUint(val[0]), nil
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if val, ok := tmp["page"]; ok && len(val) > 0 {
|
||||
r.Page, err = payload.ParseUint(val[0]), nil
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if val, ok := tmp["perPage"]; ok && len(val) > 0 {
|
||||
r.PerPage, err = payload.ParseUint(val[0]), nil
|
||||
if val, ok := tmp["pageCursor"]; ok && len(val) > 0 {
|
||||
r.PageCursor, err = val[0], nil
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package rest
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/cortezaproject/corteza-server/store"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/titpetric/factory/resputil"
|
||||
@@ -57,14 +58,22 @@ func (ctrl Role) Read(ctx context.Context, r *request.RoleRead) (interface{}, er
|
||||
}
|
||||
|
||||
func (ctrl Role) List(ctx context.Context, r *request.RoleList) (interface{}, error) {
|
||||
f := types.RoleFilter{
|
||||
Query: r.Query,
|
||||
var (
|
||||
err error
|
||||
f = types.RoleFilter{
|
||||
Query: r.Query,
|
||||
|
||||
Archived: rh.FilterState(r.Archived),
|
||||
Deleted: rh.FilterState(r.Deleted),
|
||||
Archived: rh.FilterState(r.Archived),
|
||||
Deleted: rh.FilterState(r.Deleted),
|
||||
}
|
||||
)
|
||||
|
||||
Sort: rh.NormalizeSortColumns(r.Sort),
|
||||
PageFilter: rh.Paging(r),
|
||||
if f.Paging, err = store.NewPaging(r.Limit, r.PageCursor); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if f.Sorting, err = store.NewSorting(r.Sort); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
set, filter, err := ctrl.role.With(ctx).Find(f)
|
||||
|
||||
@@ -2,6 +2,7 @@ package rest
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/cortezaproject/corteza-server/store"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/titpetric/factory/resputil"
|
||||
|
||||
@@ -36,20 +37,27 @@ func (User) New() *User {
|
||||
}
|
||||
|
||||
func (ctrl User) List(ctx context.Context, r *request.UserList) (interface{}, error) {
|
||||
f := types.UserFilter{
|
||||
UserID: payload.ParseUint64s(r.UserID),
|
||||
RoleID: payload.ParseUint64s(r.RoleID),
|
||||
Query: r.Query,
|
||||
Email: r.Email,
|
||||
Username: r.Username,
|
||||
Handle: r.Handle,
|
||||
Kind: r.Kind,
|
||||
Suspended: rh.FilterState(r.Suspended),
|
||||
Deleted: rh.FilterState(r.Deleted),
|
||||
var (
|
||||
err error
|
||||
f = types.UserFilter{
|
||||
UserID: payload.ParseUint64s(r.UserID),
|
||||
RoleID: payload.ParseUint64s(r.RoleID),
|
||||
Query: r.Query,
|
||||
Email: r.Email,
|
||||
Username: r.Username,
|
||||
Handle: r.Handle,
|
||||
Kind: r.Kind,
|
||||
Suspended: rh.FilterState(r.Suspended),
|
||||
Deleted: rh.FilterState(r.Deleted),
|
||||
}
|
||||
)
|
||||
|
||||
Sort: rh.NormalizeSortColumns(r.Sort),
|
||||
if f.Paging, err = store.NewPaging(r.Limit, r.PageCursor); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
PageFilter: rh.Paging(r),
|
||||
if f.Sorting, err = store.NewSorting(r.Sort); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if r.IncSuspended && f.Suspended == 0 {
|
||||
|
||||
@@ -64,9 +64,16 @@ func (svc *application) Search(ctx context.Context, filter types.ApplicationFilt
|
||||
aaProps = &applicationActionProps{filter: &filter}
|
||||
)
|
||||
|
||||
err = func() error {
|
||||
filter.IsReadable = svc.ac.FilterReadableApplications(ctx)
|
||||
// For each fetched item, store backend will check if it is valid or not
|
||||
filter.Check = func(res *types.Application) (bool, error) {
|
||||
if !svc.ac.CanReadApplication(ctx, res) {
|
||||
return false, nil
|
||||
}
|
||||
|
||||
return true, nil
|
||||
}
|
||||
|
||||
err = func() error {
|
||||
if filter.Deleted > rh.FilterStateExcluded {
|
||||
// If list with deleted applications is requested
|
||||
// user must have access permissions to system (ie: is admin)
|
||||
|
||||
@@ -96,9 +96,16 @@ func (svc role) Find(filter types.RoleFilter) (rr types.RoleSet, f types.RoleFil
|
||||
raProps = &roleActionProps{filter: &filter}
|
||||
)
|
||||
|
||||
err = func() error {
|
||||
filter.IsReadable = svc.ac.FilterReadableRoles(svc.ctx)
|
||||
// For each fetched item, store backend will check if it is valid or not
|
||||
filter.Check = func(res *types.Role) (bool, error) {
|
||||
if !svc.ac.CanReadRole(svc.ctx, res) {
|
||||
return false, nil
|
||||
}
|
||||
|
||||
return true, nil
|
||||
}
|
||||
|
||||
err = func() error {
|
||||
if filter.Deleted > 0 {
|
||||
// If list with deleted or suspended users is requested
|
||||
// user must have access permissions to system (ie: is admin)
|
||||
|
||||
@@ -70,6 +70,7 @@ func (svc settings) findByPrefix(ctx context.Context, pp ...string) (types.Setti
|
||||
var (
|
||||
f = types.SettingsFilter{
|
||||
Prefix: strings.Join(pp, "."),
|
||||
Check: func(*types.SettingValue) (bool, error) { return true, nil },
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
@@ -262,12 +262,13 @@ func (svc user) Find(filter types.UserFilter) (uu types.UserSet, f types.UserFil
|
||||
uaProps = &userActionProps{filter: &filter}
|
||||
)
|
||||
|
||||
filter.Check = func(user *types.User) (bool, error) {
|
||||
if !svc.ac.CanReadUser(svc.ctx, user) {
|
||||
// For each fetched item, store backend will check if it is valid or not
|
||||
filter.Check = func(res *types.User) (bool, error) {
|
||||
if !svc.ac.CanReadUser(svc.ctx, res) {
|
||||
return false, nil
|
||||
}
|
||||
|
||||
svc.handlePrivateData(user)
|
||||
svc.handlePrivateData(res)
|
||||
return true, nil
|
||||
}
|
||||
|
||||
@@ -283,14 +284,6 @@ func (svc user) Find(filter types.UserFilter) (uu types.UserSet, f types.UserFil
|
||||
}
|
||||
}
|
||||
|
||||
//// Prepare filter for email unmasking check
|
||||
//filter.IsEmailUnmaskable = svc.ac.FilterUsersWithUnmaskableEmail(svc.ctx)
|
||||
//
|
||||
//// Prepare filter for name unmasking check
|
||||
//filter.IsNameUnmaskable = svc.ac.FilterUsersWithUnmaskableName(svc.ctx)
|
||||
//
|
||||
//filter.IsReadable = svc.ac.FilterReadableUsers(svc.ctx)
|
||||
|
||||
uu, f, err = svc.store.SearchUsers(svc.ctx, filter)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -3,6 +3,7 @@ package types
|
||||
import (
|
||||
"database/sql/driver"
|
||||
"encoding/json"
|
||||
"github.com/cortezaproject/corteza-server/store"
|
||||
"time"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
@@ -39,22 +40,17 @@ type (
|
||||
Name string `json:"name"`
|
||||
Query string `json:"query"`
|
||||
|
||||
Sort string `json:"sort"`
|
||||
|
||||
// Standard paging fields & helpers
|
||||
rh.PageFilter
|
||||
|
||||
// Resource permission check filter
|
||||
// deprecated
|
||||
IsReadable *permissions.ResourceFilter `json:"-"`
|
||||
Deleted rh.FilterState `json:"deleted"`
|
||||
|
||||
// Check fn is called by store backend for each resource found function can
|
||||
// modify the resource and return false if store should not return it
|
||||
//
|
||||
// Store then loads additional resources to satisfy the paging parameters
|
||||
Check func(user *Application) (bool, error)
|
||||
Check func(*Application) (bool, error) `json:"-"`
|
||||
|
||||
Deleted rh.FilterState `json:"deleted"`
|
||||
// Standard helpers for paging and sorting
|
||||
store.Sorting
|
||||
store.Paging
|
||||
}
|
||||
|
||||
ApplicationMetrics struct {
|
||||
|
||||
@@ -3,11 +3,10 @@ package types
|
||||
import (
|
||||
"database/sql/driver"
|
||||
"encoding/json"
|
||||
"github.com/cortezaproject/corteza-server/store"
|
||||
"time"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"github.com/cortezaproject/corteza-server/pkg/rh"
|
||||
)
|
||||
|
||||
type (
|
||||
@@ -35,10 +34,10 @@ type (
|
||||
// modify the resource and return false if store should not return it
|
||||
//
|
||||
// Store then loads additional resources to satisfy the paging parameters
|
||||
Check func(user *Attachment) (bool, error)
|
||||
Check func(*Attachment) (bool, error) `json:"-"`
|
||||
|
||||
// Standard paging fields & helpers
|
||||
rh.PageFilter
|
||||
// Standard helpers for paging and sorting
|
||||
store.Paging
|
||||
}
|
||||
|
||||
attachmentImageMeta struct {
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
package types
|
||||
|
||||
import (
|
||||
"github.com/cortezaproject/corteza-server/store"
|
||||
"time"
|
||||
|
||||
"github.com/jmoiron/sqlx/types"
|
||||
|
||||
"github.com/cortezaproject/corteza-server/pkg/rh"
|
||||
)
|
||||
|
||||
type (
|
||||
@@ -38,15 +37,14 @@ type (
|
||||
ExcludeDismissed bool `json:"excludeDismissed"`
|
||||
ScheduledOnly bool `json:"scheduledOnly"`
|
||||
|
||||
Sort string `json:"sort"`
|
||||
|
||||
// Check fn is called by store backend for each resource found function can
|
||||
// modify the resource and return false if store should not return it
|
||||
//
|
||||
// Store then loads additional resources to satisfy the paging parameters
|
||||
Check func(user *Reminder) (bool, error)
|
||||
Check func(*Reminder) (bool, error) `json:"-"`
|
||||
|
||||
// Standard paging fields & helpers
|
||||
rh.PageFilter
|
||||
// Standard helpers for paging and sorting
|
||||
store.Sorting
|
||||
store.Paging
|
||||
}
|
||||
)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package types
|
||||
|
||||
import (
|
||||
"github.com/cortezaproject/corteza-server/store"
|
||||
"time"
|
||||
|
||||
"github.com/cortezaproject/corteza-server/pkg/permissions"
|
||||
@@ -31,20 +32,15 @@ type (
|
||||
Deleted rh.FilterState `json:"deleted"`
|
||||
Archived rh.FilterState `json:"archived"`
|
||||
|
||||
Sort string `json:"sort"`
|
||||
|
||||
// Standard paging fields & helpers
|
||||
rh.PageFilter
|
||||
|
||||
// Resource permission check filter
|
||||
// deprecated
|
||||
IsReadable *permissions.ResourceFilter `json:"-"`
|
||||
|
||||
// Check fn is called by store backend for each resource found function can
|
||||
// modify the resource and return false if store should not return it
|
||||
//
|
||||
// Store then loads additional resources to satisfy the paging parameters
|
||||
Check func(user *Role) (bool, error)
|
||||
Check func(*Role) (bool, error) `json:"-"`
|
||||
|
||||
// Standard helpers for paging and sorting
|
||||
store.Sorting
|
||||
store.Paging
|
||||
}
|
||||
|
||||
RoleMetrics struct {
|
||||
|
||||
@@ -4,7 +4,6 @@ import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/cortezaproject/corteza-server/pkg/rh"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@@ -28,13 +27,11 @@ type (
|
||||
Prefix string `json:"prefix"`
|
||||
OwnedBy uint64 `json:"ownedBy"`
|
||||
|
||||
rh.PageFilter
|
||||
|
||||
// Check fn is called by store backend for each resource found function can
|
||||
// modify the resource and return false if store should not return it
|
||||
//
|
||||
// Store then loads additional resources to satisfy the paging parameters
|
||||
Check func(user *SettingValue) (bool, error)
|
||||
Check func(*SettingValue) (bool, error) `json:"-"`
|
||||
}
|
||||
|
||||
SettingsKV map[string]types.JSONText
|
||||
@@ -44,13 +41,6 @@ const (
|
||||
settingsFilterPerPageMax = 100
|
||||
)
|
||||
|
||||
func (f *SettingsFilter) Normalize() {
|
||||
f.Prefix = strings.TrimSpace(f.Prefix)
|
||||
if f.PerPage > settingsFilterPerPageMax {
|
||||
f.PerPage = settingsFilterPerPageMax
|
||||
}
|
||||
}
|
||||
|
||||
func (v *SettingValue) SetRawValue(str string) error {
|
||||
var dummy interface{}
|
||||
// Test input to be sure we can save it...
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"database/sql/driver"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/cortezaproject/corteza-server/store"
|
||||
"time"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
@@ -52,16 +53,15 @@ type (
|
||||
Deleted rh.FilterState `json:"deleted"`
|
||||
Suspended rh.FilterState `json:"suspended"`
|
||||
|
||||
Sort string `json:"sort"`
|
||||
|
||||
// Check fn is called by store backend for each resource found function can
|
||||
// modify the resource and return false if store should not return it
|
||||
//
|
||||
// Store then loads additional resources to satisfy the paging parameters
|
||||
Check func(user *User) (bool, error)
|
||||
Check func(*User) (bool, error) `json:"-"`
|
||||
|
||||
// Standard paging fields & helpers
|
||||
rh.PageFilter
|
||||
// Standard helpers for paging and sorting
|
||||
store.Sorting
|
||||
store.Paging
|
||||
}
|
||||
|
||||
UserKind string
|
||||
|
||||
Reference in New Issue
Block a user