Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add path to publiclink POST response #4004

Merged
merged 1 commit into from
Jun 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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