Skip to content

Commit

Permalink
Allow using the username when accessing the users home (#1205)
Browse files Browse the repository at this point in the history
Signed-off-by: Jörn Friedrich Dreyer <[email protected]>
  • Loading branch information
butonic authored Sep 30, 2020
1 parent a05b4f0 commit 80157f4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
6 changes: 6 additions & 0 deletions changelog/unreleased/allow-username-in-dav-files.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Enhancement: Allow using the username when accessing the users home

We now allow using the userid and the username when accessing the
users home on the `/dev/files` endpoint.

https://github.com/cs3org/reva/pull/1205
8 changes: 7 additions & 1 deletion internal/http/services/owncloud/ocdav/dav.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ import (
"fmt"
"net/http"
"path"
"strings"

gatewayv1beta1 "github.com/cs3org/go-cs3apis/cs3/gateway/v1beta1"
userv1beta1 "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1"
rpc "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1"
rpcv1beta1 "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1"
provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
Expand Down Expand Up @@ -82,6 +84,10 @@ func (h *DavHandler) init(c *Config) error {
return h.TrashbinHandler.init(c)
}

func isOwner(userIDorName string, user *userv1beta1.User) bool {
return userIDorName != "" && (userIDorName == user.Id.OpaqueId || strings.EqualFold(userIDorName, user.Username))
}

// Handler handles requests
func (h *DavHandler) Handler(s *svc) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
Expand All @@ -103,7 +109,7 @@ func (h *DavHandler) Handler(s *svc) http.Handler {

// note: some requests like OPTIONS don't forward the user
contextUser, ok := ctxuser.ContextGetUser(ctx)
if ok && requestUserID != "" && requestUserID == contextUser.Id.OpaqueId {
if ok && isOwner(requestUserID, contextUser) {
// use home storage handler when user was detected
base := path.Join(ctx.Value(ctxKeyBaseURI).(string), "files", requestUserID)
ctx := context.WithValue(ctx, ctxKeyBaseURI, base)
Expand Down

0 comments on commit 80157f4

Please sign in to comment.