From f9ed5625bceb30de0a104a135ee2aae01b445350 Mon Sep 17 00:00:00 2001 From: Christian Richter Date: Fri, 27 Oct 2023 15:14:18 +0200 Subject: [PATCH] bugfix keep existing hidden states Signed-off-by: Christian Richter --- .../unreleased/add-hide-flag-to-shares.md | 1 + .../handlers/apps/sharing/shares/pending.go | 22 ++++++++++++++++--- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/changelog/unreleased/add-hide-flag-to-shares.md b/changelog/unreleased/add-hide-flag-to-shares.md index cba7e26c90..97d0c4f268 100644 --- a/changelog/unreleased/add-hide-flag-to-shares.md +++ b/changelog/unreleased/add-hide-flag-to-shares.md @@ -4,6 +4,7 @@ We have added the ability to hide shares through the ocs/v2.php/apps/files_sharing/api/v1/shares/pending/ endpoint by appending a POST-Variable called hide which can be true or false. +https://github.com/cs3org/reva/pull/4295 https://github.com/cs3org/reva/pull/4289 https://github.com/cs3org/reva/pull/4194 https://github.com/owncloud/ocis/issues/7589 \ No newline at end of file diff --git a/internal/http/services/owncloud/ocs/handlers/apps/sharing/shares/pending.go b/internal/http/services/owncloud/ocs/handlers/apps/sharing/shares/pending.go index b5fdf23c35..8709502c6b 100644 --- a/internal/http/services/owncloud/ocs/handlers/apps/sharing/shares/pending.go +++ b/internal/http/services/owncloud/ocs/handlers/apps/sharing/shares/pending.go @@ -88,6 +88,7 @@ func (h *Handler) AcceptReceivedShare(w http.ResponseWriter, r *http.Request) { } } else { if s.State == collaboration.ShareState_SHARE_STATE_ACCEPTED { + s.Hidden = h.getReceivedShareHideFlagFromShareID(r.Context(), shareID) mountedShares = append(mountedShares, s) } } @@ -127,7 +128,8 @@ func (h *Handler) AcceptReceivedShare(w http.ResponseWriter, r *http.Request) { Share: &collaboration.Share{ Id: &collaboration.ShareId{OpaqueId: shareID}, }, - State: collaboration.ShareState_SHARE_STATE_ACCEPTED, + State: collaboration.ShareState_SHARE_STATE_ACCEPTED, + Hidden: h.getReceivedShareHideFlagFromShareID(r.Context(), shareID), MountPoint: &provider.Reference{ Path: mount, }, @@ -151,7 +153,8 @@ func (h *Handler) RejectReceivedShare(w http.ResponseWriter, r *http.Request) { Share: &collaboration.Share{ Id: &collaboration.ShareId{OpaqueId: shareID}, }, - State: collaboration.ShareState_SHARE_STATE_REJECTED, + State: collaboration.ShareState_SHARE_STATE_REJECTED, + Hidden: h.getReceivedShareHideFlagFromShareID(r.Context(), shareID), } updateMask := &fieldmaskpb.FieldMask{Paths: []string{"state", "hidden"}} @@ -238,7 +241,7 @@ func (h *Handler) updateReceivedShare(w http.ResponseWriter, r *http.Request, re } data.State = mapState(rs.GetState()) - data.Hidden = rs.Hidden + data.Hidden = rs.GetHidden() h.addFileInfo(ctx, data, info) h.mapUserIds(r.Context(), client, data) @@ -251,6 +254,19 @@ func (h *Handler) updateReceivedShare(w http.ResponseWriter, r *http.Request, re return data } +// getReceivedShareHideFlagFromShareId returns the hide flag of a received share based on its ID. +func (h *Handler) getReceivedShareHideFlagFromShareID(ctx context.Context, shareID string) bool { + client, err := h.getClient() + if err != nil { + return false + } + rs, _ := getReceivedShareFromID(ctx, client, shareID) + if rs != nil { + return rs.GetShare().GetHidden() + } + return false +} + // getReceivedShareFromID uses a client to the gateway to fetch a share based on its ID. func getReceivedShareFromID(ctx context.Context, client gateway.GatewayAPIClient, shareID string) (*collaboration.GetReceivedShareResponse, *response.Response) { s, err := client.GetReceivedShare(ctx, &collaboration.GetReceivedShareRequest{