From 8869b1e0aa8bbcebf0361c8ac4956854a3cc0aa4 Mon Sep 17 00:00:00 2001 From: David Christofas Date: Fri, 23 Jul 2021 16:27:27 +0200 Subject: [PATCH] fix share path when listing a specific share --- changelog/unreleased/fix-share-path.md | 5 +++ .../handlers/apps/sharing/shares/shares.go | 36 ++++++++++++++++--- 2 files changed, 36 insertions(+), 5 deletions(-) create mode 100644 changelog/unreleased/fix-share-path.md diff --git a/changelog/unreleased/fix-share-path.md b/changelog/unreleased/fix-share-path.md new file mode 100644 index 00000000000..71130343faa --- /dev/null +++ b/changelog/unreleased/fix-share-path.md @@ -0,0 +1,5 @@ +Bugfix: Fix share path when listing a specific share + +The file path and target of shares where missing the share jail path when a specific share was listed. + +https://github.com/cs3org/reva/pull/1918 diff --git a/internal/http/services/owncloud/ocs/handlers/apps/sharing/shares/shares.go b/internal/http/services/owncloud/ocs/handlers/apps/sharing/shares/shares.go index 624df6bcf96..e1f6ac15560 100644 --- a/internal/http/services/owncloud/ocs/handlers/apps/sharing/shares/shares.go +++ b/internal/http/services/owncloud/ocs/handlers/apps/sharing/shares/shares.go @@ -52,6 +52,7 @@ import ( "github.com/cs3org/reva/pkg/rhttp/router" "github.com/cs3org/reva/pkg/share/cache" "github.com/cs3org/reva/pkg/share/cache/registry" + "github.com/cs3org/reva/pkg/user" "github.com/cs3org/reva/pkg/utils" "github.com/pkg/errors" ) @@ -374,6 +375,7 @@ func (h *Handler) getShare(w http.ResponseWriter, r *http.Request, shareID strin resourceID = psRes.Share.ResourceId } + var receivedShare *collaboration.ReceivedShare if share == nil { // check if we have a user share logger.Debug().Str("shareID", shareID).Msg("get user share by id") @@ -405,10 +407,30 @@ func (h *Handler) getShare(w http.ResponseWriter, r *http.Request, shareID strin if err == nil && uRes.GetShare() != nil { resourceID = uRes.Share.ResourceId - share, err = conversions.CS3Share2ShareData(ctx, uRes.Share) - if err != nil { - response.WriteOCSError(w, r, response.MetaServerError.StatusCode, "error mapping share data", err) - return + currentUser := user.ContextMustGetUser(ctx) + if utils.UserEqual(uRes.Share.Creator, currentUser.Id) { + share, err = conversions.CS3Share2ShareData(ctx, uRes.Share) + if err != nil { + response.WriteOCSError(w, r, response.MetaServerError.StatusCode, "error mapping share data", err) + return + } + } else { + rsRes, err := client.GetReceivedShare(ctx, &collaboration.GetReceivedShareRequest{ + Ref: &collaboration.ShareReference{ + Spec: &collaboration.ShareReference_Id{ + Id: uRes.Share.Id, + }, + }, + }) + + if err == nil && rsRes.GetShare() != nil { + receivedShare = rsRes.GetShare() + share, err = conversions.CS3Share2ShareData(ctx, rsRes.Share.Share) + if err != nil { + response.WriteOCSError(w, r, response.MetaServerError.StatusCode, "error mapping share data", err) + return + } + } } } } @@ -438,7 +460,11 @@ func (h *Handler) getShare(w http.ResponseWriter, r *http.Request, shareID strin response.WriteOCSError(w, r, response.MetaServerError.StatusCode, "error mapping share data", err) } h.mapUserIds(ctx, client, share) - + if receivedShare != nil && receivedShare.State == collaboration.ShareState_SHARE_STATE_ACCEPTED { + // Needed because received shares can be jailed in a folder in the users home + share.FileTarget = path.Join(h.sharePrefix, path.Base(info.Path)) + share.Path = path.Join(h.sharePrefix, path.Base(info.Path)) + } response.WriteOCSSuccess(w, r, []*conversions.ShareData{share}) }