Skip to content

Commit

Permalink
fix share path when listing a specific share
Browse files Browse the repository at this point in the history
  • Loading branch information
David Christofas committed Sep 13, 2021
1 parent 36d6211 commit 55b17ac
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 5 deletions.
5 changes: 5 additions & 0 deletions changelog/unreleased/fix-share-path.md
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ import (
"github.com/cs3org/reva/pkg/share"
"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"
)
Expand Down Expand Up @@ -299,6 +300,7 @@ func (h *Handler) GetShare(w http.ResponseWriter, r *http.Request) {
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")
Expand Down Expand Up @@ -330,10 +332,30 @@ func (h *Handler) GetShare(w http.ResponseWriter, r *http.Request) {

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
}
}
}
}
}
Expand Down Expand Up @@ -363,7 +385,11 @@ func (h *Handler) GetShare(w http.ResponseWriter, r *http.Request) {
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})
}

Expand Down

0 comments on commit 55b17ac

Please sign in to comment.