Skip to content

Commit

Permalink
Merge pull request #4004 from kobergj/AddPathToPublicLink
Browse files Browse the repository at this point in the history
Add path to publiclink POST response
  • Loading branch information
kobergj authored Jun 21, 2023
2 parents a4c9718 + b147e28 commit 85eb1be
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 85eb1be

Please sign in to comment.