user

package
v0.0.0-...-31d061a Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 19, 2024 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RolePublic       = "public"
	RoleRegistered   = "registered"
	RoleBCCMember    = "bcc-members"
	RoleNonBCCMember = "non-bcc-members"
)

All well-known roles as used in the DB

View Source
const (
	CtxUser          = "ctx-user"
	CacheRoles       = "roles"
	CtxLanguages     = "ctx-languages"
	CtxImpersonating = "ctx-impersonating"
	CtxProfiles      = "ctx-profiles"
	CtxProfile       = "ctx-profile"
)

Various hardcoded keys

View Source
const CtxRoles = "roles"

CtxRoles context key for roles

Variables

View Source
var (
	ErrItemNotPublished    = common.ErrItemNotPublished
	ErrItemNoAccess        = common.ErrItemNoAccess
	ErrPublishDateInFuture = merry.Sentinel("Publish date in the future")
)

Sentinel errors

View Source
var AgeGroups = map[int]string{
	65: "65+",
	51: "51 - 64",
	37: "37 - 50",
	26: "26 - 36",
	19: "19 - 25",
	13: "13 - 18",
	10: "10 - 12",
	0:  "0 - 9",
}

AgeGroups contains the different age groups keyed by the minimum age.

Functions

func GetAcceptedLanguagesFromCtx

func GetAcceptedLanguagesFromCtx(ctx *gin.Context) []string

GetAcceptedLanguagesFromCtx as sent by the user

func GetFromCtx

func GetFromCtx(ctx *gin.Context) *common.User

GetFromCtx gets the user stored in the context by the middleware

func GetLanguagesFromCtx

func GetLanguagesFromCtx(ctx *gin.Context) []string

GetLanguagesFromCtx as provided in the request

func GetProfileFromCtx

func GetProfileFromCtx(ctx *gin.Context) *common.Profile

GetProfileFromCtx returns the current profile

func GetProfilesFromCtx

func GetProfilesFromCtx(ctx *gin.Context) []common.Profile

GetProfilesFromCtx returns the current profile

func GetRolesFromCtx

func GetRolesFromCtx(ctx *gin.Context) []string

GetRolesFromCtx returns the roles stored in context

func ValidateAccess

func ValidateAccess[k comparable](
	ctx context.Context,
	permissionLoader *loaders.Loader[k, *common.Permissions[k]],
	id k,
	conditions CheckConditions,
) error

ValidateAccess returns error if user in context does not have access to the specified item

Types

type CheckConditions

type CheckConditions struct {
	FromDate    bool
	PublishDate bool
	Download    bool
}

CheckConditions defines which conditions that should be checked

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL