mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-02-22 13:39:24 -06:00
feat(activitylog): repair trash events
Signed-off-by: jkoberg <jkoberg@owncloud.com>
This commit is contained in:
@@ -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:
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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()),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user