Skip to content

Commit

Permalink
Merge pull request #3710 from rhafer/del-space-permission-denied
Browse files Browse the repository at this point in the history
Fix error handling in DeleteStorage space
  • Loading branch information
micbar authored Mar 8, 2023
2 parents 861c31c + fc69deb commit 4ebb727
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
6 changes: 6 additions & 0 deletions changelog/unreleased/fix-del-space.md
Original file line number Diff line number Diff line change
@@ -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
11 changes: 10 additions & 1 deletion internal/grpc/services/storageprovider/storageprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit 4ebb727

Please sign in to comment.