fix: attribute direct library prints to the authenticated user

The library POST /files/{file_id}/print endpoint discarded the
  authenticated user and passed requested_by_user_id=None to the
  dispatcher, so archives created from direct prints had no
  created_by_id and didn't show up in per-user statistics. Queue
  and reprint paths already forwarded the user correctly.

  Bind the auth dependency to current_user and pass its id/username
  through to dispatch_print_library_file, matching the reprint
  endpoint. The dispatcher already propagates this to
  printer_manager.set_current_print_user, which the archive
  creation reads.
This commit is contained in:
maziggy
2026-04-14 11:16:26 +02:00
parent d74ab06072
commit f03d0c4cf7
2 changed files with 4 additions and 3 deletions
+3 -3
View File
@@ -2169,7 +2169,7 @@ async def print_library_file(
printer_id: int,
body: FilePrintRequest | None = None,
db: AsyncSession = Depends(get_db),
_: User | None = Depends(require_permission_if_auth_enabled(Permission.PRINTERS_CONTROL)),
current_user: User | None = Depends(require_permission_if_auth_enabled(Permission.PRINTERS_CONTROL)),
):
"""Dispatch a library file for send/start on a printer.
@@ -2238,8 +2238,8 @@ async def print_library_file(
printer_name=printer.name,
options=body.model_dump(exclude_none=True),
project_id=body.project_id,
requested_by_user_id=None,
requested_by_username=None,
requested_by_user_id=current_user.id if current_user else None,
requested_by_username=current_user.username if current_user else None,
)
except DispatchEnqueueRejected as e:
raise HTTPException(status_code=409, detail=str(e)) from e