fix(activitylog): Add fallback for folder names

(cherry picked from commit b8e8d15439)
This commit is contained in:
Bastian Beier authored and Roman Perekhod committed 2025-01-27 17:46:32 +01:00
1 parent 63c0abe910
commit 6874e577cb
3 files changed
+28 -12

No files matched your search

@@ -0,0 +1,6 @@
Bugfix: Add fallback for folder names
Add translated `shared-with-me` fallback for folder names in the activitylog to avoid `{folder}` in the output.
https://github.com/owncloud/ocis/pull/10932
https://github.com/owncloud/ocis/issues/10906
+17 -11
View File
@@ -137,19 +137,23 @@ func (s *ActivitylogService) HandleGetItemActivities(w http.ResponseWriter, r *h
message = MessageResourceUpdated
}
ts = utils.TSToTime(ev.Timestamp)
vars, err = s.GetVars(ctx, WithResource(ev.FileRef, false, ""), WithUser(nil, ev.ExecutingUser, ev.ImpersonatingUser))
vars, err = s.GetVars(ctx, WithResource(ev.FileRef, false, "", &t, loc),
WithUser(nil, ev.ExecutingUser, ev.ImpersonatingUser))
case events.FileTouched:
message = MessageResourceCreated
ts = utils.TSToTime(ev.Timestamp)
vars, err = s.GetVars(ctx, WithResource(ev.Ref, false, ""), WithUser(ev.Executant, nil, ev.ImpersonatingUser))
vars, err = s.GetVars(ctx, WithResource(ev.Ref, false, "", &t, loc),
WithUser(ev.Executant, nil, ev.ImpersonatingUser))
case events.FileDownloaded:
message = MessageResourceDownloaded
ts = utils.TSToTime(ev.Timestamp)
vars, err = s.GetVars(ctx, WithResource(ev.Ref, false, ""), WithUser(ev.Executant, nil, ev.ImpersonatingUser), WithVar("token", "", ev.ImpersonatingUser.GetId().GetOpaqueId()))
vars, err = s.GetVars(ctx, WithResource(ev.Ref, false, "", &t, loc),
WithUser(ev.Executant, nil, ev.ImpersonatingUser), WithVar("token", "", ev.ImpersonatingUser.GetId().GetOpaqueId()))
case events.ContainerCreated:
message = MessageResourceCreated
ts = utils.TSToTime(ev.Timestamp)
vars, err = s.GetVars(ctx, WithResource(ev.Ref, false, ""), WithUser(ev.Executant, nil, ev.ImpersonatingUser))
vars, err = s.GetVars(ctx, WithResource(ev.Ref, false, "", &t, loc),
WithUser(ev.Executant, nil, ev.ImpersonatingUser))
case events.ItemTrashed:
message = MessageResourceTrashed
ts = utils.TSToTime(ev.Timestamp)
@@ -158,17 +162,19 @@ func (s *ActivitylogService) HandleGetItemActivities(w http.ResponseWriter, r *h
switch isRename(ev.OldReference, ev.Ref) {
case true:
message = MessageResourceRenamed
vars, err = s.GetVars(ctx, WithResource(ev.Ref, false, ""), WithOldResource(ev.OldReference), WithUser(ev.Executant, nil, ev.ImpersonatingUser))
vars, err = s.GetVars(ctx, WithResource(ev.Ref, false, "", &t, loc),
WithOldResource(ev.OldReference), WithUser(ev.Executant, nil, ev.ImpersonatingUser))
case false:
message = MessageResourceMoved
vars, err = s.GetVars(ctx, WithResource(ev.Ref, false, ""), WithUser(ev.Executant, nil, ev.ImpersonatingUser))
vars, err = s.GetVars(ctx, WithResource(ev.Ref, false, "", &t, loc),
WithUser(ev.Executant, nil, ev.ImpersonatingUser))
}
ts = utils.TSToTime(ev.Timestamp)
case events.ShareCreated:
message = MessageShareCreated
ts = utils.TSToTime(ev.CTime)
vars, err = s.GetVars(ctx,
WithResource(toRef(ev.ItemID), false, ev.ResourceName),
WithResource(toRef(ev.ItemID), false, ev.ResourceName, &t, loc),
WithUser(ev.Executant, nil, nil),
WithSharee(ev.GranteeUserID, ev.GranteeGroupID))
case events.ShareUpdated:
@@ -178,21 +184,21 @@ func (s *ActivitylogService) HandleGetItemActivities(w http.ResponseWriter, r *h
message = MessageShareUpdated
ts = utils.TSToTime(ev.MTime)
vars, err = s.GetVars(ctx,
WithResource(toRef(ev.ItemID), false, ev.ResourceName),
WithResource(toRef(ev.ItemID), false, ev.ResourceName, &t, loc),
WithUser(ev.Executant, nil, nil),
WithTranslation(&t, loc, "field", ev.UpdateMask))
case events.ShareRemoved:
message = MessageShareDeleted
ts = ev.Timestamp
vars, err = s.GetVars(ctx,
WithResource(toRef(ev.ItemID), false, ev.ResourceName),
WithResource(toRef(ev.ItemID), false, ev.ResourceName, &t, loc),
WithUser(ev.Executant, nil, nil),
WithSharee(ev.GranteeUserID, ev.GranteeGroupID))
case events.LinkCreated:
message = MessageLinkCreated
ts = utils.TSToTime(ev.CTime)
vars, err = s.GetVars(ctx,
WithResource(toRef(ev.ItemID), false, ev.ResourceName),
WithResource(toRef(ev.ItemID), false, ev.ResourceName, &t, loc),
WithUser(ev.Executant, nil, nil))
case events.LinkUpdated:
if ev.Sharer != nil && ev.ItemID != nil && ev.Sharer.GetOpaqueId() == ev.ItemID.GetSpaceId() {
@@ -208,7 +214,7 @@ func (s *ActivitylogService) HandleGetItemActivities(w http.ResponseWriter, r *h
case events.LinkRemoved:
message = MessageLinkDeleted
ts = utils.TSToTime(ev.Timestamp)
vars, err = s.GetVars(ctx, WithResource(toRef(ev.ItemID), false, ""), WithUser(ev.Executant, nil, nil))
vars, err = s.GetVars(ctx, WithResource(toRef(ev.ItemID), false, "", &t, loc), WithUser(ev.Executant, nil, nil))
case events.SpaceShared:
message = MessageSpaceShared
ts = ev.Timestamp
+5 -1
View File
@@ -42,6 +42,7 @@ var (
StrExpirationDate = l10n.Template("expiration date")
StrDisplayName = l10n.Template("display name")
StrDescription = l10n.Template("description")
StrFallbackFolder = l10n.Template("shared-with-me")
)
// GetActivitiesResponse is the response on GET activities requests
@@ -65,7 +66,7 @@ type Actor struct {
type ActivityOption func(context.Context, gateway.GatewayAPIClient, map[string]interface{}) error
// WithResource sets the resource variable for an activity
func WithResource(ref *provider.Reference, addSpace bool, explicitResourceName string) ActivityOption {
func WithResource(ref *provider.Reference, addSpace bool, explicitResourceName string, t *l10n.Translator, locale string) ActivityOption {
return func(ctx context.Context, gwc gateway.GatewayAPIClient, vars map[string]interface{}) error {
info, err := utils.GetResource(ctx, ref, gwc)
if err != nil {
@@ -99,6 +100,9 @@ func WithResource(ref *provider.Reference, addSpace bool, explicitResourceName s
parent, err := utils.GetResourceByID(ctx, info.GetParentId(), gwc)
if err != nil {
vars["folder"] = Resource{
Name: t.Translate(StrFallbackFolder, locale),
}
return err
}
vars["folder"] = Resource{