From 43df861b670a43bd82658df6ae6cf32437ed20c7 Mon Sep 17 00:00:00 2001 From: jkoberg Date: Thu, 27 Jun 2024 14:18:02 +0200 Subject: [PATCH] fix(activitylog): add space even if resource got deleted Signed-off-by: jkoberg --- changelog/unreleased/activitylog-fixes.md | 1 + services/activitylog/pkg/service/http.go | 8 ++++---- services/activitylog/pkg/service/response.go | 5 +++++ 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/changelog/unreleased/activitylog-fixes.md b/changelog/unreleased/activitylog-fixes.md index c2e509d37bc..15c9bb6b583 100644 --- a/changelog/unreleased/activitylog-fixes.md +++ b/changelog/unreleased/activitylog-fixes.md @@ -2,4 +2,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/9485 https://github.com/owncloud/ocis/pull/9467 diff --git a/services/activitylog/pkg/service/http.go b/services/activitylog/pkg/service/http.go index af203113eea..d47e2e71811 100644 --- a/services/activitylog/pkg/service/http.go +++ b/services/activitylog/pkg/service/http.go @@ -110,15 +110,15 @@ func (s *ActivitylogService) HandleGetItemActivities(w http.ResponseWriter, r *h case events.UploadReady: message = MessageResourceCreated ts = utils.TSToTime(ev.Timestamp) - vars, err = s.GetVars(ctx, WithResource(ev.FileRef, true), WithUser(ev.ExecutingUser.GetId(), ev.ExecutingUser.GetDisplayName())) + vars, err = s.GetVars(ctx, WithResource(ev.FileRef, true), WithUser(ev.ExecutingUser.GetId(), ev.ExecutingUser.GetDisplayName()), WithSpace(toSpace(ev.FileRef))) case events.FileTouched: message = MessageResourceCreated ts = utils.TSToTime(ev.Timestamp) - vars, err = s.GetVars(ctx, WithResource(ev.Ref, true), WithUser(ev.Executant, "")) + vars, err = s.GetVars(ctx, WithResource(ev.Ref, true), WithUser(ev.Executant, ""), WithSpace(toSpace(ev.Ref))) case events.ContainerCreated: message = MessageResourceCreated ts = utils.TSToTime(ev.Timestamp) - vars, err = s.GetVars(ctx, WithResource(ev.Ref, true), WithUser(ev.Executant, "")) + vars, err = s.GetVars(ctx, WithResource(ev.Ref, true), WithUser(ev.Executant, ""), WithSpace(toSpace(ev.Ref))) case events.ItemTrashed: message = MessageResourceTrashed ts = utils.TSToTime(ev.Timestamp) @@ -130,7 +130,7 @@ func (s *ActivitylogService) HandleGetItemActivities(w http.ResponseWriter, r *h vars, err = s.GetVars(ctx, WithResource(ev.Ref, false), WithOldResource(ev.OldReference), WithUser(ev.Executant, "")) case false: message = MessageResourceMoved - vars, err = s.GetVars(ctx, WithResource(ev.Ref, true), WithUser(ev.Executant, "")) + vars, err = s.GetVars(ctx, WithResource(ev.Ref, true), WithUser(ev.Executant, ""), WithSpace(toSpace(ev.Ref))) } ts = utils.TSToTime(ev.Timestamp) case events.ShareCreated: diff --git a/services/activitylog/pkg/service/response.go b/services/activitylog/pkg/service/response.go index 4d60b822577..95944191bc0 100644 --- a/services/activitylog/pkg/service/response.go +++ b/services/activitylog/pkg/service/response.go @@ -192,6 +192,11 @@ func WithSharee(uid *user.UserId, gid *group.GroupId) ActivityOption { // WithSpace sets the space variable for an activity func WithSpace(spaceid *provider.StorageSpaceId) ActivityOption { return func(ctx context.Context, gwc gateway.GatewayAPIClient, vars map[string]interface{}) error { + if _, ok := vars["space"]; ok { + // do not override space if already set + return nil + } + s, err := utils.GetSpace(ctx, spaceid.GetOpaqueId(), gwc) if err != nil { vars["space"] = Resource{