Skip to content

Commit

Permalink
feat(activitylog): repair trash events
Browse files Browse the repository at this point in the history
Signed-off-by: jkoberg <[email protected]>
  • Loading branch information
kobergj committed Jun 21, 2024
1 parent ba85271 commit fddc2e0
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
2 changes: 1 addition & 1 deletion services/activitylog/pkg/service/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
29 changes: 29 additions & 0 deletions services/activitylog/pkg/service/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 6 additions & 0 deletions services/activitylog/pkg/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
}
}

0 comments on commit fddc2e0

Please sign in to comment.