Documentation
¶
Index ¶
- Variables
- func GetCurrentTenantID(ctx context.Context) (string, error)
- func GetCurrentUserID(ctx context.Context) (string, error)
- func HasPermission(ctx context.Context, permission string) bool
- func HasRole(ctx context.Context, role string) bool
- func IsAuthenticated(ctx context.Context) bool
- func IsSuperAdmin(ctx context.Context) bool
- func IsTenantAdmin(ctx context.Context) bool
- func RequirePermission(ctx context.Context, permission string) error
- type PermissionChecker
- func (pc *PermissionChecker) HasAllPermissions(ctx context.Context, permissions ...string) bool
- func (pc *PermissionChecker) HasAnyPermission(ctx context.Context, permissions ...string) bool
- func (pc *PermissionChecker) HasAnyRole(ctx context.Context, roles ...string) bool
- func (pc *PermissionChecker) HasPermission(ctx context.Context, permission string) bool
- func (pc *PermissionChecker) HasRole(ctx context.Context, role string) bool
- func (pc *PermissionChecker) IsSuperAdmin(ctx context.Context) bool
- func (pc *PermissionChecker) IsTenantAdmin(ctx context.Context) bool
- func (pc *PermissionChecker) RequirePermission(ctx context.Context, permission string) error
- type UserInfo
Constants ¶
This section is empty.
Variables ¶
var ( ErrPermissionDenied = errors.New("permission denied") ErrNoPermissions = errors.New("no permissions found") )
var GlobalPermissionChecker = NewPermissionChecker()
Global permission checker instance
Functions ¶
func GetCurrentTenantID ¶
GetCurrentTenantID retrieves current tenant ID
func GetCurrentUserID ¶
GetCurrentUserID retrieves current user ID
func HasPermission ¶
Helper functions using global checker
func IsAuthenticated ¶
IsAuthenticated checks if user is authenticated
func IsSuperAdmin ¶
func IsTenantAdmin ¶
Types ¶
type PermissionChecker ¶
type PermissionChecker struct{}
PermissionChecker provides permission checking functionality
func NewPermissionChecker ¶
func NewPermissionChecker() *PermissionChecker
NewPermissionChecker creates a new permission checker
func (*PermissionChecker) HasAllPermissions ¶
func (pc *PermissionChecker) HasAllPermissions(ctx context.Context, permissions ...string) bool
HasAllPermissions checks if user has all of the specified permissions
func (*PermissionChecker) HasAnyPermission ¶
func (pc *PermissionChecker) HasAnyPermission(ctx context.Context, permissions ...string) bool
HasAnyPermission checks if user has any of the specified permissions
func (*PermissionChecker) HasAnyRole ¶
func (pc *PermissionChecker) HasAnyRole(ctx context.Context, roles ...string) bool
HasAnyRole checks if user has any of the specified roles
func (*PermissionChecker) HasPermission ¶
func (pc *PermissionChecker) HasPermission(ctx context.Context, permission string) bool
HasPermission checks if user has a specific permission
func (*PermissionChecker) HasRole ¶
func (pc *PermissionChecker) HasRole(ctx context.Context, role string) bool
HasRole checks if user has a specific role
func (*PermissionChecker) IsSuperAdmin ¶
func (pc *PermissionChecker) IsSuperAdmin(ctx context.Context) bool
IsSuperAdmin checks if user is super admin
func (*PermissionChecker) IsTenantAdmin ¶
func (pc *PermissionChecker) IsTenantAdmin(ctx context.Context) bool
IsTenantAdmin checks if user is tenant admin
func (*PermissionChecker) RequirePermission ¶
func (pc *PermissionChecker) RequirePermission(ctx context.Context, permission string) error
RequirePermission checks permission and returns error if not authorized
type UserInfo ¶
UserInfo represents current user information
func GetCurrentUser ¶
GetCurrentUser retrieves current user info from context
func MustGetCurrentUser ¶
MustGetCurrentUser retrieves current user or panics