Skip to content

Commit

Permalink
add path to POST publiclink
Browse files Browse the repository at this point in the history
Signed-off-by: jkoberg <jkoberg@owncloud.com>
  • Loading branch information
kobergj committed Jun 21, 2023
1 parent a4c9718 commit b147e28
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
5 changes: 5 additions & 0 deletions changelog/unreleased/add-path-to-publiclink-post.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Bugfix: Add path to public link POST

When POSTing a public link, the response would not contain the complete path to the resource. This is fixed now.

https://github.com/cs3org/reva/pull/4004
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,8 @@ func (h *Handler) CreateShare(w http.ResponseWriter, r *http.Request) {
}

s := conversions.PublicShare2ShareData(share, r, h.publicURL)
h.addFileInfo(ctx, s, statRes.Info)
h.addFileInfo(ctx, s, statRes.GetInfo())
h.addPath(ctx, s, statRes.GetInfo())
h.mapUserIds(ctx, client, s)

response.WriteOCSSuccess(w, r, s)
Expand Down Expand Up @@ -1225,6 +1226,22 @@ func (h *Handler) addFileInfo(ctx context.Context, s *conversions.ShareData, inf
s.SpaceAlias = utils.ReadPlainFromOpaque(info.GetSpace().GetOpaque(), "spaceAlias")
}

// addPath adds the complete path of the `ResourceInfo` to the `ShareData`. It is an expensive operation and might leak data so use it with care.
func (h *Handler) addPath(ctx context.Context, s *conversions.ShareData, info *provider.ResourceInfo) {
log := appctx.GetLogger(ctx)
client, err := h.getClient()
if err != nil {
log.Error().Err(err).Msg("addPath failed: cannot get gateway client")
return
}
gpRes, err := client.GetPath(ctx, &provider.GetPathRequest{ResourceId: info.Id})
if err != nil || gpRes.GetStatus().GetCode() != rpc.Code_CODE_OK {
log.Error().Err(err).Interface("rpc response code", gpRes.GetStatus().GetCode()).Msg("addPath failed: cannot get path")
return
}
s.Path = gpRes.GetPath()
}

// mustGetIdentifiers always returns a struct with identifiers, if the user or group could not be found they will all be empty
func (h *Handler) mustGetIdentifiers(ctx context.Context, client gateway.GatewayAPIClient, id string, isGroup bool) *userIdentifiers {
sublog := appctx.GetLogger(ctx).With().Str("id", id).Logger()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,11 @@ var _ = Describe("The ocs API", func() {
})

It("creates a link share", func() {
gatewayClient.On("GetPath", mock.Anything, mock.Anything, mock.Anything).Return(&provider.GetPathResponse{
Status: &rpc.Status{Code: rpc.Code_CODE_OK},
Path: "path/to/file",
}, nil)

form := url.Values{}
form.Add("shareType", "3")
form.Add("path", "/")
Expand Down

0 comments on commit b147e28

Please sign in to comment.