From dc08e27e19be9e3fb6853b841a5db16449b1d789 Mon Sep 17 00:00:00 2001 From: Roman Perekhod Date: Tue, 8 Oct 2024 18:34:20 +0200 Subject: [PATCH] Kept historical resource naming after renaming in activity for shares and public links. --- .../unreleased/fix-activity-keep-naming.md | 6 +++++ .../eventsmiddleware/conversion.go | 16 +++++++++----- .../publicshareprovider.go | 22 +++++++++++-------- .../publicshareprovider_test.go | 3 +++ .../usershareprovider/usershareprovider.go | 3 +++ pkg/events/sharing.go | 21 +++++++++++++----- 6 files changed, 51 insertions(+), 20 deletions(-) create mode 100644 changelog/unreleased/fix-activity-keep-naming.md diff --git a/changelog/unreleased/fix-activity-keep-naming.md b/changelog/unreleased/fix-activity-keep-naming.md new file mode 100644 index 0000000000..2cad1b439a --- /dev/null +++ b/changelog/unreleased/fix-activity-keep-naming.md @@ -0,0 +1,6 @@ +Bugfix: Kept historical resource naming in activity + +Kept historical resource naming after renaming in activity for shares and public links. + +https://github.com/cs3org/reva/pull/4880 +https://github.com/owncloud/ocis/issues/10210 diff --git a/internal/grpc/interceptors/eventsmiddleware/conversion.go b/internal/grpc/interceptors/eventsmiddleware/conversion.go index 0bdedfe4ce..1ed9ac9299 100644 --- a/internal/grpc/interceptors/eventsmiddleware/conversion.go +++ b/internal/grpc/interceptors/eventsmiddleware/conversion.go @@ -51,6 +51,7 @@ func ShareCreated(r *collaboration.CreateShareResponse, executant *user.User) ev GranteeUserID: r.Share.GetGrantee().GetUserId(), GranteeGroupID: r.Share.GetGrantee().GetGroupId(), ItemID: r.Share.ResourceId, + ResourceName: utils.ReadPlainFromOpaque(r.Opaque, "resourcename"), CTime: r.Share.Ctime, Permissions: r.Share.Permissions, } @@ -73,6 +74,7 @@ func ShareRemoved(r *collaboration.RemoveShareResponse, req *collaboration.Remov GranteeUserID: userid, GranteeGroupID: groupid, ItemID: rid, + ResourceName: utils.ReadPlainFromOpaque(r.Opaque, "resourcename"), Timestamp: time.Now(), } } @@ -83,6 +85,7 @@ func ShareUpdated(r *collaboration.UpdateShareResponse, req *collaboration.Updat Executant: executant.GetId(), ShareID: r.Share.Id, ItemID: r.Share.ResourceId, + ResourceName: utils.ReadPlainFromOpaque(r.Opaque, "resourcename"), Permissions: r.Share.Permissions, GranteeUserID: r.Share.GetGrantee().GetUserId(), GranteeGroupID: r.Share.GetGrantee().GetGroupId(), @@ -114,6 +117,7 @@ func LinkCreated(r *link.CreatePublicShareResponse, executant *user.User) events ShareID: r.Share.Id, Sharer: r.Share.Creator, ItemID: r.Share.ResourceId, + ResourceName: utils.ReadPlainFromOpaque(r.Opaque, "resourcename"), Permissions: r.Share.Permissions, DisplayName: r.Share.DisplayName, Expiration: r.Share.Expiration, @@ -130,6 +134,7 @@ func LinkUpdated(r *link.UpdatePublicShareResponse, req *link.UpdatePublicShareR ShareID: r.Share.Id, Sharer: r.Share.Creator, ItemID: r.Share.ResourceId, + ResourceName: utils.ReadPlainFromOpaque(r.Opaque, "resourcename"), Permissions: r.Share.Permissions, DisplayName: r.Share.DisplayName, Expiration: r.Share.Expiration, @@ -177,11 +182,12 @@ func LinkRemoved(r *link.RemovePublicShareResponse, req *link.RemovePublicShareR var rid *provider.ResourceId _ = utils.ReadJSONFromOpaque(r.Opaque, "resourceid", &rid) return events.LinkRemoved{ - Executant: executant.GetId(), - ShareID: req.Ref.GetId(), - ShareToken: req.Ref.GetToken(), - Timestamp: utils.TSNow(), - ItemID: rid, + Executant: executant.GetId(), + ShareID: req.Ref.GetId(), + ShareToken: req.Ref.GetToken(), + Timestamp: utils.TSNow(), + ItemID: rid, + ResourceName: utils.ReadPlainFromOpaque(r.Opaque, "resourcename"), } } diff --git a/internal/grpc/services/publicshareprovider/publicshareprovider.go b/internal/grpc/services/publicshareprovider/publicshareprovider.go index 7876750b67..1c97430457 100644 --- a/internal/grpc/services/publicshareprovider/publicshareprovider.go +++ b/internal/grpc/services/publicshareprovider/publicshareprovider.go @@ -332,6 +332,7 @@ func (s *service) CreatePublicShare(ctx context.Context, req *link.CreatePublicS default: res.Status = status.NewOK(ctx) res.Share = share + res.Opaque = utils.AppendPlainToOpaque(nil, "resourcename", sRes.GetInfo().GetName()) } return res, nil @@ -353,15 +354,15 @@ func (s *service) RemovePublicShare(ctx context.Context, req *link.RemovePublicS Status: status.NewInternal(ctx, "error loading public share"), }, err } - if !publicshare.IsCreatedByUser(ps, user) { - sRes, err := gatewayClient.Stat(ctx, &provider.StatRequest{Ref: &provider.Reference{ResourceId: ps.ResourceId}}) - if err != nil { - log.Err(err).Interface("resource_id", ps.ResourceId).Msg("failed to stat shared resource") - return &link.RemovePublicShareResponse{ - Status: status.NewInternal(ctx, "failed to stat shared resource"), - }, err - } + sRes, err := gatewayClient.Stat(ctx, &provider.StatRequest{Ref: &provider.Reference{ResourceId: ps.ResourceId}}) + if err != nil { + log.Err(err).Interface("resource_id", ps.ResourceId).Msg("failed to stat shared resource") + return &link.RemovePublicShareResponse{ + Status: status.NewInternal(ctx, "failed to stat shared resource"), + }, err + } + if !publicshare.IsCreatedByUser(ps, user) { if !sRes.GetInfo().GetPermissionSet().RemoveGrant { return &link.RemovePublicShareResponse{ Status: status.NewPermissionDenied(ctx, nil, "no permission to delete public share"), @@ -374,8 +375,10 @@ func (s *service) RemovePublicShare(ctx context.Context, req *link.RemovePublicS Status: status.NewInternal(ctx, "error deleting public share"), }, err } + o := utils.AppendJSONToOpaque(nil, "resourceid", ps.GetResourceId()) + o = utils.AppendPlainToOpaque(o, "resourcename", sRes.GetInfo().GetName()) return &link.RemovePublicShareResponse{ - Opaque: utils.AppendJSONToOpaque(nil, "resourceid", ps.GetResourceId()), + Opaque: o, Status: status.NewOK(ctx), }, nil } @@ -603,6 +606,7 @@ func (s *service) UpdatePublicShare(ctx context.Context, req *link.UpdatePublicS res := &link.UpdatePublicShareResponse{ Status: status.NewOK(ctx), Share: updateR, + Opaque: utils.AppendPlainToOpaque(nil, "resourcename", sRes.GetInfo().GetName()), } return res, nil } diff --git a/internal/grpc/services/publicshareprovider/publicshareprovider_test.go b/internal/grpc/services/publicshareprovider/publicshareprovider_test.go index 5534b1628d..c1483332cf 100644 --- a/internal/grpc/services/publicshareprovider/publicshareprovider_test.go +++ b/internal/grpc/services/publicshareprovider/publicshareprovider_test.go @@ -763,6 +763,9 @@ var _ = Describe("PublicShareProvider", func() { Once(). Return( createdLink, nil) + + gatewayClient.EXPECT().Stat(mock.Anything, mock.Anything).Return(statResourceResponse, nil) + manager. EXPECT(). RevokePublicShare( diff --git a/internal/grpc/services/usershareprovider/usershareprovider.go b/internal/grpc/services/usershareprovider/usershareprovider.go index 60433148df..d8d52669bf 100644 --- a/internal/grpc/services/usershareprovider/usershareprovider.go +++ b/internal/grpc/services/usershareprovider/usershareprovider.go @@ -248,6 +248,7 @@ func (s *service) CreateShare(ctx context.Context, req *collaboration.CreateShar return &collaboration.CreateShareResponse{ Status: status.NewOK(ctx), Share: createdShare, + Opaque: utils.AppendPlainToOpaque(nil, "resourcename", sRes.GetInfo().GetName()), }, nil } @@ -296,6 +297,7 @@ func (s *service) RemoveShare(ctx context.Context, req *collaboration.RemoveShar } o := utils.AppendJSONToOpaque(nil, "resourceid", share.GetResourceId()) + o = utils.AppendPlainToOpaque(o, "resourcename", sRes.GetInfo().GetName()) if user := share.GetGrantee().GetUserId(); user != nil { o = utils.AppendJSONToOpaque(o, "granteeuserid", user) } else { @@ -447,6 +449,7 @@ func (s *service) UpdateShare(ctx context.Context, req *collaboration.UpdateShar res := &collaboration.UpdateShareResponse{ Status: status.NewOK(ctx), Share: share, + Opaque: utils.AppendPlainToOpaque(nil, "resourcename", sRes.GetInfo().GetName()), } return res, nil } diff --git a/pkg/events/sharing.go b/pkg/events/sharing.go index daa13ad11b..f6bc215ea0 100644 --- a/pkg/events/sharing.go +++ b/pkg/events/sharing.go @@ -41,6 +41,7 @@ type ShareCreated struct { GranteeGroupID *group.GroupId Sharee *provider.Grantee ItemID *provider.ResourceId + ResourceName string Permissions *collaboration.SharePermissions CTime *types.Timestamp } @@ -62,8 +63,9 @@ type ShareRemoved struct { GranteeUserID *user.UserId GranteeGroupID *group.GroupId - ItemID *provider.ResourceId - Timestamp time.Time + ItemID *provider.ResourceId + ResourceName string + Timestamp time.Time } // Unmarshal to fulfill umarshaller interface @@ -78,6 +80,7 @@ type ShareUpdated struct { Executant *user.UserId ShareID *collaboration.ShareId ItemID *provider.ResourceId + ResourceName string Permissions *collaboration.SharePermissions GranteeUserID *user.UserId GranteeGroupID *group.GroupId @@ -101,6 +104,7 @@ type ShareExpired struct { ShareID *collaboration.ShareId ShareOwner *user.UserId ItemID *provider.ResourceId + Path string ExpiredAt time.Time // split the protobuf Grantee oneof so we can use stdlib encoding/json GranteeUserID *user.UserId @@ -119,6 +123,7 @@ type ReceivedShareUpdated struct { Executant *user.UserId ShareID *collaboration.ShareId ItemID *provider.ResourceId + Path string Permissions *collaboration.SharePermissions GranteeUserID *user.UserId GranteeGroupID *group.GroupId @@ -141,6 +146,7 @@ type LinkCreated struct { ShareID *link.PublicShareId Sharer *user.UserId ItemID *provider.ResourceId + ResourceName string Permissions *link.PublicSharePermissions DisplayName string Expiration *types.Timestamp @@ -162,6 +168,7 @@ type LinkUpdated struct { ShareID *link.PublicShareId Sharer *user.UserId ItemID *provider.ResourceId + ResourceName string Permissions *link.PublicSharePermissions DisplayName string Expiration *types.Timestamp @@ -185,6 +192,7 @@ type LinkAccessed struct { ShareID *link.PublicShareId Sharer *user.UserId ItemID *provider.ResourceId + Path string Permissions *link.PublicSharePermissions DisplayName string Expiration *types.Timestamp @@ -221,10 +229,11 @@ func (LinkAccessFailed) Unmarshal(v []byte) (interface{}, error) { type LinkRemoved struct { Executant *user.UserId // split protobuf Ref - ShareID *link.PublicShareId - ShareToken string - Timestamp *types.Timestamp - ItemID *provider.ResourceId + ShareID *link.PublicShareId + ShareToken string + Timestamp *types.Timestamp + ItemID *provider.ResourceId + ResourceName string } // Unmarshal to fulfill umarshaller interface