diff --git a/services/activitylog/pkg/service/http.go b/services/activitylog/pkg/service/http.go index 91554b11d..9dea4f27a 100644 --- a/services/activitylog/pkg/service/http.go +++ b/services/activitylog/pkg/service/http.go @@ -116,7 +116,7 @@ func (s *ActivitylogService) HandleGetItemActivities(w http.ResponseWriter, r *h case events.ItemTrashed: message = MessageResourceTrashed ts = utils.TSToTime(ev.Timestamp) - vars, err = s.GetVars(WithResource(ev.Ref, true), WithUser(ev.Executant, "")) + vars, err = s.GetVars(WithTrashedResource(ev.Ref, ev.ID), WithUser(ev.Executant, ""), WithSpace(toSpace(ev.Ref))) case events.ItemMoved: switch isRename(ev.OldReference, ev.Ref) { case true: diff --git a/services/activitylog/pkg/service/response.go b/services/activitylog/pkg/service/response.go index f5ec0f4ad..54ad2f4cf 100644 --- a/services/activitylog/pkg/service/response.go +++ b/services/activitylog/pkg/service/response.go @@ -87,6 +87,35 @@ func WithOldResource(ref *provider.Reference) ActivityOption { } } +// WithTrashedResource sets the resource variable if the resource is trashed +func WithTrashedResource(ref *provider.Reference, rid *provider.ResourceId) ActivityOption { + return func(ctx context.Context, gwc gateway.GatewayAPIClient, vars map[string]interface{}) error { + resp, err := gwc.ListRecycle(ctx, &provider.ListRecycleRequest{ + Ref: ref, + }) + if err != nil { + return err + } + if resp.GetStatus().GetCode() != rpc.Code_CODE_OK { + return fmt.Errorf("error listing recycle: %s", resp.GetStatus().GetMessage()) + } + + for _, item := range resp.GetRecycleItems() { + if item.GetKey() == rid.GetOpaqueId() { + + vars["resource"] = Resource{ + ID: storagespace.FormatResourceID(*rid), + Name: filepath.Base(item.GetRef().GetPath()), + } + + return nil + } + } + + return nil + } +} + // WithUser sets the user variable for an Activity func WithUser(uid *user.UserId, username string) ActivityOption { return func(_ context.Context, gwc gateway.GatewayAPIClient, vars map[string]interface{}) error { diff --git a/services/activitylog/pkg/service/service.go b/services/activitylog/pkg/service/service.go index 32429778e..7b4cfd3a4 100644 --- a/services/activitylog/pkg/service/service.go +++ b/services/activitylog/pkg/service/service.go @@ -291,3 +291,9 @@ func toRef(r *provider.ResourceId) *provider.Reference { ResourceId: r, } } + +func toSpace(r *provider.Reference) *provider.StorageSpaceId { + return &provider.StorageSpaceId{ + OpaqueId: storagespace.FormatStorageID(r.GetResourceId().GetStorageId(), r.GetResourceId().GetSpaceId()), + } +}