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 }