Skip to content

Commit

Permalink
Kept historical resource naming after renaming in activity for shares…
Browse files Browse the repository at this point in the history
… and public links.
  • Loading branch information
2403905 committed Oct 8, 2024
1 parent ba9db87 commit 7c2488f
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 9 deletions.
6 changes: 6 additions & 0 deletions changelog/unreleased/fix-activity-rename.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
6 changes: 6 additions & 0 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,
Path: utils.ReadPlainFromOpaque(r.Opaque, "path"),
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,
Path: utils.ReadPlainFromOpaque(r.Opaque, "path"),
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,
Path: utils.ReadPlainFromOpaque(r.Opaque, "path"),
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,
Path: utils.ReadPlainFromOpaque(r.Opaque, "path"),
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,
Path: utils.ReadPlainFromOpaque(r.Opaque, "path"),
Permissions: r.Share.Permissions,
DisplayName: r.Share.DisplayName,
Expiration: r.Share.Expiration,
Expand Down Expand Up @@ -182,6 +187,7 @@ func LinkRemoved(r *link.RemovePublicShareResponse, req *link.RemovePublicShareR
ShareToken: req.Ref.GetToken(),
Timestamp: utils.TSNow(),
ItemID: rid,
Path: utils.ReadPlainFromOpaque(r.Opaque, "path"),
}
}

Expand Down
22 changes: 13 additions & 9 deletions internal/grpc/services/publicshareprovider/publicshareprovider.go
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, "path", sRes.GetInfo().GetPath())
}

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, "path", sRes.GetInfo().GetPath())
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, "path", sRes.GetInfo().GetPath()),
}
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
3 changes: 3 additions & 0 deletions internal/grpc/services/usershareprovider/usershareprovider.go
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, "path", sRes.GetInfo().GetPath()),
}, 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, "path", sRes.GetInfo().GetPath())
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, "path", sRes.GetInfo().GetPath()),
}
return res, nil
}
Expand Down
9 changes: 9 additions & 0 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
Path string
Permissions *collaboration.SharePermissions
CTime *types.Timestamp
}
Expand All @@ -63,6 +64,7 @@ type ShareRemoved struct {
GranteeGroupID *group.GroupId

ItemID *provider.ResourceId
Path string
Timestamp time.Time
}

Expand All @@ -78,6 +80,7 @@ type ShareUpdated struct {
Executant *user.UserId
ShareID *collaboration.ShareId
ItemID *provider.ResourceId
Path 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
Path 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
Path 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 @@ -225,6 +233,7 @@ type LinkRemoved struct {
ShareToken string
Timestamp *types.Timestamp
ItemID *provider.ResourceId
Path string
}

// Unmarshal to fulfill umarshaller interface
Expand Down

0 comments on commit 7c2488f

Please sign in to comment.