From b235e3dd0f49112170c6e69e63892f0e38f0a552 Mon Sep 17 00:00:00 2001 From: kobergj Date: Tue, 8 Mar 2022 16:05:53 +0100 Subject: [PATCH] don't send event when result status is not OK (#2621) Signed-off-by: jkoberg --- changelog/unreleased/send-events-only-if-ok.md | 5 +++++ internal/grpc/interceptors/eventsmiddleware/events.go | 5 ++++- pkg/events/example/example.go | 2 +- 3 files changed, 10 insertions(+), 2 deletions(-) create mode 100644 changelog/unreleased/send-events-only-if-ok.md diff --git a/changelog/unreleased/send-events-only-if-ok.md b/changelog/unreleased/send-events-only-if-ok.md new file mode 100644 index 0000000000..9be6db465a --- /dev/null +++ b/changelog/unreleased/send-events-only-if-ok.md @@ -0,0 +1,5 @@ +Bugfix: send events only if response code is `OK` + +Before events middleware was sending events also when the resulting status code was not `OK`. This is clearly a bug. + +https://github.com/cs3org/reva/pull/2621 diff --git a/internal/grpc/interceptors/eventsmiddleware/events.go b/internal/grpc/interceptors/eventsmiddleware/events.go index 7f484b4386..d9c05890fe 100644 --- a/internal/grpc/interceptors/eventsmiddleware/events.go +++ b/internal/grpc/interceptors/eventsmiddleware/events.go @@ -26,6 +26,7 @@ import ( "google.golang.org/grpc" "github.com/asim/go-micro/plugins/events/nats/v4" + rpc "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1" collaboration "github.com/cs3org/go-cs3apis/cs3/sharing/collaboration/v1beta1" "github.com/cs3org/reva/v2/pkg/events" "github.com/cs3org/reva/v2/pkg/events/server" @@ -58,7 +59,9 @@ func NewUnary(m map[string]interface{}) (grpc.UnaryServerInterceptor, int, error var ev interface{} switch v := res.(type) { case *collaboration.CreateShareResponse: - ev = ShareCreated(v) + if v.Status.Code == rpc.Code_CODE_OK { + ev = ShareCreated(v) + } } if ev != nil { diff --git a/pkg/events/example/example.go b/pkg/events/example/example.go index f84b377411..05fdcffa4c 100644 --- a/pkg/events/example/example.go +++ b/pkg/events/example/example.go @@ -61,7 +61,7 @@ func Server() { // Client builds a nats client func Client() events.Stream { - c, err := server.NewNatsStream(nats.Address("127.0.0.1:4222"), nats.ClusterID("test-cluster")) + c, err := server.NewNatsStream(nats.Address("127.0.0.1:9233"), nats.ClusterID("test-cluster")) if err != nil { log.Fatal(err) }