Merge pull request #8936 from kobergj/FixInitiatorID

Fix InitiatorIDs for graph events
This commit is contained in:
kobergj authored and GitHub committed 2024-04-23 15:38:04 +02:00
commit 9242eae6db
2 files changed
+12 -4

No files matched your search

+1
View File
@@ -2,4 +2,5 @@ Enhancement: Initiator-IDs
Allows sending a header `Initiator-ID` on http requests. This id will be added to sse events so clients can figure out if their particular instance was triggering the event. Additionally this adds the etag of the file/folder to all sse events.
https://github.com/owncloud/ocis/pull/8936
https://github.com/owncloud/ocis/pull/8701
+11 -4
View File
@@ -7,6 +7,7 @@ import (
"google.golang.org/grpc/metadata"
"github.com/cs3org/reva/v2/pkg/auth/scope"
ctxpkg "github.com/cs3org/reva/v2/pkg/ctx"
revactx "github.com/cs3org/reva/v2/pkg/ctx"
"github.com/cs3org/reva/v2/pkg/token/manager/jwt"
"github.com/owncloud/ocis/v2/ocis-pkg/account"
@@ -75,14 +76,20 @@ func Auth(opts ...account.Option) func(http.Handler) http.Handler {
ctx = revactx.ContextSetToken(ctx, t)
ctx = revactx.ContextSetUser(ctx, u)
ctx = gmmetadata.Set(ctx, opkgm.AccountID, u.Id.OpaqueId)
if u.Opaque != nil && u.Opaque.Map != nil {
if roles, ok := u.Opaque.Map["roles"]; ok {
ctx = gmmetadata.Set(ctx, opkgm.RoleIDs, string(roles.Value))
ctx = gmmetadata.Set(ctx, opkgm.AccountID, u.GetId().GetOpaqueId())
if m := u.GetOpaque().GetMap(); m != nil {
if roles, ok := m["roles"]; ok {
ctx = gmmetadata.Set(ctx, opkgm.RoleIDs, string(roles.GetValue()))
}
}
ctx = metadata.AppendToOutgoingContext(ctx, revactx.TokenHeader, t)
initiatorID := r.Header.Get(ctxpkg.InitiatorHeader)
if initiatorID != "" {
ctx = ctxpkg.ContextSetInitiator(ctx, initiatorID)
ctx = metadata.AppendToOutgoingContext(ctx, ctxpkg.InitiatorHeader, initiatorID)
}
next.ServeHTTP(w, r.WithContext(ctx))
})
}