mirror of
https://github.com/SecurityBrewery/catalyst.git
synced 2025-12-08 08:12:48 +01:00
@@ -2,10 +2,9 @@ package busdb
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
|
||||
"github.com/SecurityBrewery/catalyst/generated/models"
|
||||
"github.com/SecurityBrewery/catalyst/generated/model"
|
||||
"github.com/SecurityBrewery/catalyst/role"
|
||||
)
|
||||
|
||||
@@ -14,21 +13,22 @@ const (
|
||||
groupContextKey = "groups"
|
||||
)
|
||||
|
||||
func SetContext(ctx *gin.Context, user *models.UserResponse) {
|
||||
func SetContext(r *http.Request, user *model.UserResponse) *http.Request {
|
||||
user.Roles = role.Strings(role.Explodes(user.Roles))
|
||||
ctx.Set(userContextKey, user)
|
||||
|
||||
return r.WithContext(context.WithValue(r.Context(), userContextKey, user))
|
||||
}
|
||||
|
||||
func SetGroupContext(ctx *gin.Context, groups []string) {
|
||||
ctx.Set(groupContextKey, groups)
|
||||
func SetGroupContext(r *http.Request, groups []string) *http.Request {
|
||||
return r.WithContext(context.WithValue(r.Context(), groupContextKey, groups))
|
||||
}
|
||||
|
||||
func UserContext(ctx context.Context, user *models.UserResponse) context.Context {
|
||||
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) (*models.UserResponse, bool) {
|
||||
u, ok := ctx.Value(userContextKey).(*models.UserResponse)
|
||||
func UserFromContext(ctx context.Context) (*model.UserResponse, bool) {
|
||||
u, ok := ctx.Value(userContextKey).(*model.UserResponse)
|
||||
return u, ok
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user