move context out of controller struct
@@ -29,31 +29,25 @@ var updateFields = []string{
type CheckActions struct {
Store store.CheckConfigStore
Policy authorization.CheckPolicy
- Context context.Context
}
// NewCheckActions returns new CheckActions
-func NewCheckActions(ctx context.Context, store store.CheckConfigStore) CheckActions {
- return CheckActions{Store: store}.WithContext(ctx)
+func NewCheckActions(store store.CheckConfigStore) CheckActions {
+ return CheckActions{
+ Store: store,
+ Policy: authorization.Checks,
}
-
-// WithContext returns new CheckActions w/ context & policy configured.
-func (a CheckActions) WithContext(ctx context.Context) CheckActions {
- if ctx != nil {
- a.Policy = a.Policy.WithContext(ctx)
- a.Context = ctx
- }
- return a
}
// Query returns resources available to the viewer filter by given params.
-func (a CheckActions) Query(params QueryParams) ([]interface{}, error) {
- if yes := a.Policy.CanList(); !yes {
+func (a CheckActions) Query(ctx context.Context, params QueryParams) ([]interface{}, error) {
+ abilities := a.Policy.WithContext(ctx)
+ if yes := abilities.CanList(); !yes {
return nil, NewErrorf(PermissionDenied, "cannot list resources")
}
// Fetch from store
- results, serr := a.Store.GetCheckConfigs(a.Context)
+ results, serr := a.Store.GetCheckConfigs(ctx)
if serr != nil {
return nil, NewError(InternalErr, serr)
}
