From 489e2af5687ef0302017c9100877ca08a7b90f43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20Friedrich=20Dreyer?= Date: Wed, 30 Sep 2020 12:06:06 +0200 Subject: [PATCH] Allow using the username when accessing the users home MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jörn Friedrich Dreyer --- changelog/unreleased/allow-username-in-dav-files.md | 6 ++++++ internal/http/services/owncloud/ocdav/dav.go | 8 +++++++- 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 changelog/unreleased/allow-username-in-dav-files.md diff --git a/changelog/unreleased/allow-username-in-dav-files.md b/changelog/unreleased/allow-username-in-dav-files.md new file mode 100644 index 0000000000..73dd0628e7 --- /dev/null +++ b/changelog/unreleased/allow-username-in-dav-files.md @@ -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 diff --git a/internal/http/services/owncloud/ocdav/dav.go b/internal/http/services/owncloud/ocdav/dav.go index ed9238a8c6..10ef5380b9 100644 --- a/internal/http/services/owncloud/ocdav/dav.go +++ b/internal/http/services/owncloud/ocdav/dav.go @@ -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" @@ -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) { @@ -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)