audit-fix: загрузка пользователя в журнале аудита

This commit is contained in:
tsygankoviva 2026-06-04 10:25:13 +03:00
parent bf3896f2f0
commit 8e07135a16
3 changed files with 10 additions and 6 deletions

View File

@ -49,8 +49,8 @@ class AppUser(Base):
# back_populates="updater", # back_populates="updater",
# foreign_keys="RfProjectReport.updated_by", # foreign_keys="RfProjectReport.updated_by",
# ) # )
# audit_logs: Mapped[list["AuditLog"]] = relationship( # type: ignore audit_logs: Mapped[list["AuditLog"]] = relationship( # type: ignore
# "AuditLog", back_populates="user" "AuditLog", back_populates="user"
# ) )
user_orgs: Mapped[list["UserOrg"]] = relationship("UserOrg", 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) 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_type: Mapped[str] = mapped_column(String)
event_data: Mapped[dict | None] = mapped_column(JSON) event_data: Mapped[dict | None] = mapped_column(JSON)
# user: Mapped["AppUser | None"] = relationship( user: Mapped["AppUser | None"] = relationship(
# "AppUser", back_populates="audit_logs" "AppUser", back_populates="audit_logs"
# ) )
# org_unit: Mapped["OrgUnit | None"] = relationship( # org_unit: Mapped["OrgUnit | None"] = relationship(
# "OrgUnit", back_populates="audit_logs" # "OrgUnit", back_populates="audit_logs"
# ) # )

View File

@ -4,6 +4,8 @@ from typing import Iterable, Optional
from sqlalchemy import select from sqlalchemy import select
from sqlalchemy.ext.asyncio import AsyncSession from sqlalchemy.ext.asyncio import AsyncSession
from sqlalchemy.sql.functions import func from sqlalchemy.sql.functions import func
from sqlalchemy.orm import joinedload
# from sqlalchemy.orm import selectinload # from sqlalchemy.orm import selectinload
# from app.domain.models import AuditLog # from app.domain.models import AuditLog
@ -65,6 +67,8 @@ class AuditLogRepository:
if date_to is not None: if date_to is not None:
query = query.where(AuditLog.event_dt <= date_to) query = query.where(AuditLog.event_dt <= date_to)
query_count = query_count.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()) query = query.order_by(AuditLog.event_dt.desc())