Repository: owncloud/ocis
Pull request #4308 (2022-08-01 12:00:39)

Fix search in received shares
It apparently broke as a fallout of the shareid refactoring in reva.

/cc @micbar @JanAckermann 


Patch:
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 00000000000..88bac6a23de
--- /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
diff --git a/services/search/pkg/search/provider/searchprovider.go b/services/search/pkg/search/provider/searchprovider.go
index a744699e6e2..719fa6a7b99 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,
 		})


Test patch:
diff --git a/services/search/pkg/search/provider/searchprovider_test.go b/services/search/pkg/search/provider/searchprovider_test.go
index 0badf5e715a..f16e6f6f1f8 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",