mirror of
https://github.com/empayre/fleet.git
synced 2024-11-06 17:05:18 +00:00
Updated ListQueries method in DB layer
This commit is contained in:
parent
390e0565d0
commit
de9a1540d0
@ -358,12 +358,20 @@ func (ds *Datastore) ListQueries(ctx context.Context, opt fleet.ListQueryOptions
|
|||||||
if opt.OnlyObserverCanRun {
|
if opt.OnlyObserverCanRun {
|
||||||
sql += " AND q.observer_can_run=true"
|
sql += " AND q.observer_can_run=true"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
args := []interface{}{false, aggregatedStatsTypeQuery}
|
||||||
|
whereClause := " AND team_id_char = ''"
|
||||||
|
if opt.TeamID != nil {
|
||||||
|
args = append(args, fmt.Sprint(*opt.TeamID))
|
||||||
|
whereClause = " AND team_id_char = ?"
|
||||||
|
}
|
||||||
|
sql += whereClause
|
||||||
|
|
||||||
sql = appendListOptionsToSQL(sql, &opt.ListOptions)
|
sql = appendListOptionsToSQL(sql, &opt.ListOptions)
|
||||||
|
|
||||||
results := []*fleet.Query{}
|
results := []*fleet.Query{}
|
||||||
|
|
||||||
if err := sqlx.SelectContext(ctx, ds.reader(ctx), &results, sql, false, aggregatedStatsTypeQuery); err != nil {
|
if err := sqlx.SelectContext(ctx, ds.reader(ctx), &results, sql, args...); err != nil {
|
||||||
fmt.Println(err)
|
|
||||||
return nil, ctxerr.Wrap(ctx, err, "listing queries")
|
return nil, ctxerr.Wrap(ctx, err, "listing queries")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -761,6 +761,9 @@ func (l ListOptions) UsesCursorPagination() bool {
|
|||||||
type ListQueryOptions struct {
|
type ListQueryOptions struct {
|
||||||
ListOptions
|
ListOptions
|
||||||
|
|
||||||
|
// TeamID which team the queries belong to. If teamID is nil, then it is assumed the 'global'
|
||||||
|
// team
|
||||||
|
TeamID *uint
|
||||||
OnlyObserverCanRun bool
|
OnlyObserverCanRun bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user