Skip to content

Commit

Permalink
Rewire dav files endpoint to home (better approach) (#1125)
Browse files Browse the repository at this point in the history
  • Loading branch information
Vincent Petry authored Aug 26, 2020
1 parent dcf99b1 commit c0f54e1
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 18 deletions.
8 changes: 8 additions & 0 deletions changelog/unreleased/ocdav-dav-files-to-home.md
Original file line number Diff line number Diff line change
@@ -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
33 changes: 29 additions & 4 deletions internal/http/services/owncloud/ocdav/dav.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -42,6 +43,7 @@ type tokenStatInfoKey struct{}
type DavHandler struct {
AvatarsHandler *AvatarsHandler
FilesHandler *WebDavHandler
FilesHomeHandler *WebDavHandler
MetaHandler *MetaHandler
TrashbinHandler *TrashbinHandler
PublicFolderHandler *WebDavHandler
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down
15 changes: 1 addition & 14 deletions tests/acceptance/expected-failures-on-OC-storage.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -999,4 +986,4 @@ apiWebdavUpload2/uploadFileUsingOldChunking.feature:97
apiWebdavUpload2/uploadFileUsingOldChunking.feature:98
apiWebdavUpload2/uploadFileUsingOldChunking.feature:99
apiWebdavUpload2/uploadFileUsingOldChunking.feature:100
apiWebdavUpload2/uploadFileUsingOldChunking.feature:101
apiWebdavUpload2/uploadFileUsingOldChunking.feature:101

0 comments on commit c0f54e1

Please sign in to comment.