Some checks failed
SonarQube / SonarQube (push) Failing after 5m28s
E2e test on main branch push / server and client test (map[name:admin port:8080]) (push) Failing after 3m33s
Server and lib tests / Library test (js) (push) Failing after 1m36s
Server and lib tests / Library test (vue) (push) Successful in 2m24s
Server and lib tests / Web client test (admin) (push) Successful in 2m52s
Server and lib tests / Web client test (compose) (push) Successful in 3m23s
Server and lib tests / Web client test (discovery) (push) Successful in 2m49s
Server and lib tests / Web client test (one) (push) Successful in 2m52s
Server and lib tests / Web client test (privacy) (push) Successful in 2m44s
Server and lib tests / Web client test (reporter) (push) Successful in 2m56s
Server and lib tests / Web client test (workflow) (push) Successful in 3m0s
Server and lib tests / Server tests (push) Failing after 4m55s
E2e test on main branch push / notify-failure (push) Failing after 9s
Server and lib tests / Send matrix testing notification (push) Successful in 2s
Mark stale issues and pull requests / stale (push) Successful in 40s
106 lines
2.2 KiB
Go
106 lines
2.2 KiB
Go
package feed
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
"github.com/cortezaproject/corteza/server/discovery/service"
|
|
"github.com/cortezaproject/corteza/server/discovery/types"
|
|
"github.com/cortezaproject/corteza/server/pkg/errors"
|
|
"github.com/cortezaproject/corteza/server/pkg/filter"
|
|
"github.com/cortezaproject/corteza/server/pkg/options"
|
|
|
|
"github.com/cortezaproject/corteza/server/pkg/rbac"
|
|
)
|
|
|
|
type (
|
|
resourceActivity struct {
|
|
opt options.DiscoveryOpt
|
|
|
|
rbac interface {
|
|
SignificantRoles(res rbac.Resource, op string) (aRR, dRR []uint64)
|
|
}
|
|
|
|
ac interface {
|
|
}
|
|
|
|
resActivity service.ResourceActivityService
|
|
}
|
|
)
|
|
|
|
func ResourceActivity() *resourceActivity {
|
|
return &resourceActivity{
|
|
opt: service.DefaultOption,
|
|
rbac: rbac.Global(),
|
|
resActivity: service.DefaultResourceActivity,
|
|
}
|
|
}
|
|
|
|
func (a resourceActivity) ResourceActivities(ctx context.Context, limit uint, cur string, from *time.Time, to *time.Time) (rsp *Response, err error) {
|
|
return rsp, func() (err error) {
|
|
var (
|
|
aa types.ResourceActivitySet
|
|
|
|
f = types.ResourceActivityFilter{}
|
|
)
|
|
|
|
if from == nil || from.IsZero() {
|
|
return errors.Internal("invalid or missing from timestamp")
|
|
}
|
|
|
|
if to == nil || to.IsZero() {
|
|
now := time.Now()
|
|
to = &now
|
|
}
|
|
|
|
if from.After(*to) {
|
|
return errors.Internal("invalid from timestamp, it must be before to timestamp")
|
|
}
|
|
|
|
// Ensure both 'from' and 'to' are in UTC
|
|
utcFrom := from.UTC()
|
|
utcTo := to.UTC()
|
|
|
|
from = &utcFrom
|
|
to = &utcTo
|
|
|
|
f.FromTimestamp = from
|
|
f.ToTimestamp = to
|
|
|
|
if f.Paging, err = filter.NewPaging(limit, cur); err != nil {
|
|
return err
|
|
}
|
|
|
|
if aa, f, err = a.resActivity.Find(ctx, f); err != nil {
|
|
return err
|
|
}
|
|
|
|
rsp = &Response{
|
|
ActivityLogs: make([]ActivityLog, 0),
|
|
Filter: Filter{
|
|
Limit: limit,
|
|
NextPage: f.NextPage,
|
|
},
|
|
}
|
|
|
|
err = aa.Walk(func(a *types.ResourceActivity) error {
|
|
rsp.ActivityLogs = append(rsp.ActivityLogs, ActivityLog{
|
|
ID: a.ID,
|
|
ResourceID: a.ResourceID,
|
|
ResourceType: a.ResourceType,
|
|
ResourceAction: a.ResourceAction,
|
|
Timestamp: a.Timestamp,
|
|
Meta: a.Meta,
|
|
})
|
|
|
|
return nil
|
|
})
|
|
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}()
|
|
}
|