2021-11-29 13:12:22 +00:00
|
|
|
package service
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
|
|
|
"github.com/fleetdm/fleet/v4/server/fleet"
|
|
|
|
)
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Get activities
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
type listActivitiesRequest struct {
|
|
|
|
ListOptions fleet.ListOptions `url:"list_options"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type listActivitiesResponse struct {
|
2023-01-18 12:57:11 +00:00
|
|
|
Meta *fleet.PaginationMetadata `json:"meta"`
|
|
|
|
Activities []*fleet.Activity `json:"activities"`
|
|
|
|
Err error `json:"error,omitempty"`
|
2021-11-29 13:12:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (r listActivitiesResponse) error() error { return r.Err }
|
|
|
|
|
2022-12-27 14:26:59 +00:00
|
|
|
func listActivitiesEndpoint(ctx context.Context, request interface{}, svc fleet.Service) (errorer, error) {
|
2021-11-29 13:12:22 +00:00
|
|
|
req := request.(*listActivitiesRequest)
|
2023-01-18 12:57:11 +00:00
|
|
|
activities, metadata, err := svc.ListActivities(ctx, fleet.ListActivitiesOptions{
|
2022-12-23 22:04:13 +00:00
|
|
|
ListOptions: req.ListOptions,
|
|
|
|
})
|
2021-11-29 13:12:22 +00:00
|
|
|
if err != nil {
|
|
|
|
return listActivitiesResponse{Err: err}, nil
|
|
|
|
}
|
|
|
|
|
2023-01-18 12:57:11 +00:00
|
|
|
return listActivitiesResponse{Meta: metadata, Activities: activities}, nil
|
2021-11-29 13:12:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ListActivities returns a slice of activities for the whole organization
|
2023-01-18 12:57:11 +00:00
|
|
|
func (svc *Service) ListActivities(ctx context.Context, opt fleet.ListActivitiesOptions) ([]*fleet.Activity, *fleet.PaginationMetadata, error) {
|
2021-11-29 13:12:22 +00:00
|
|
|
if err := svc.authz.Authorize(ctx, &fleet.Activity{}, fleet.ActionRead); err != nil {
|
2023-01-18 12:57:11 +00:00
|
|
|
return nil, nil, err
|
2021-11-29 13:12:22 +00:00
|
|
|
}
|
|
|
|
return svc.ds.ListActivities(ctx, opt)
|
|
|
|
}
|
2022-12-21 17:30:19 +00:00
|
|
|
|
2023-01-20 15:43:22 +00:00
|
|
|
func (svc *Service) NewActivity(ctx context.Context, user *fleet.User, activity fleet.ActivityDetails) error {
|
|
|
|
return svc.ds.NewActivity(ctx, user, activity)
|
|
|
|
}
|