diff --git a/changelog/unreleased/fix-webdav-trashbin-errors.md b/changelog/unreleased/fix-webdav-trashbin-errors.md new file mode 100644 index 0000000000..05d06e8b23 --- /dev/null +++ b/changelog/unreleased/fix-webdav-trashbin-errors.md @@ -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 diff --git a/internal/http/services/owncloud/ocdav/error.go b/internal/http/services/owncloud/ocdav/error.go index 725be4fb1e..114b80fdff 100644 --- a/internal/http/services/owncloud/ocdav/error.go +++ b/internal/http/services/owncloud/ocdav/error.go @@ -43,6 +43,8 @@ const ( SabredavPermissionDenied // SabredavNotFound maps to HTTP 404 SabredavNotFound + // SabredavConflict maps to HTTP 409 + SabredavConflict ) var ( @@ -53,6 +55,7 @@ var ( "Sabre\\DAV\\Exception\\PreconditionFailed", "Sabre\\DAV\\Exception\\PermissionDenied", "Sabre\\DAV\\Exception\\NotFound", + "Sabre\\DAV\\Exception\\Conflict", } ) diff --git a/internal/http/services/owncloud/ocdav/trashbin.go b/internal/http/services/owncloud/ocdav/trashbin.go index a06a37d9c0..e5eeb7db6c 100644 --- a/internal/http/services/owncloud/ocdav/trashbin.go +++ b/internal/http/services/owncloud/ocdav/trashbin.go @@ -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 @@ -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 } @@ -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) }