From b147e28b7737b5e82a0e5533e3d78e8e0ceb8c6e Mon Sep 17 00:00:00 2001 From: jkoberg Date: Wed, 21 Jun 2023 15:12:04 +0200 Subject: [PATCH] add path to POST publiclink Signed-off-by: jkoberg --- .../unreleased/add-path-to-publiclink-post.md | 5 +++++ .../handlers/apps/sharing/shares/shares.go | 19 ++++++++++++++++++- .../apps/sharing/shares/shares_test.go | 5 +++++ 3 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 changelog/unreleased/add-path-to-publiclink-post.md diff --git a/changelog/unreleased/add-path-to-publiclink-post.md b/changelog/unreleased/add-path-to-publiclink-post.md new file mode 100644 index 0000000000..eaeffa3f35 --- /dev/null +++ b/changelog/unreleased/add-path-to-publiclink-post.md @@ -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 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 7c675f9bd4..b272c569c1 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 @@ -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) @@ -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() diff --git a/internal/http/services/owncloud/ocs/handlers/apps/sharing/shares/shares_test.go b/internal/http/services/owncloud/ocs/handlers/apps/sharing/shares/shares_test.go index 09cf66a23f..10c11e0ac0 100644 --- a/internal/http/services/owncloud/ocs/handlers/apps/sharing/shares/shares_test.go +++ b/internal/http/services/owncloud/ocs/handlers/apps/sharing/shares/shares_test.go @@ -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", "/")