Skip to content

Commit

Permalink
improve webdav responses on errors (#1878)
Browse files Browse the repository at this point in the history
  • Loading branch information
micbar authored Jul 12, 2021
1 parent 00cbdaa commit 256d683
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 9 deletions.
5 changes: 5 additions & 0 deletions changelog/unreleased/fix-webdav-trashbin-errors.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Bugfix: Improve the webdav error handling in the trashbin

The trashbin handles errors better now on the webdav endpoint.

https://github.com/cs3org/reva/pull/1878
3 changes: 3 additions & 0 deletions internal/http/services/owncloud/ocdav/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ const (
SabredavPermissionDenied
// SabredavNotFound maps to HTTP 404
SabredavNotFound
// SabredavConflict maps to HTTP 409
SabredavConflict
)

var (
Expand All @@ -53,6 +55,7 @@ var (
"Sabre\\DAV\\Exception\\PreconditionFailed",
"Sabre\\DAV\\Exception\\PermissionDenied",
"Sabre\\DAV\\Exception\\NotFound",
"Sabre\\DAV\\Exception\\Conflict",
}
)

Expand Down
37 changes: 28 additions & 9 deletions internal/http/services/owncloud/ocdav/trashbin.go
Original file line number Diff line number Diff line change
Expand Up @@ -482,15 +482,7 @@ func (h *TrashbinHandler) restore(w http.ResponseWriter, r *http.Request, s *svc
message: "The destination node already exists, and the overwrite header is set to false",
header: "Overwrite",
})
if err != nil {
sublog.Error().Msgf("error marshaling xml response: %s", b)
w.WriteHeader(http.StatusInternalServerError)
return
}
_, err = w.Write(b)
if err != nil {
sublog.Err(err).Msg("error writing response")
}
HandleWebdavError(&sublog, w, b, err)
return
}
// delete existing tree
Expand Down Expand Up @@ -528,6 +520,14 @@ func (h *TrashbinHandler) restore(w http.ResponseWriter, r *http.Request, s *svc
}

if res.Status.Code != rpc.Code_CODE_OK {
if res.Status.Code == rpc.Code_CODE_PERMISSION_DENIED {
w.WriteHeader(http.StatusForbidden)
b, err := Marshal(exception{
code: SabredavPermissionDenied,
message: "Permission denied to restore",
})
HandleWebdavError(&sublog, w, b, err)
}
HandleErrorStatus(&sublog, w, res.Status)
return
}
Expand Down Expand Up @@ -613,6 +613,25 @@ func (h *TrashbinHandler) delete(w http.ResponseWriter, r *http.Request, s *svc,
case rpc.Code_CODE_NOT_FOUND:
sublog.Debug().Str("storageid", sRes.Info.Id.StorageId).Str("key", key).Interface("status", res.Status).Msg("resource not found")
w.WriteHeader(http.StatusConflict)
m := fmt.Sprintf("storageid %v not found", sRes.Info.Id.StorageId)
b, err := Marshal(exception{
code: SabredavConflict,
message: m,
})
HandleWebdavError(&sublog, w, b, err)
case rpc.Code_CODE_PERMISSION_DENIED:
w.WriteHeader(http.StatusForbidden)
var m string
if key == "" {
m = "Permission denied to purge recycle"
} else {
m = "Permission denied to delete"
}
b, err := Marshal(exception{
code: SabredavPermissionDenied,
message: m,
})
HandleWebdavError(&sublog, w, b, err)
default:
HandleErrorStatus(&sublog, w, res.Status)
}
Expand Down

0 comments on commit 256d683

Please sign in to comment.