From 814342a101dbe9cac2e68b26aba8d04a330cca44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Duffeck?= Date: Mon, 1 Aug 2022 13:53:35 +0200 Subject: [PATCH 1/2] Fix search in received shares It apparently broke as a fallout of the shareid refactoring. --- .../search/pkg/search/provider/searchprovider.go | 15 +++++++++------ .../pkg/search/provider/searchprovider_test.go | 15 +++++++++++---- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/services/search/pkg/search/provider/searchprovider.go b/services/search/pkg/search/provider/searchprovider.go index a744699e6..719fa6a7b 100644 --- a/services/search/pkg/search/provider/searchprovider.go +++ b/services/search/pkg/search/provider/searchprovider.go @@ -114,12 +114,19 @@ func (p *Provider) Search(ctx context.Context, req *searchsvc.SearchRequest) (*s matches := MatchArray{} total := int32(0) for _, space := range listSpacesRes.StorageSpaces { + searchRootId := &searchmsg.ResourceID{ + StorageId: space.Root.StorageId, + SpaceId: space.Root.SpaceId, + OpaqueId: space.Root.OpaqueId, + } var mountpointRootId *searchmsg.ResourceID mountpointPrefix := "" switch space.SpaceType { case "mountpoint": continue // mountpoint spaces are only "links" to the shared spaces. we have to search the shared "grant" space instead case "grant": + // In case of grant spaces we search the root of the outer space and translate the paths to the according mountpoint + searchRootId.OpaqueId = space.Root.SpaceId mountpointId, ok := mountpointMap[space.Id.OpaqueId] if !ok { p.logger.Warn().Interface("space", space).Msg("could not find mountpoint space for grant space") @@ -153,12 +160,8 @@ func (p *Provider) Search(ctx context.Context, req *searchsvc.SearchRequest) (*s res, err := p.indexClient.Search(ctx, &searchsvc.SearchIndexRequest{ Query: formatQuery(req.Query), Ref: &searchmsg.Reference{ - ResourceId: &searchmsg.ResourceID{ - StorageId: space.Root.StorageId, - SpaceId: space.Root.SpaceId, - OpaqueId: space.Root.OpaqueId, - }, - Path: mountpointPrefix, + ResourceId: searchRootId, + Path: mountpointPrefix, }, PageSize: req.PageSize, }) diff --git a/services/search/pkg/search/provider/searchprovider_test.go b/services/search/pkg/search/provider/searchprovider_test.go index 0badf5e71..f16e6f6f1 100644 --- a/services/search/pkg/search/provider/searchprovider_test.go +++ b/services/search/pkg/search/provider/searchprovider_test.go @@ -49,8 +49,8 @@ var _ = Describe("Searchprovider", func() { }, }, }, - Id: &sprovider.StorageSpaceId{OpaqueId: "personalspace"}, - Root: &sprovider.ResourceId{StorageId: "storageid", OpaqueId: "storageid"}, + Id: &sprovider.StorageSpaceId{OpaqueId: "storageid$personalspace!personalspace"}, + Root: &sprovider.ResourceId{StorageId: "storageid", SpaceId: "personalspace", OpaqueId: "storageid"}, Name: "personalspace", } @@ -133,6 +133,7 @@ var _ = Describe("Searchprovider", func() { Ref: &searchmsg.Reference{ ResourceId: &searchmsg.ResourceID{ StorageId: personalSpace.Root.StorageId, + SpaceId: personalSpace.Root.SpaceId, OpaqueId: personalSpace.Root.OpaqueId, }, Path: "./path/to/Foo.pdf", @@ -259,6 +260,7 @@ var _ = Describe("Searchprovider", func() { Ref: &searchmsg.Reference{ ResourceId: &searchmsg.ResourceID{ StorageId: grantSpace.Root.StorageId, + SpaceId: grantSpace.Root.SpaceId, OpaqueId: grantSpace.Root.OpaqueId, }, Path: "./grant/path/to/Shared.pdf", @@ -297,7 +299,8 @@ var _ = Describe("Searchprovider", func() { StorageSpaces: []*sprovider.StorageSpace{personalSpace, grantSpace, mountpointSpace}, }, nil) indexClient.On("Search", mock.Anything, mock.MatchedBy(func(req *searchsvc.SearchIndexRequest) bool { - return req.Ref.ResourceId.StorageId == grantSpace.Root.StorageId + return req.Ref.ResourceId.OpaqueId == grantSpace.Root.SpaceId && + req.Ref.ResourceId.SpaceId == grantSpace.Root.SpaceId })).Return(&searchsvc.SearchIndexResponse{ TotalMatches: 2, Matches: []*searchmsg.Match{ @@ -307,6 +310,7 @@ var _ = Describe("Searchprovider", func() { Ref: &searchmsg.Reference{ ResourceId: &searchmsg.ResourceID{ StorageId: grantSpace.Root.StorageId, + SpaceId: grantSpace.Root.SpaceId, OpaqueId: grantSpace.Root.OpaqueId, }, Path: "./grant/path/to/Shared.pdf", @@ -324,6 +328,7 @@ var _ = Describe("Searchprovider", func() { Ref: &searchmsg.Reference{ ResourceId: &searchmsg.ResourceID{ StorageId: grantSpace.Root.StorageId, + SpaceId: grantSpace.Root.SpaceId, OpaqueId: grantSpace.Root.OpaqueId, }, Path: "./grant/path/to/Irrelevant.pdf", @@ -338,7 +343,8 @@ var _ = Describe("Searchprovider", func() { }, }, nil) indexClient.On("Search", mock.Anything, mock.MatchedBy(func(req *searchsvc.SearchIndexRequest) bool { - return req.Ref.ResourceId.StorageId == personalSpace.Root.StorageId + return req.Ref.ResourceId.OpaqueId == personalSpace.Root.OpaqueId && + req.Ref.ResourceId.SpaceId == personalSpace.Root.SpaceId })).Return(&searchsvc.SearchIndexResponse{ TotalMatches: 1, Matches: []*searchmsg.Match{ @@ -348,6 +354,7 @@ var _ = Describe("Searchprovider", func() { Ref: &searchmsg.Reference{ ResourceId: &searchmsg.ResourceID{ StorageId: personalSpace.Root.StorageId, + SpaceId: personalSpace.Root.SpaceId, OpaqueId: personalSpace.Root.OpaqueId, }, Path: "./path/to/Foo.pdf", From d8905734a89097e8d5e1c5644f46869aa65b2295 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Duffeck?= Date: Mon, 1 Aug 2022 13:58:45 +0200 Subject: [PATCH 2/2] Add changelog --- changelog/unreleased/fix-search-in-received-shares.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 changelog/unreleased/fix-search-in-received-shares.md diff --git a/changelog/unreleased/fix-search-in-received-shares.md b/changelog/unreleased/fix-search-in-received-shares.md new file mode 100644 index 000000000..88bac6a23 --- /dev/null +++ b/changelog/unreleased/fix-search-in-received-shares.md @@ -0,0 +1,5 @@ +Bugfix: Fix search in received shares + +We fixed a problem where items in received shares were not found. + +https://github.com/owncloud/ocis/issues/4308