mirror of
https://github.com/SecurityBrewery/catalyst.git
synced 2025-12-09 16:52:51 +01:00
@@ -1,38 +0,0 @@
|
||||
package busdb
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
|
||||
"github.com/SecurityBrewery/catalyst/generated/model"
|
||||
"github.com/SecurityBrewery/catalyst/role"
|
||||
)
|
||||
|
||||
type contextKey string
|
||||
|
||||
const (
|
||||
userContextKey contextKey = "user"
|
||||
groupContextKey contextKey = "groups"
|
||||
)
|
||||
|
||||
func SetContext(r *http.Request, user *model.UserResponse) *http.Request {
|
||||
user.Roles = role.Strings(role.Explodes(user.Roles))
|
||||
|
||||
return r.WithContext(context.WithValue(r.Context(), userContextKey, user))
|
||||
}
|
||||
|
||||
func SetGroupContext(r *http.Request, groups []string) *http.Request {
|
||||
return r.WithContext(context.WithValue(r.Context(), groupContextKey, groups))
|
||||
}
|
||||
|
||||
func UserContext(ctx context.Context, user *model.UserResponse) context.Context {
|
||||
user.Roles = role.Strings(role.Explodes(user.Roles))
|
||||
|
||||
return context.WithValue(ctx, userContextKey, user)
|
||||
}
|
||||
|
||||
func UserFromContext(ctx context.Context) (*model.UserResponse, bool) {
|
||||
u, ok := ctx.Value(userContextKey).(*model.UserResponse)
|
||||
|
||||
return u, ok
|
||||
}
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/arangodb/go-driver"
|
||||
maut "github.com/jonas-plum/maut/auth"
|
||||
|
||||
"github.com/SecurityBrewery/catalyst/bus"
|
||||
"github.com/SecurityBrewery/catalyst/generated/model"
|
||||
@@ -15,7 +16,7 @@ import (
|
||||
const LogCollectionName = "logs"
|
||||
|
||||
func (db *BusDatabase) LogCreate(ctx context.Context, logType, reference, message string) (*model.LogEntry, error) {
|
||||
user, ok := UserFromContext(ctx)
|
||||
user, _, ok := maut.UserFromContext(ctx)
|
||||
if !ok {
|
||||
return nil, errors.New("no user in context")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user