Merge pull request #4012 from aduffeck/handle-file-touched-events

Handle file touched events
This commit is contained in:
Michael Barz
2022-06-23 15:27:16 +02:00
committed by GitHub
6 changed files with 37 additions and 7 deletions

View File

@@ -91,6 +91,11 @@ func (p *Provider) handleEvent(ev interface{}) {
owner = &user.User{
Id: e.Executant,
}
case events.FileTouched:
ref = e.Ref
owner = &user.User{
Id: e.Executant,
}
case events.FileVersionRestored:
ref = e.Ref
owner = &user.User{

View File

@@ -95,6 +95,23 @@ var _ = Describe("Searchprovider", func() {
}, "2s").Should(BeTrue())
})
It("triggers an index update when a file has been touched", func() {
called := false
indexClient.On("Add", mock.Anything, mock.MatchedBy(func(riToIndex *sprovider.ResourceInfo) bool {
return riToIndex.Id.OpaqueId == ri.Id.OpaqueId
})).Return(nil).Run(func(args mock.Arguments) {
called = true
})
eventsChan <- events.FileTouched{
Ref: ref,
Executant: user.Id,
}
Eventually(func() bool {
return called
}, "2s").Should(BeTrue())
})
It("removes an entry from the index when the file has been deleted", func() {
called := false
gwClient.On("Stat", mock.Anything, mock.Anything).Return(&sprovider.StatResponse{

View File

@@ -14,6 +14,7 @@ import (
provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
ctxpkg "github.com/cs3org/reva/v2/pkg/ctx"
"github.com/cs3org/reva/v2/pkg/errtypes"
"github.com/cs3org/reva/v2/pkg/events"
sdk "github.com/cs3org/reva/v2/pkg/sdk/common"
"github.com/cs3org/reva/v2/pkg/storage/utils/walker"
"github.com/cs3org/reva/v2/pkg/storagespace"
@@ -26,6 +27,16 @@ import (
searchsvc "github.com/owncloud/ocis/v2/protogen/gen/ocis/services/search/v0"
)
var ListenEvents = []events.Unmarshaller{
events.ItemTrashed{},
events.ItemRestored{},
events.ItemMoved{},
events.ContainerCreated{},
events.FileUploaded{},
events.FileTouched{},
events.FileVersionRestored{},
}
type Provider struct {
logger log.Logger
gwClient gateway.GatewayAPIClient

View File

@@ -14,7 +14,6 @@ import (
"go-micro.dev/v4/metadata"
grpcmetadata "google.golang.org/grpc/metadata"
"github.com/owncloud/ocis/v2/extensions/audit/pkg/types"
"github.com/owncloud/ocis/v2/extensions/search/pkg/config"
"github.com/owncloud/ocis/v2/extensions/search/pkg/search"
"github.com/owncloud/ocis/v2/extensions/search/pkg/search/index"
@@ -38,7 +37,7 @@ func NewHandler(opts ...Option) (searchsvc.SearchProviderHandler, error) {
if err != nil {
return nil, err
}
evts, err := events.Consume(client, evtsCfg.ConsumerGroup, types.RegisteredEvents()...)
evts, err := events.Consume(client, evtsCfg.ConsumerGroup, searchprovider.ListenEvents...)
if err != nil {
return nil, err
}

2
go.mod
View File

@@ -10,7 +10,7 @@ require (
github.com/blevesearch/bleve_index_api v1.0.2
github.com/coreos/go-oidc/v3 v3.2.0
github.com/cs3org/go-cs3apis v0.0.0-20220512100524-551800f020d8
github.com/cs3org/reva/v2 v2.6.0
github.com/cs3org/reva/v2 v2.6.1-0.20220622100918-317fb93c2990
github.com/disintegration/imaging v1.6.2
github.com/go-chi/chi/v5 v5.0.7
github.com/go-chi/cors v1.2.1

6
go.sum
View File

@@ -294,10 +294,8 @@ github.com/crewjam/httperr v0.2.0/go.mod h1:Jlz+Sg/XqBQhyMjdDiC+GNNRzZTD7x39Gu3p
github.com/crewjam/saml v0.4.6 h1:XCUFPkQSJLvzyl4cW9OvpWUbRf0gE7VUpU8ZnilbeM4=
github.com/crewjam/saml v0.4.6/go.mod h1:ZBOXnNPFzB3CgOkRm7Nd6IVdkG+l/wF+0ZXLqD96t1A=
github.com/cs3org/cato v0.0.0-20200828125504-e418fc54dd5e/go.mod h1:XJEZ3/EQuI3BXTp/6DUzFr850vlxq11I6satRtz0YQ4=
github.com/cs3org/reva/v2 v2.5.2-0.20220621133128-d90c8aa60a15 h1:isQbNMNY9PSWy0CWT1KQIdCyD85XUdu6Ww1HjIuR6uc=
github.com/cs3org/reva/v2 v2.5.2-0.20220621133128-d90c8aa60a15/go.mod h1:zAHqzr36X4lIalonDQeNbwrIXjn66C38lp5A+MTRS1c=
github.com/cs3org/reva/v2 v2.6.0 h1:h+QYJWhDFqONsfgLXjHXKRyPJLhyNUR6oYaTkR5I3gg=
github.com/cs3org/reva/v2 v2.6.0/go.mod h1:zAHqzr36X4lIalonDQeNbwrIXjn66C38lp5A+MTRS1c=
github.com/cs3org/reva/v2 v2.6.1-0.20220622100918-317fb93c2990 h1:xjbf0G+Xq3fYkv7eJYwMBIPI3N+tr1nqOz7Kn2/dkAQ=
github.com/cs3org/reva/v2 v2.6.1-0.20220622100918-317fb93c2990/go.mod h1:zAHqzr36X4lIalonDQeNbwrIXjn66C38lp5A+MTRS1c=
github.com/cubewise-code/go-mime v0.0.0-20200519001935-8c5762b177d8 h1:Z9lwXumT5ACSmJ7WGnFl+OMLLjpz5uR2fyz7dC255FI=
github.com/cubewise-code/go-mime v0.0.0-20200519001935-8c5762b177d8/go.mod h1:4abs/jPXcmJzYoYGF91JF9Uq9s/KL5n1jvFDix8KcqY=
github.com/cyberdelia/templates v0.0.0-20141128023046-ca7fffd4298c/go.mod h1:GyV+0YP4qX0UQ7r2MoYZ+AvYDp12OF5yg4q8rGnyNh4=