Merge pull request 'audit-fix: загрузка пользователя в журнале аудита' (#29) from audit-fix into test

Reviewed-on: #29
Reviewed-by: Raykov-MS <RaykovMS@avt.rshb.ru>
This commit is contained in:
tsygankoviva 2026-06-04 10:28:07 +03:00
commit b6a7ae509e
3 changed files with 10 additions and 6 deletions

View File

@ -49,8 +49,8 @@ class AppUser(Base):
# back_populates="updater",
# foreign_keys="RfProjectReport.updated_by",
# )
# audit_logs: Mapped[list["AuditLog"]] = relationship( # type: ignore
# "AuditLog", back_populates="user"
# )
audit_logs: Mapped[list["AuditLog"]] = relationship( # type: ignore
"AuditLog", back_populates="user"
)
user_orgs: Mapped[list["UserOrg"]] = relationship("UserOrg", back_populates="user")
org_units: Mapped[list["OrgUnit"]] = relationship("OrgUnit", secondary="v3.user_org", viewonly=True)

View File

@ -55,9 +55,9 @@ class AuditLog(Base):
event_type: Mapped[str] = mapped_column(String)
event_data: Mapped[dict | None] = mapped_column(JSON)
# user: Mapped["AppUser | None"] = relationship(
# "AppUser", back_populates="audit_logs"
# )
user: Mapped["AppUser | None"] = relationship(
"AppUser", back_populates="audit_logs"
)
# org_unit: Mapped["OrgUnit | None"] = relationship(
# "OrgUnit", back_populates="audit_logs"
# )

View File

@ -4,6 +4,8 @@ from typing import Iterable, Optional
from sqlalchemy import select
from sqlalchemy.ext.asyncio import AsyncSession
from sqlalchemy.sql.functions import func
from sqlalchemy.orm import joinedload
# from sqlalchemy.orm import selectinload
# from app.domain.models import AuditLog
@ -66,6 +68,8 @@ class AuditLogRepository:
query = query.where(AuditLog.event_dt <= date_to)
query_count = query_count.where(AuditLog.event_dt <= date_to)
query = query.options(joinedload(AuditLog.user))
query = query.order_by(AuditLog.event_dt.desc())
if limit is not None: