diff --git a/changelog/unreleased/fix_ocm_removegrant.md b/changelog/unreleased/fix_ocm_removegrant.md new file mode 100644 index 0000000000..f73559b40b --- /dev/null +++ b/changelog/unreleased/fix_ocm_removegrant.md @@ -0,0 +1,7 @@ +Bugfix: Deleting OCM share also updates storageprovider + +When remvoving an OCM share we're now also removing the related grant from +the storage provider. + +https://github.com/cs3org/reva/pull/4989 +https://github.com/owncloud/ocis/issues/10262 diff --git a/internal/grpc/services/gateway/ocmshareprovider.go b/internal/grpc/services/gateway/ocmshareprovider.go index d5e0f49916..4f8b943157 100644 --- a/internal/grpc/services/gateway/ocmshareprovider.go +++ b/internal/grpc/services/gateway/ocmshareprovider.go @@ -85,11 +85,37 @@ func (s *svc) RemoveOCMShare(ctx context.Context, req *ocm.RemoveOCMShareRequest }, nil } + getShareRes, err := c.GetOCMShare(ctx, &ocm.GetOCMShareRequest{ + Ref: req.Ref, + }) + if err != nil { + return nil, errors.Wrap(err, "gateway: error calling GetOCMShare") + } + if getShareRes.Status.Code != rpc.Code_CODE_OK { + res := &ocm.RemoveOCMShareResponse{ + Status: status.NewInternal(ctx, + "error getting ocm share when committing to the storage"), + } + return res, nil + } + share := getShareRes.Share + res, err := c.RemoveOCMShare(ctx, req) if err != nil { return nil, errors.Wrap(err, "gateway: error calling RemoveOCMShare") } + // remove the grant from the storage provider + status, err := s.removeGrant(ctx, share.GetResourceId(), share.GetGrantee(), share.GetAccessMethods()[0].GetWebdavOptions().GetPermissions(), nil) + if err != nil { + return nil, errors.Wrap(err, "gateway: error removing grant from storage") + } + if status.Code != rpc.Code_CODE_OK { + return &ocm.RemoveOCMShareResponse{ + Status: status, + }, err + } + return res, nil }