Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rewire dav files endpoint to home (better approach) #1125

Merged
merged 2 commits into from
Aug 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Comment on lines -503 to -509
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are Scenario Outline Examples for the "new" dav-path. The Examples for the "old" dav-path were already passing. So the "rewiring" in this PR has fixed some issue with the "new" dav-path. That is "a good thing" (tm)

#
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
Comment on lines -537 to -538
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are both Examples for "new" dav-path. The example for "old" dav-path at 294 and 309 were already passing.

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