msflib.account¶
Public modules of the msflib-account package.
msflib.account.actions
¶
AccountAction(*, settings: SettingsBase | None = None, profile_action: Optional[ProfileAction] = None)
¶
Bases: ModelAction[AccountType, AccountCreateType, AccountUpdateType], Generic[AccountType, AccountCreateType, AccountUpdateType]
resolve_workspace_context(session: Session, *, account: AccountType) -> dict[str, Any]
¶
Stub kept for backward compatibility.
Workspace-aware context resolution now lives in
msflib.workspaces.actions.WorkspaceAction.resolve_workspace_context.
Calling this on a plain AccountAction returns an empty context.
build_access_token_claims(session: Session, *, account: AccountType) -> dict[str, Any]
¶
Stub kept for backward compatibility. Returns an empty dict.
decorate_access_token_payload(session: Session, *, payload: dict[str, Any]) -> dict[str, Any]
¶
Stub kept for backward compatibility. Returns payload unchanged.
random(**overrides: dict[str, Any]) -> AccountCreateType
¶
Generate a random AccountCreate instance, respecting the fields of the schema.
msflib.account.config
¶
msflib.account.contracts
¶
Structural contracts (Protocols) exported by msflib.account.
These are lightweight interfaces that other modules can use to type-hint optional dependencies on account-adjacent concepts (e.g. workspaces) without requiring a hard package dependency on the module that owns the concrete model.
UserContract
¶
Bases: Protocol
Structural contract for user objects.
id, account_id, and workspace_id are required;
any concrete user model that exposes these attributes satisfies this contract.
WorkspaceContract
¶
Bases: Protocol
Structural contract for workspace objects.
Only id is required; any concrete workspace model that exposes an id
attribute satisfies this contract.
workspace
¶
Workspace integration contract.
Any workspace object passed into a router or action that does not want to declare
a hard dependency on msflib-workspaces should type-hint against this Protocol.
The concrete workspace model in msflib.workspaces satisfies this protocol
structurally; no explicit inheritance is required.
WorkspaceContract
¶
Bases: Protocol
Structural contract for workspace objects.
Only id is required; any concrete workspace model that exposes an id
attribute satisfies this contract.
UserContract
¶
Bases: Protocol
Structural contract for user objects.
id, account_id, and workspace_id are required;
any concrete user model that exposes these attributes satisfies this contract.
msflib.account.eventbus
¶
msflib.account.models
¶
msflib.account.router
¶
account_router(get_session: Callable, get_current_account: Callable, settings: SettingsBase, account_type: type[AccountBase], profile_type: type[ProfileBase], account_read_type: type[AccountRead] = AccountRead, account_create_type: type[Any] | None = None, account_action: ModelAction = None, profile_action: ModelAction = None, open_registration_path: str | None = None, unique_account_fields: list[str] | None = None, prefix: str = '/account', tags: list[str] | None = None)
¶
Create account router with dependencies.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
get_session
|
Callable
|
Callable to get the current session |
required |
get_current_account
|
Callable
|
Callable to get the current account |
required |
settings
|
SettingsBase
|
Application settings |
required |
account_type
|
type[AccountBase]
|
Account model type (default: Account) |
required |
account_read_type
|
type[AccountRead]
|
Account read schema type (default: AccountRead) |
AccountRead
|
account_create_type
|
type[Any] | None
|
Account create schema type for request validation (default: inferred from account action) |
None
|
account_action
|
ModelAction
|
Account action type (default: account_action) |
None
|
profile_action
|
ModelAction
|
Profile action type (default: profile_action) |
None
|
open_registration_path
|
str | None
|
Open registration endpoint path (default: ACCOUNT.OPEN_REGISTRATION_PATH or /open) |
None
|
prefix
|
str
|
The URL prefix for this router |
'/account'
|
tags
|
list[str] | None
|
List of tags for OpenAPI documentation |
None
|
unique_account_fields
|
list[str] | None
|
Account fields to check for uniqueness during create and update operations (default: AccountAction.DEFAULT_UNIQUE_FIELDS) |
None
|
account_admin_router(get_session: Callable, role_check: Callable, settings: SettingsBase, account_type: type[AccountBase], profile_type: type[ProfileBase], account_read_type: type[AccountRead] = AccountRead, account_create_type: type[Any] | None = None, account_action: ModelAction = None, profile_action: ModelAction = None, unique_account_fields: list[str] | None = None, prefix: str = '/admin/accounts', tags: list[str] | None = None)
¶
Create admin account router with dependencies.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
get_session
|
Callable
|
Callable to get the current session |
required |
role_check
|
Callable
|
Callable factory that returns role guard dependencies |
required |
settings
|
SettingsBase
|
Application settings |
required |
account_read_type
|
type[AccountRead]
|
Account read schema type (default: AccountRead) |
AccountRead
|
account_create_type
|
type[Any] | None
|
Account create schema type for request body validation (default: inferred from account action) |
None
|
unique_account_fields
|
list[str] | None
|
Account fields to check for uniqueness during create and update operations (default: AccountAction.DEFAULT_UNIQUE_FIELDS) |
None
|
prefix
|
str
|
The URL prefix for this router |
'/admin/accounts'
|
tags
|
list[str] | None
|
List of tags for OpenAPI documentation |
None
|
profile_router(get_session: Callable, get_current_account: Callable, get_current_active_account: Callable, settings: SettingsBase, profile_type: type[ProfileBase], account_type: type[AccountBase], profile_read_type: type[ProfileRead] = ProfileRead, profile_create_type: type[Any] | None = None, profile_update_type: type[Any] | None = None, profile_action: ModelAction = None, account_action: ModelAction = None, profile_decorator: ProfileDecorator = lambda session, profile: profile, prefix: str = '/profiles', tags: list[str] | None = None)
¶
Create profile router with dependencies.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
get_session
|
Callable
|
Callable to get the current session |
required |
get_current_account
|
Callable
|
Callable to get the current account |
required |
get_current_active_account
|
Callable
|
Callable to get the current active account |
required |
settings
|
SettingsBase
|
Application settings |
required |
profile_read_type
|
type[ProfileRead]
|
Profile read schema type (default: ProfileRead) |
ProfileRead
|
profile_create_type
|
type[Any] | None
|
Profile create schema type for request body validation (default: ProfileCreate) |
None
|
profile_update_type
|
type[Any] | None
|
Profile update schema type for request body validation (default: ProfileUpdate) |
None
|
profile_action
|
ModelAction
|
Profile action (default: pa) |
None
|
account_action
|
ModelAction
|
Account action (default: aa) |
None
|
prefix
|
str
|
The URL prefix for this router |
'/profiles'
|
tags
|
list[str] | None
|
List of tags for OpenAPI documentation |
None
|