Skip to content

Commit

Permalink
update grants in the storage provider on share update
Browse files Browse the repository at this point in the history
Signed-off-by: David Christofas <dchristofas@owncloud.com>
  • Loading branch information
David Christofas committed Oct 20, 2020
1 parent e221f0b commit 40db8d2
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 37 deletions.
5 changes: 5 additions & 0 deletions changelog/unreleased/update-grants-on-share-update.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Bugfix: update share grants on share update

When a share was updated the share information in the share manager was updated but the grants set by the storage provider were not.

https://github.com/cs3org/reva/pull/1258
93 changes: 56 additions & 37 deletions internal/grpc/services/gateway/usershareprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,46 +186,31 @@ func (s *svc) UpdateShare(ctx context.Context, req *collaboration.UpdateShareReq
}

// TODO(labkode): if both commits are enabled they could be done concurrently.
/*
if s.c.CommitShareToStorageGrant {
getShareReq := &collaboration.GetShareRequest{
Ref: req.Ref,
}
getShareRes, err := c.GetShare(ctx, getShareReq)
if err != nil {
return nil, errors.Wrap(err, "gateway: error calling GetShare")
}

if getShareRes.Status.Code != rpc.Code_CODE_OK {
return &collaboration.UpdateShareResponse{
Status: status.NewInternal(ctx, status.NewErrorFromCode(getShareRes.Status.Code, "gateway"),
"error getting share when committing to the share"),
}, nil
}
if s.c.CommitShareToStorageGrant {
getShareReq := &collaboration.GetShareRequest{
Ref: req.Ref,
}
getShareRes, err := c.GetShare(ctx, getShareReq)
if err != nil {
return nil, errors.Wrap(err, "gateway: error calling GetShare")
}

grantReq := &provider.UpdateGrantRequest{
Ref: &provider.Reference{
Spec: &provider.Reference_Id{
Id: getShareRes.Share.ResourceId,
},
},
Grant: &provider.Grant{
Grantee: getShareRes.Share.Grantee,
Permissions: getShareRes.Share.Permissions.Permissions,
},
}
grantRes, err := s.UpdateGrant(ctx, grantReq)
if err != nil {
return nil, errors.Wrap(err, "gateway: error calling UpdateGrant")
}
if grantRes.Status.Code != rpc.Code_CODE_OK {
return &collaboration.UpdateShareResponse{
Status: status.NewInternal(ctx, status.NewErrorFromCode(grantRes.Status.Code, "gateway"),
"error updating storage grant"),
}, nil
}
if getShareRes.Status.Code != rpc.Code_CODE_OK {
return &collaboration.UpdateShareResponse{
Status: status.NewInternal(ctx, status.NewErrorFromCode(getShareRes.Status.Code, "gateway"),
"error getting share when committing to the share"),
}, nil
}
updateGrantStatus, err := s.updateGrant(ctx, getShareRes.GetShare().GetResourceId(),
getShareRes.GetShare().GetGrantee(),
getShareRes.GetShare().GetPermissions().GetPermissions())
if updateGrantStatus.Code != rpc.Code_CODE_OK {
return &collaboration.UpdateShareResponse{
Status: updateGrantStatus,
}, err
}
*/
}

return res, nil
}
Expand Down Expand Up @@ -464,6 +449,40 @@ func (s *svc) addGrant(ctx context.Context, id *provider.ResourceId, g *provider
return status.NewOK(ctx), nil
}

func (s *svc) updateGrant(ctx context.Context, id *provider.ResourceId, g *provider.Grantee, p *provider.ResourcePermissions) (*rpc.Status, error) {

grantReq := &provider.UpdateGrantRequest{
Ref: &provider.Reference{
Spec: &provider.Reference_Id{
Id: id,
},
},
Grant: &provider.Grant{
Grantee: g,
Permissions: p,
},
}

c, err := s.findByID(ctx, id)
if err != nil {
if _, ok := err.(errtypes.IsNotFound); ok {
return status.NewNotFound(ctx, "storage provider not found"), nil
}
return status.NewInternal(ctx, err, "error finding storage provider"), nil
}

grantRes, err := c.UpdateGrant(ctx, grantReq)
if err != nil {
return nil, errors.Wrap(err, "gateway: error calling UpdateGrant")
}
if grantRes.Status.Code != rpc.Code_CODE_OK {
return status.NewInternal(ctx, status.NewErrorFromCode(grantRes.Status.Code, "gateway"),
"error committing share to storage grant"), nil
}

return status.NewOK(ctx), nil
}

func (s *svc) removeGrant(ctx context.Context, id *provider.ResourceId, g *provider.Grantee, p *provider.ResourcePermissions) (*rpc.Status, error) {

grantReq := &provider.RemoveGrantRequest{
Expand Down

0 comments on commit 40db8d2

Please sign in to comment.