Add session auth views and enforce permission-based update/delete booking operations - #408
Conversation
Agent-Logs-Url: https://github.com/conorheffron/booking-sys/sessions/68e96142-58a7-4d10-b953-75190aeba1df Co-authored-by: conorheffron <8218626+conorheffron@users.noreply.github.com>
Agent-Logs-Url: https://github.com/conorheffron/booking-sys/sessions/68e96142-58a7-4d10-b953-75190aeba1df Co-authored-by: conorheffron <8218626+conorheffron@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR introduces session-based authentication endpoints on the Django backend and updates the React frontend to support login/logout flows and to restrict booking mutation actions (edit/delete) to authenticated users.
Changes:
- Backend: adds
/api/auth/status,/api/auth/login,/api/auth/logout, and enforces authentication onPUT/DELETEforbookings_by_id. - Frontend: adds
LoginPage/LogoutPage, route-guards edit routes, and gates edit/delete UI based on auth status. - Tests: expands backend API tests for the new auth contract and adds frontend tests for login/logout and auth-aware UI.
Reviewed changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| frontend/src/pages/ReservationsPage.tsx | Fetches auth status and gates edit/delete actions in the reservations list UI. |
| frontend/src/pages/LoginPage.tsx | Adds login form that calls session-auth login endpoint and redirects after success. |
| frontend/src/pages/LogoutPage.tsx | Adds logout flow that calls session-auth logout endpoint and redirects home. |
| frontend/src/pages/tests/Reservationspage.test.tsx | Adds/updates reservations page tests to cover unauthenticated gating behavior. |
| frontend/src/pages/tests/LoginPage.test.tsx | Adds login page tests for success navigation and error rendering. |
| frontend/src/pages/tests/LogoutPage.test.tsx | Adds logout page tests for logout call + redirect and error display. |
| frontend/src/main.tsx | Adds /login and /logout routes and a RequireAuth guard for edit route. |
| frontend/src/components/Navbar.tsx | Displays Login/Logout link based on auth status. |
| frontend/src/components/auth.ts | Adds frontend API helpers for auth status/login/logout using cookie credentials. |
| frontend/src/components/tests/Navbar.test.tsx | Updates navbar tests to validate Login vs Logout rendering. |
| backend/hr/views.py | Implements auth status/login/logout handlers and requires auth for update/delete booking operations. |
| backend/hr/urls.py | Registers the new /api/auth/* endpoints. |
| backend/hr/test_apis.py | Updates API tests for authenticated mutations and adds tests for the auth endpoints. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
|
@copilot resolve the merge conflicts in this pull request |
Merge conflicts resolved. The conflicts were in 4 files:
The resolution adopts main's more robust permission system ( |
|
@copilot resolve the merge conflicts in this pull request |
|
@copilot resolve the merge conflicts in this pull request |
Merged both auth features (login/logout/status) and current_user endpoint from main. Resolved conflicts in: - backend/hr/views.py: kept both auth methods and current_user method - backend/hr/test_apis.py: kept both auth tests and current_user tests - frontend/src/components/Navbar.tsx: combined auth status and user dropdown - frontend/src/components/__tests__/Navbar.test.tsx: combined all tests - frontend/src/pages/__tests__/Reservationspage.test.tsx: added MemoryRouter wrapper
Merge conflicts resolved. The conflicts were in 4 files:
Also fixed |
|
@copilot resolve the merge conflicts in this pull request |
Merged clear-all reservations feature from main with auth-gated operations: - backend/hr/test_apis.py: added clear-all user fixtures alongside auth user - frontend/src/pages/ReservationsPage.tsx: combined auth status, clearAll state, removed duplicate import, and auth-gated the Clear All button
Merge conflicts resolved in commit
All 48 backend and 76 frontend tests pass. |
This issue required explicit login/logout views and general app authentication for reservation update/delete flows. This PR adds session-auth endpoints and wires frontend auth-aware routing/UI so edit and delete actions are only available to authenticated users with proper permissions.
Backend: auth surface + enforcement
/api/auth/*:GET /api/auth/statusPOST /api/auth/loginPOST /api/auth/logoutbookings_by_id:PUTnow requires authentication andchange_reservationpermission, returns401when unauthenticated or403when lacking permission.DELETEnow requires authentication anddelete_reservationpermission, returns401when unauthenticated or403when lacking permission.GET /bookingsById/<id>behavior unchanged._require_api_permissionhelper that validates both authentication and specific Django model permissions.Frontend: login/logout flows
LoginPageandLogoutPage.auth.tsclient helpers forstatus/login/logoutAPI calls with cookie credentials./login/logout/reservations/edit/:idto redirect unauthenticated users to/login(preserving intended destination).Frontend: auth-aware booking operations
ReservationsPagenow reads auth status and gates mutation actions:Navbarnow rendersLoginvsLogoutbased on current auth status.Tests updated for new auth contract
The
_require_api_permissionhelper validates both authentication (returns 401 if not authenticated) and specific model permissions (returns 403 if authenticated but lacking the required permission).