flask_more_smorest.perms.models.role
Role and domain models for Flask-More-Smorest.
Provides BaseRoleEnum, Domain, and UserRole models for multi-domain role-based access control.
Classes
|
Distinct domains within the app for multi-domain support. |
|
User roles with domain scoping for multi-domain applications. |
- class flask_more_smorest.perms.models.role.BaseRoleEnum(*values)[source]
Default user role enumeration.
Values are uppercase for backward compatibility with applications expecting uppercase role strings.
- SUPERADMIN = 'SUPERADMIN'
- ADMIN = 'ADMIN'
- USER = 'USER'
- class flask_more_smorest.perms.models.role.Domain(**kwargs)[source]
Distinct domains within the app for multi-domain support.
This is a concrete implementation of AbstractDomain. For customization, subclass AbstractDomain instead of this class.
- classmethod get_default_domain_id()[source]
Get the default domain ID from environment or first available.
- __init__(**kwargs)
Initialize model after checking sub-fields can be created.
- created_at
- id
- updated_at
- class flask_more_smorest.perms.models.role.UserRole(domain_id=None, role=None, **kwargs)[source]
User roles with domain scoping for multi-domain applications.
To use custom role enums, simply pass enum values when creating roles:
- class CustomRole(str, enum.Enum):
SUPERADMIN = “superadmin” ADMIN = “admin” MANAGER = “manager” USER = “user”
# Create roles with custom enum values role = UserRole(user=user, role=CustomRole.MANAGER)
# The role property will return the string value, which can be # converted back to your custom enum as needed: manager_role = CustomRole(role.role) if hasattr(CustomRole, role.role) else role.role
- __init__(domain_id=None, role=None, **kwargs)
Initialize role with domain and role handling.
- Parameters:
domain_id – Domain UUID or ‘*’ for all domains
role – Role value (enum or string)
**kwargs – Additional field values
- created_at
- domain
- id
- updated_at
- user