From a8a1e193b2fdd094209195922a16c3fe6788144a Mon Sep 17 00:00:00 2001 From: Ralf Haferkamp Date: Thu, 5 Dec 2024 13:06:20 +0100 Subject: [PATCH] fix: remove grant from storage when removing OCM share Fixes: https://github.com/owncloud/ocis/issues/10262 --- changelog/unreleased/fix_ocm_removegrant.md | 7 +++++ .../grpc/services/gateway/ocmshareprovider.go | 26 +++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 changelog/unreleased/fix_ocm_removegrant.md 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 }