Merge pull request #4308 from aduffeck/fix-search-in-received-shares

Fix search in received shares
This commit is contained in:
Andre Duffeck
2022-08-02 09:11:32 +02:00
committed by GitHub
3 changed files with 25 additions and 10 deletions

View File

@@ -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

View File

@@ -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,
})

View File

@@ -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",