services#

Admin audit logging and aggregate dashboard query services.

Admin domain services.

class app.domain.admin.services.AuditLogService(session: ~sqlalchemy.ext.asyncio.session.AsyncSession | ~sqlalchemy.ext.asyncio.scoping.async_scoped_session[~sqlalchemy.ext.asyncio.session.AsyncSession], *, statement: ~sqlalchemy.sql.selectable.Select | None = None, model_type: type[~advanced_alchemy.repository.typing.ModelT] | None = None, repository_type: type[~advanced_alchemy.repository.typing.SQLAlchemyAsyncRepositoryT] | None = None, auto_expunge: bool = False, auto_refresh: bool = True, auto_commit: bool = False, order_by: ~typing.List[tuple[str | ~sqlalchemy.orm.attributes.InstrumentedAttribute[~typing.Any], bool] | ~sqlalchemy.sql.elements.UnaryExpression[~typing.Any]] | tuple[str | ~sqlalchemy.orm.attributes.InstrumentedAttribute[~typing.Any], bool] | ~sqlalchemy.sql.elements.UnaryExpression[~typing.Any] | None = None, error_messages: ~advanced_alchemy.exceptions.ErrorMessages | type[~advanced_alchemy.utils.dataclass.Empty] | None = <class 'advanced_alchemy.utils.dataclass.Empty'>, wrap_exceptions: bool = True, load: ~collections.abc.Sequence[~sqlalchemy.orm.interfaces.LoaderOption | ~typing.Literal['*'] | ~sqlalchemy.orm.attributes.InstrumentedAttribute[~typing.Any] | ~sqlalchemy.orm.relationships.RelationshipProperty[~typing.Any] | ~sqlalchemy.orm.interfaces.MapperProperty[~typing.Any] | ~collections.abc.Sequence[~sqlalchemy.orm.interfaces.LoaderOption | ~typing.Literal['*'] | ~sqlalchemy.orm.attributes.InstrumentedAttribute[~typing.Any] | ~sqlalchemy.orm.relationships.RelationshipProperty[~typing.Any] | ~sqlalchemy.orm.interfaces.MapperProperty[~typing.Any]]] | ~sqlalchemy.orm.interfaces.LoaderOption | ~typing.Literal['*'] | ~sqlalchemy.orm.attributes.InstrumentedAttribute[~typing.Any] | ~sqlalchemy.orm.relationships.RelationshipProperty[~typing.Any] | ~sqlalchemy.orm.interfaces.MapperProperty[~typing.Any] | ~sqlalchemy.sql.base.ExecutableOption | ~collections.abc.Sequence[~sqlalchemy.sql.base.ExecutableOption] | None = None, execution_options: dict[str, ~typing.Any] | None = None, uniquify: bool | None = None, count_with_window_function: bool | None = None, **repo_kwargs: ~typing.Any)[source]#

Bases: SQLAlchemyAsyncRepositoryService[AuditLog, Any]

Service for recording and querying application audit log entries.

Configure the service object.

Parameters:
  • session – Session managing the unit-of-work for the operation.

  • statement – To facilitate customization of the underlying select query.

  • model_type – Optional SQLAlchemy model type when instantiating directly without subclassing.

  • repository_type – Optional repository class override when instantiating directly.

  • auto_expunge – Remove object from session before returning.

  • auto_refresh – Refresh object from session before returning.

  • auto_commit – Commit objects before returning.

  • order_by – Set default order options for queries.

  • error_messages – A set of custom error messages to use for operations

  • wrap_exceptions – Wrap exceptions in a RepositoryError

  • load – Set default relationships to be loaded

  • execution_options – Set default execution options

  • uniquify – Optionally apply the unique() method to results before returning.

  • count_with_window_function – When false, list and count will use two queries instead of an analytical window function. Defaults to True in 1.x (planned to change to False in v2.0).

  • **repo_kwargs – passed as keyword args to repo instantiation.

async log_action(action: str, actor_id: UUID | None = None, actor_email: str | None = None, target_type: str | None = None, target_id: str | None = None, target_label: str | None = None, details: dict[str, Any] | None = None, ip_address: str | None = None, user_agent: str | None = None, request: Request[Any, Any, Any] | None = None) → m.AuditLog[source]#

Create and persist a new audit log entry.

Returns:

The persisted AuditLog record.

async log_admin_user_update(*, actor_id: UUID, actor_email: str | None, user_id: UUID, user_email: str, changes: list[str], request: Request[Any, Any, Any] | None = None) → m.AuditLog[source]#

Log an admin user update event.

Returns:

The persisted AuditLog record.

async log_admin_user_delete(*, actor_id: UUID, actor_email: str | None, user_id: UUID, user_email: str, request: Request[Any, Any, Any] | None = None) → m.AuditLog[source]#

Log an admin user deletion event.

Returns:

The persisted AuditLog record.

async log_admin_team_update(*, actor_id: UUID, actor_email: str | None, team_id: UUID, team_name: str, changes: list[str], request: Request[Any, Any, Any] | None = None) → m.AuditLog[source]#

Log an admin team update event.

Returns:

The persisted AuditLog record.

async log_admin_team_delete(*, actor_id: UUID, actor_email: str | None, team_id: UUID, team_name: str, request: Request[Any, Any, Any] | None = None) → m.AuditLog[source]#

Log an admin team deletion event.

Returns:

The persisted AuditLog record.

async find_logs(*filters: StatementFilter | ColumnElement[bool], action: str | None = None, end_date: datetime | None = None) → tuple[Sequence[m.AuditLog], int][source]#

Find audit logs matching filters, optionally narrowed to one action and to entries up to end_date.

Returns:

The matching audit logs and their total count before pagination.

repository_type#

alias of AuditLogRepository

class app.domain.admin.services.DashboardQueryService(session: AsyncSession | async_scoped_session[AsyncSession], **repo_kwargs: Any)[source]#

Bases: SQLAlchemyAsyncQueryService

Computes admin dashboard statistics via parameterized SQL aggregate queries.

Configure the service object.

Parameters:
  • session – Session managing the unit-of-work for the operation.

  • **repo_kwargs – Optional configuration values to pass into the repository

async get_stats(*, now: datetime | None = None) → DashboardStats[source]#

Execute parameterized aggregate counts for users, teams, and 24-hour audit events.

Returns:

Aggregated dashboard statistics snapshot.