Skip to content

Commit

Permalink
don't send event when result status is not OK (#2621)
Browse files Browse the repository at this point in the history
Signed-off-by: jkoberg <jkoberg@owncloud.com>
  • Loading branch information
kobergj authored Mar 8, 2022
1 parent e4509f1 commit b235e3d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
5 changes: 5 additions & 0 deletions changelog/unreleased/send-events-only-if-ok.md
Original file line number Diff line number Diff line change
@@ -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
5 changes: 4 additions & 1 deletion internal/grpc/interceptors/eventsmiddleware/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion pkg/events/example/example.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit b235e3d

Please sign in to comment.