Fix setting observer_can_run in query API (#823)

Previous work in #777 added the datastore and model layers, but didn't
handle setting this value in the service and transport.

Fixes #822
This commit is contained in:
Zach Wasserman 2021-05-20 10:28:55 -07:00 committed by GitHub
parent 83b7f79699
commit 82fe7c0035
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 3 deletions

View file

@ -61,9 +61,10 @@ type QueryService interface {
}
type QueryPayload struct {
Name *string
Description *string
Query *string
Name *string
Description *string
Query *string
ObserverCanRun *bool `json:"observer_can_run"`
}
type Query struct {

View file

@ -89,6 +89,10 @@ func (svc service) NewQuery(ctx context.Context, p kolide.QueryPayload) (*kolide
query.Query = *p.Query
}
if p.ObserverCanRun != nil {
query.ObserverCanRun = *p.ObserverCanRun
}
vc, ok := viewer.FromContext(ctx)
if ok {
query.AuthorID = uintPtr(vc.UserID())
@ -125,6 +129,10 @@ func (svc service) ModifyQuery(ctx context.Context, id uint, p kolide.QueryPaylo
query.Query = *p.Query
}
if p.ObserverCanRun != nil {
query.ObserverCanRun = *p.ObserverCanRun
}
if err := query.ValidateSQL(); err != nil {
return nil, err
}