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

update grants in the storage provider on share update #1258

Merged
merged 3 commits into from
Oct 20, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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
}
*/
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@labkode any reason why this was commented?


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