From 4f0e02f3915f6fc0ea4b7047599cd887041664c8 Mon Sep 17 00:00:00 2001 From: jkoberg Date: Tue, 25 Jun 2024 16:20:20 +0200 Subject: [PATCH] fix(activitylog): multiple minor bugfixes Signed-off-by: jkoberg --- changelog/unreleased/activitylog-fixes.md | 5 +++++ services/activitylog/pkg/command/server.go | 1 + services/activitylog/pkg/service/http.go | 7 ++++++- services/activitylog/pkg/service/response.go | 5 ++++- services/activitylog/pkg/service/service.go | 10 ++++++++++ 5 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 changelog/unreleased/activitylog-fixes.md diff --git a/changelog/unreleased/activitylog-fixes.md b/changelog/unreleased/activitylog-fixes.md new file mode 100644 index 00000000000..c2e509d37bc --- /dev/null +++ b/changelog/unreleased/activitylog-fixes.md @@ -0,0 +1,5 @@ +Enhancement: Various fixes for the activitylog service + +First round of fixes to make the activitylog service more robust and reliable. + +https://github.com/owncloud/ocis/pull/9467 diff --git a/services/activitylog/pkg/command/server.go b/services/activitylog/pkg/command/server.go index 4ed99d10bc1..e6854065c8b 100644 --- a/services/activitylog/pkg/command/server.go +++ b/services/activitylog/pkg/command/server.go @@ -33,6 +33,7 @@ var _registeredEvents = []events.Unmarshaller{ events.FileTouched{}, events.ContainerCreated{}, events.ItemTrashed{}, + events.ItemPurged{}, events.ItemMoved{}, events.ShareCreated{}, events.ShareRemoved{}, diff --git a/services/activitylog/pkg/service/http.go b/services/activitylog/pkg/service/http.go index 1fbd2fb53d6..9c2388f9fe9 100644 --- a/services/activitylog/pkg/service/http.go +++ b/services/activitylog/pkg/service/http.go @@ -17,6 +17,7 @@ import ( "github.com/cs3org/reva/v2/pkg/utils" "google.golang.org/grpc/metadata" + libregraph "github.com/owncloud/libre-graph-api-go" "github.com/owncloud/ocis/v2/ocis-pkg/ast" "github.com/owncloud/ocis/v2/ocis-pkg/kql" "github.com/owncloud/ocis/v2/ocis-pkg/l10n" @@ -83,7 +84,7 @@ func (s *ActivitylogService) HandleGetItemActivities(w http.ResponseWriter, r *h return } - var resp GetActivitiesResponse + resp := GetActivitiesResponse{Activities: make([]libregraph.Activity, 0, len(evRes.GetEvents()))} for _, e := range evRes.GetEvents() { delete(toDelete, e.GetId()) @@ -269,6 +270,10 @@ func (s *ActivitylogService) getFilters(query string) (*provider.ResourceId, int if err != nil { return nil, limit, nil, nil, err } + if rid.GetOpaqueId() == "" { + // space root requested - fix format + rid.OpaqueId = rid.GetSpaceId() + } pref := func(a RawActivity) bool { for _, f := range prefilters { if !f(a) { diff --git a/services/activitylog/pkg/service/response.go b/services/activitylog/pkg/service/response.go index 9a9d710bc2c..0c04a6ba4c7 100644 --- a/services/activitylog/pkg/service/response.go +++ b/services/activitylog/pkg/service/response.go @@ -57,6 +57,9 @@ func WithResource(ref *provider.Reference, addSpace bool) ActivityOption { return func(ctx context.Context, gwc gateway.GatewayAPIClient, vars map[string]interface{}) error { info, err := utils.GetResource(ctx, ref, gwc) if err != nil { + vars["resource"] = Resource{ + Name: filepath.Base(ref.GetPath()), + } return err } @@ -209,7 +212,7 @@ func (s *ActivitylogService) GetVars(ctx context.Context, opts ...ActivityOption vars := make(map[string]interface{}) for _, opt := range opts { if err := opt(ctx, gwc, vars); err != nil { - return nil, err + s.log.Info().Err(err).Msg("error getting activity vars") } } diff --git a/services/activitylog/pkg/service/service.go b/services/activitylog/pkg/service/service.go index 2653bd434ba..930156b67eb 100644 --- a/services/activitylog/pkg/service/service.go +++ b/services/activitylog/pkg/service/service.go @@ -104,6 +104,8 @@ func (a *ActivitylogService) Run() { err = a.AddActivity(ev.Ref, e.ID, utils.TSToTime(ev.Timestamp)) case events.ItemTrashed: err = a.AddActivityTrashed(ev.ID, ev.Ref, e.ID, utils.TSToTime(ev.Timestamp)) + case events.ItemPurged: + err = a.RemoveResource(ev.ID) case events.ItemMoved: err = a.AddActivity(ev.Ref, e.ID, utils.TSToTime(ev.Timestamp)) case events.ShareCreated: @@ -221,6 +223,14 @@ func (a *ActivitylogService) RemoveActivities(rid *provider.ResourceId, toDelete }) } +// RemoveResource removes the resource from the store +func (a *ActivitylogService) RemoveResource(rid *provider.ResourceId) error { + a.lock.Lock() + defer a.lock.Unlock() + + return a.store.Delete(storagespace.FormatResourceID(*rid)) +} + func (a *ActivitylogService) activities(rid *provider.ResourceId) ([]RawActivity, error) { resourceID := storagespace.FormatResourceID(*rid)