Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kept historical resource naming after renaming in activity for shares and public links. #4880

Merged
merged 1 commit into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions changelog/unreleased/fix-activity-keep-naming.md
Original file line number Diff line number Diff line change
@@ -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
16 changes: 11 additions & 5 deletions internal/grpc/interceptors/eventsmiddleware/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand All @@ -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(),
}
}
Expand All @@ -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(),
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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"),
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"),
Expand All @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
Expand Down
21 changes: 15 additions & 6 deletions pkg/events/sharing.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ type ShareCreated struct {
GranteeGroupID *group.GroupId
Sharee *provider.Grantee
ItemID *provider.ResourceId
ResourceName string
Permissions *collaboration.SharePermissions
CTime *types.Timestamp
}
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
Loading