Skip to content

Conversation

@CK-7vn
Copy link
Member

@CK-7vn CK-7vn commented Dec 4, 2025

Description of the change

This ticket implements the ability for administrators to export singular user attendance for both active and deactivated residents.

Screenshot(s)

image image

Additional context

Backend Changes:

  • Added ResidentAttendanceCSVData struct and ResidentAttendanceToCSVFormat() function to backend/src/models/users.go
  • Added GetResidentAttendanceCSVData() database query to backend/src/database/users.go
  • Added GET /api/users/{id}/attendance-export endpoint in backend/src/handlers/user_handler.go
  • Added LoginMetrics to test migrations in backend/src/database/DB.go

Frontend Changes:

  • Added 'Export Attendance' to ResidentAccountAction enum in frontend/src/common.ts
  • Added "Export Attendance" action to UserActionsDropdown.tsx (visible for both active and deactivated residents)
  • Added downloadAttendanceExport() handler in frontend/src/Pages/ResidentProfile.tsx

CSV Output:

  • Headers: Program Name, Class Name, Session Date, Attendance Status, Note
  • Sorted by Program (alphabetical) → Class (alphabetical) → Date (chronological)
  • Attendance statuses displayed as: Present, Absent Excused, Absent Unexcused

Security Features:

  • Uses validatedAdminRoute with UserRoleResolver middleware (same auth as viewing profile)
  • Facility admins can only export attendance for residents in their own facility
  • Students cannot access this endpoint
  • Audit logging captures user_id and rows_exported

Edge Cases Handled:

  • No attendance records: Returns CSV with headers only
  • Deactivated residents: Can still export historical attendance (button remains visible)
  • Enrollment date filtering: Only includes attendance recorded during active enrollment period

Integration Tests Added:

  • backend/tests/integration/user_attendance_export_test.go with 8 test scenarios covering:
    • Successful CSV export with data
    • Facility boundary enforcement
    • Empty attendance records
    • Deactivated resident export
    • Enrollment date filtering
    • CSV sorting validation
    • Student role access denial

Decisions Made:

  • Export only sessions with recorded attendance (not all sessions during enrollment) - simpler and more performant
  • No success toast after download trigger - the browser's download dialog provides sufficient feedback
  • Button visible for deactivated residents to allow historical data access

Known Limitations:

  • CSV export only (PDF format not implemented)
  • No date range filtering (exports all historical attendance)

@CK-7vn CK-7vn requested a review from a team as a code owner December 4, 2025 05:13
@CK-7vn CK-7vn requested review from calisio and removed request for a team December 4, 2025 05:13
Copy link
Member Author

CK-7vn commented Dec 4, 2025

The vulnerability in the provider middleware is inside of the standard library, the only way we can fix it is upgrading our Go version, which is done in the reports ticket to 1.25, which doens't have the vulnerability, so....Don't know how everyone wnats to go about that, just wait for the reports PR to get merged?

@carddev81 carddev81 requested review from carddev81 and corypride and removed request for calisio December 10, 2025 17:42
Copy link
Contributor

@carddev81 carddev81 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested good and looks great!! Good job!

Copy link
Contributor

@corypride corypride left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests good.

@CK-7vn CK-7vn merged commit 80b2e3b into main Jan 5, 2026
10 checks passed
@CK-7vn CK-7vn deleted the CK-7vn/id-533 branch January 5, 2026 19:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants