diff --git a/changelog/unreleased/ocdav-dav-files-to-home.md b/changelog/unreleased/ocdav-dav-files-to-home.md new file mode 100644 index 0000000000..856b861dc9 --- /dev/null +++ b/changelog/unreleased/ocdav-dav-files-to-home.md @@ -0,0 +1,8 @@ +Enhancement: Rewire dav files to the home storage + +If the user specified in the dav files URL matches the current one, +rewire it to use the webDavHandler which is wired to the home storage. + +This fixes path mapping issues. + +https://github.com/cs3org/reva/pull/1125 diff --git a/internal/http/services/owncloud/ocdav/dav.go b/internal/http/services/owncloud/ocdav/dav.go index 0d5d1d5df8..ed9238a8c6 100644 --- a/internal/http/services/owncloud/ocdav/dav.go +++ b/internal/http/services/owncloud/ocdav/dav.go @@ -33,6 +33,7 @@ import ( "github.com/cs3org/reva/pkg/rhttp/router" tokenpkg "github.com/cs3org/reva/pkg/token" "github.com/cs3org/reva/pkg/user" + ctxuser "github.com/cs3org/reva/pkg/user" "google.golang.org/grpc/metadata" ) @@ -42,6 +43,7 @@ type tokenStatInfoKey struct{} type DavHandler struct { AvatarsHandler *AvatarsHandler FilesHandler *WebDavHandler + FilesHomeHandler *WebDavHandler MetaHandler *MetaHandler TrashbinHandler *TrashbinHandler PublicFolderHandler *WebDavHandler @@ -57,6 +59,10 @@ func (h *DavHandler) init(c *Config) error { if err := h.FilesHandler.init(c.FilesNamespace); err != nil { return err } + h.FilesHomeHandler = new(WebDavHandler) + if err := h.FilesHomeHandler.init(c.WebdavNamespace); err != nil { + return err + } h.MetaHandler = new(MetaHandler) if err := h.MetaHandler.init(c); err != nil { return err @@ -89,10 +95,29 @@ func (h *DavHandler) Handler(s *svc) http.Handler { case "avatars": h.AvatarsHandler.Handler(s).ServeHTTP(w, r) case "files": - base := path.Join(ctx.Value(ctxKeyBaseURI).(string), "files") - ctx := context.WithValue(ctx, ctxKeyBaseURI, base) - r = r.WithContext(ctx) - h.FilesHandler.Handler(s).ServeHTTP(w, r) + var requestUserID string + var oldPath = r.URL.Path + + // detect and check current user in URL + requestUserID, r.URL.Path = router.ShiftPath(r.URL.Path) + + // note: some requests like OPTIONS don't forward the user + contextUser, ok := ctxuser.ContextGetUser(ctx) + if ok && requestUserID != "" && requestUserID == contextUser.Id.OpaqueId { + // use home storage handler when user was detected + base := path.Join(ctx.Value(ctxKeyBaseURI).(string), "files", requestUserID) + ctx := context.WithValue(ctx, ctxKeyBaseURI, base) + r = r.WithContext(ctx) + + h.FilesHomeHandler.Handler(s).ServeHTTP(w, r) + } else { + r.URL.Path = oldPath + base := path.Join(ctx.Value(ctxKeyBaseURI).(string), "files") + ctx := context.WithValue(ctx, ctxKeyBaseURI, base) + r = r.WithContext(ctx) + + h.FilesHandler.Handler(s).ServeHTTP(w, r) + } case "meta": base := path.Join(ctx.Value(ctxKeyBaseURI).(string), "meta") ctx = context.WithValue(ctx, ctxKeyBaseURI, base) diff --git a/tests/acceptance/expected-failures-on-OC-storage.txt b/tests/acceptance/expected-failures-on-OC-storage.txt index 7617770db1..e6cf6e14a3 100644 --- a/tests/acceptance/expected-failures-on-OC-storage.txt +++ b/tests/acceptance/expected-failures-on-OC-storage.txt @@ -476,20 +476,16 @@ apiTrashbin/trashbinDelete.feature:37 apiTrashbin/trashbinDelete.feature:50 apiTrashbin/trashbinDelete.feature:67 # -apiTrashbin/trashbinFilesFolders.feature:21 -apiTrashbin/trashbinFilesFolders.feature:32 apiTrashbin/trashbinFilesFolders.feature:44 apiTrashbin/trashbinFilesFolders.feature:45 apiTrashbin/trashbinFilesFolders.feature:60 apiTrashbin/trashbinFilesFolders.feature:61 -apiTrashbin/trashbinFilesFolders.feature:75 apiTrashbin/trashbinFilesFolders.feature:89 apiTrashbin/trashbinFilesFolders.feature:90 apiTrashbin/trashbinFilesFolders.feature:104 apiTrashbin/trashbinFilesFolders.feature:105 apiTrashbin/trashbinFilesFolders.feature:136 apiTrashbin/trashbinFilesFolders.feature:137 -apiTrashbin/trashbinFilesFolders.feature:155 apiTrashbin/trashbinFilesFolders.feature:185 apiTrashbin/trashbinFilesFolders.feature:186 apiTrashbin/trashbinFilesFolders.feature:203 @@ -500,13 +496,6 @@ apiTrashbin/trashbinFilesFolders.feature:241 apiTrashbin/trashbinFilesFolders.feature:242 apiTrashbin/trashbinFilesFolders.feature:255 apiTrashbin/trashbinFilesFolders.feature:256 -apiTrashbin/trashbinFilesFolders.feature:273 -apiTrashbin/trashbinFilesFolders.feature:274 -apiTrashbin/trashbinFilesFolders.feature:275 -apiTrashbin/trashbinFilesFolders.feature:276 -apiTrashbin/trashbinFilesFolders.feature:277 -apiTrashbin/trashbinFilesFolders.feature:278 -apiTrashbin/trashbinFilesFolders.feature:289 # apiTrashbin/trashbinRestore.feature:31 apiTrashbin/trashbinRestore.feature:32 @@ -534,8 +523,6 @@ apiTrashbin/trashbinRestore.feature:206 apiTrashbin/trashbinRestore.feature:207 apiTrashbin/trashbinRestore.feature:279 apiTrashbin/trashbinRestore.feature:280 -apiTrashbin/trashbinRestore.feature:295 -apiTrashbin/trashbinRestore.feature:310 apiTrashbin/trashbinRestore.feature:323 apiTrashbin/trashbinRestore.feature:324 apiTrashbin/trashbinRestore.feature:325 @@ -999,4 +986,4 @@ apiWebdavUpload2/uploadFileUsingOldChunking.feature:97 apiWebdavUpload2/uploadFileUsingOldChunking.feature:98 apiWebdavUpload2/uploadFileUsingOldChunking.feature:99 apiWebdavUpload2/uploadFileUsingOldChunking.feature:100 -apiWebdavUpload2/uploadFileUsingOldChunking.feature:101 \ No newline at end of file +apiWebdavUpload2/uploadFileUsingOldChunking.feature:101