Skip to content

Commit

Permalink
fix: ocm invitation generation tests
Browse files Browse the repository at this point in the history
  • Loading branch information
fschade committed Sep 4, 2024
1 parent e67e3be commit 53fcee8
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 16 deletions.
7 changes: 7 additions & 0 deletions changelog/unreleased/ocm-generate-invite-event.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Enhancement: Publish an event when an OCM invite is generated

The ocm generate-invite endpoint now publishes an event whenever an invitation is requested and generated.
This event can be subscribed to by other services to react to the generated invitation.

https://github.com/cs3org/reva/pull/4832
https://github.com/owncloud/ocis/issues/9583
28 changes: 14 additions & 14 deletions internal/http/services/sciencemesh/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,18 +106,20 @@ func (h *tokenHandler) Generate(w http.ResponseWriter, r *http.Request) {
return
}

if err := events.Publish(ctx, h.eventStream, events.ScienceMeshInviteTokenGenerated{
Sharer: genTokenRes.GetInviteToken().GetUserId(),
RecipientMail: req.Recipient,
Token: tknRes.Token,
Description: tknRes.Description,
Expiration: tknRes.Expiration,
InviteLink: tknRes.InviteLink,
Timestamp: utils.TSNow(),
}); err != nil {
log := appctx.GetLogger(ctx)
log.Error().Err(err).
Msg("failed to publish the science-mesh invite token generated event")
if h.eventStream != nil {
if err := events.Publish(ctx, h.eventStream, events.ScienceMeshInviteTokenGenerated{
Sharer: genTokenRes.GetInviteToken().GetUserId(),
RecipientMail: req.Recipient,
Token: tknRes.Token,
Description: tknRes.Description,
Expiration: tknRes.Expiration,
InviteLink: tknRes.InviteLink,
Timestamp: utils.TSNow(),
}); err != nil {
log := appctx.GetLogger(ctx)
log.Error().Err(err).
Msg("failed to publish the science-mesh invite token generated event")
}
}

w.Header().Set("Content-Type", "application/json")
Expand All @@ -137,8 +139,6 @@ func getGenerateRequest(r *http.Request) (*generateRequest, error) {
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
return nil, err
}
} else {
return nil, errors.New("body request not recognised")
}

// validate the request
Expand Down
5 changes: 3 additions & 2 deletions tests/integration/grpc/ocm_invitation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,15 @@ import (
ocmproviderpb "github.com/cs3org/go-cs3apis/cs3/ocm/provider/v1beta1"
rpc "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1"
typesv1beta1 "github.com/cs3org/go-cs3apis/cs3/types/v1beta1"
"google.golang.org/grpc/metadata"

"github.com/cs3org/reva/v2/pkg/auth/scope"
ctxpkg "github.com/cs3org/reva/v2/pkg/ctx"
"github.com/cs3org/reva/v2/pkg/rgrpc/todo/pool"
"github.com/cs3org/reva/v2/pkg/token"
jwt "github.com/cs3org/reva/v2/pkg/token/manager/jwt"
"github.com/cs3org/reva/v2/pkg/token/manager/jwt"
"github.com/cs3org/reva/v2/pkg/utils"
"github.com/cs3org/reva/v2/pkg/utils/list"
"google.golang.org/grpc/metadata"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
Expand Down

0 comments on commit 53fcee8

Please sign in to comment.