From e3f6f3ee1dc4ee45b2469bb36906007449d0670d Mon Sep 17 00:00:00 2001 From: Roman Perekhod Date: Thu, 13 Jun 2024 09:26:00 +0200 Subject: [PATCH] The hidden shares have been excluded from a search result --- changelog/unreleased/fix-search-hidden.md | 6 ++++++ services/search/pkg/search/service.go | 20 +++++++++++++++++++- services/search/pkg/search/service_test.go | 4 ++++ 3 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 changelog/unreleased/fix-search-hidden.md diff --git a/changelog/unreleased/fix-search-hidden.md b/changelog/unreleased/fix-search-hidden.md new file mode 100644 index 000000000..d234d463a --- /dev/null +++ b/changelog/unreleased/fix-search-hidden.md @@ -0,0 +1,6 @@ +Bugfix: The hidden shares have been excluded from a search result + +The hidden shares have been excluded from a search result. + +https://github.com/owncloud/ocis/pull/9371 +https://github.com/owncloud/ocis/issues/7383 diff --git a/services/search/pkg/search/service.go b/services/search/pkg/search/service.go index 1931bed5b..2f50b32ac 100644 --- a/services/search/pkg/search/service.go +++ b/services/search/pkg/search/service.go @@ -13,6 +13,7 @@ import ( user "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1" rpc "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1" rpcv1beta1 "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1" + collaborationv1beta1 "github.com/cs3org/go-cs3apis/cs3/sharing/collaboration/v1beta1" provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1" revactx "github.com/cs3org/reva/v2/pkg/ctx" "github.com/cs3org/reva/v2/pkg/errtypes" @@ -323,6 +324,23 @@ func (s *Service) searchIndex(ctx context.Context, req *searchsvc.SearchRequest, s.logger.Error().Err(err).Str("space", space.Id.OpaqueId).Str("mountpointId", mountpointID).Msg("invalid mountpoint space id") return nil, errSkipSpace } + // exclude the hidden shares + rs, err := gatewayClient.GetReceivedShare(ctx, &collaborationv1beta1.GetReceivedShareRequest{ + Ref: &collaborationv1beta1.ShareReference{ + Spec: &collaborationv1beta1.ShareReference_Id{ + Id: &collaborationv1beta1.ShareId{ + OpaqueId: oid, + }, + }, + }, + }) + if err != nil { + s.logger.Error().Err(err).Str("space", space.Id.OpaqueId).Str("shareId", oid).Msg("invalid receive share") + } + if rs.GetStatus().GetCode() == rpcv1beta1.Code_CODE_OK && rs.GetShare().GetHidden() { + return nil, errSkipSpace + } + mountpointRootID = &searchmsg.ResourceID{ StorageId: sid, SpaceId: spid, @@ -361,7 +379,7 @@ func (s *Service) searchIndex(ctx context.Context, req *searchsvc.SearchRequest, s.logger.Debug().Interface("searchRequest", searchRequest).Str("duration", fmt.Sprint(duration)).Str("space", space.Id.OpaqueId).Int("hits", len(res.Matches)).Msg("space search done") } - var matches []*searchmsg.Match + matches := make([]*searchmsg.Match, 0, len(res.Matches)) for _, match := range res.Matches { if mountpointPrefix != "" { diff --git a/services/search/pkg/search/service_test.go b/services/search/pkg/search/service_test.go index 57a89b3ec..e5775a084 100644 --- a/services/search/pkg/search/service_test.go +++ b/services/search/pkg/search/service_test.go @@ -5,6 +5,7 @@ import ( gateway "github.com/cs3org/go-cs3apis/cs3/gateway/v1beta1" userv1beta1 "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1" + collaborationv1beta1 "github.com/cs3org/go-cs3apis/cs3/sharing/collaboration/v1beta1" sprovider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1" typesv1beta1 "github.com/cs3org/go-cs3apis/cs3/types/v1beta1" revactx "github.com/cs3org/reva/v2/pkg/ctx" @@ -101,6 +102,9 @@ var _ = Describe("Searchprovider", func() { Status: status.NewOK(context.Background()), Path: ri.Path, }, nil) + gatewayClient.On("GetReceivedShare", mock.Anything, mock.Anything).Return(&collaborationv1beta1.GetReceivedShareResponse{ + Status: status.NewOK(ctx), + }, nil) indexClient.On("DocCount").Return(uint64(1), nil) })