From fc69debe1e65588430aaecf4184ccdec71a1e836 Mon Sep 17 00:00:00 2001 From: Ralf Haferkamp Date: Wed, 8 Mar 2023 10:22:22 +0100 Subject: [PATCH] Fix error handling in DeleteStorage space Return a permission denied error when the user is not able to list the to be delete space. --- changelog/unreleased/fix-del-space.md | 6 ++++++ .../grpc/services/storageprovider/storageprovider.go | 11 ++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 changelog/unreleased/fix-del-space.md diff --git a/changelog/unreleased/fix-del-space.md b/changelog/unreleased/fix-del-space.md new file mode 100644 index 0000000000..9a163610df --- /dev/null +++ b/changelog/unreleased/fix-del-space.md @@ -0,0 +1,6 @@ +Bugfix: Fix error when try to delete space without permission + +When a user without the correct permission tries to delete a storage space, +return a PermissionDenied error instead of an Internal Error. + +https://github.com/cs3org/reva/pull/3710 diff --git a/internal/grpc/services/storageprovider/storageprovider.go b/internal/grpc/services/storageprovider/storageprovider.go index 43b68de2e9..baa1f6ba37 100644 --- a/internal/grpc/services/storageprovider/storageprovider.go +++ b/internal/grpc/services/storageprovider/storageprovider.go @@ -597,8 +597,17 @@ func (s *service) DeleteStorageSpace(ctx context.Context, req *provider.DeleteSt spaces, err := s.storage.ListStorageSpaces(ctx, []*provider.ListStorageSpacesRequest_Filter{{Type: provider.ListStorageSpacesRequest_Filter_TYPE_ID, Term: &provider.ListStorageSpacesRequest_Filter_Id{Id: id}}}, true) if err != nil || len(spaces) != 1 { + var st *rpc.Status + switch err.(type) { + case errtypes.IsNotFound, errtypes.PermissionDenied: + st = status.NewPermissionDenied(ctx, err, "permission denied") + case errtypes.BadRequest: + st = status.NewInvalid(ctx, err.Error()) + default: + st = status.NewInternal(ctx, "error deleting space: "+req.Id.String()) + } return &provider.DeleteStorageSpaceResponse{ - Status: status.NewInternal(ctx, "cannot get space"), + Status: st, }, nil }