Skip to content

Add session auth views and enforce permission-based update/delete booking operations - #408

Merged
conorheffron merged 12 commits into
mainfrom
copilot/build-login-logout-views
Jun 5, 2026
Merged

Add session auth views and enforce permission-based update/delete booking operations#408
conorheffron merged 12 commits into
mainfrom
copilot/build-login-logout-views

Conversation

Copilot AI commented May 16, 2026

Copy link
Copy Markdown
Contributor

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

    • Added auth endpoints under /api/auth/*:
      • GET /api/auth/status
      • POST /api/auth/login
      • POST /api/auth/logout
    • Added permission-based auth checks in bookings_by_id:
      • PUT now requires authentication and change_reservation permission, returns 401 when unauthenticated or 403 when lacking permission.
      • DELETE now requires authentication and delete_reservation permission, returns 401 when unauthenticated or 403 when lacking permission.
    • Kept GET /bookingsById/<id> behavior unchanged.
    • Uses _require_api_permission helper that validates both authentication and specific Django model permissions.
  • Frontend: login/logout flows

    • Added LoginPage and LogoutPage.
    • Added auth.ts client helpers for status/login/logout API calls with cookie credentials.
    • Added routes:
      • /login
      • /logout
    • Added route guard for /reservations/edit/:id to redirect unauthenticated users to /login (preserving intended destination).
  • Frontend: auth-aware booking operations

    • ReservationsPage now reads auth status and gates mutation actions:
      • Edit link visually/semantically disabled when unauthenticated.
      • Delete button disabled when unauthenticated with CSRF token and credentials included.
      • Inline "Login required" affordance added per row.
    • Navbar now renders Login vs Logout based on current auth status.
  • Tests updated for new auth contract

    • Backend API tests expanded for:
      • auth status/login/logout handlers
      • unauthenticated PUT/DELETE rejection (401)
      • permission-denied PUT/DELETE rejection (403)
    • Frontend tests expanded for:
      • login page submit/error behavior
      • logout page redirect/error behavior
      • navbar login/logout state
      • reservations unauthenticated action gating
# backend/hr/views.py (bookings_by_id)
elif request.method == "PUT":
    permission_error = cls._require_api_permission(request, "change_reservation")
    if permission_error:
        return permission_error
    ...

elif request.method == "DELETE":
    permission_error = cls._require_api_permission(request, "delete_reservation")
    if permission_error:
        return permission_error
    ...

The _require_api_permission helper validates both authentication (returns 401 if not authenticated) and specific model permissions (returns 403 if authenticated but lacking the required permission).

Copilot AI and others added 2 commits May 16, 2026 14:16
Copilot AI changed the title [WIP] Build login and logout views with general app auth for update and delete ops Add session auth views and enforce authenticated update/delete booking operations May 16, 2026
Copilot AI requested a review from conorheffron May 16, 2026 14:20
@conorheffron conorheffron added enhancement New feature or request python-code Backend related tasks on python/django side python Pull requests that update python code labels May 24, 2026
@conorheffron
conorheffron requested a review from Copilot May 24, 2026 13:02

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 on PUT/DELETE for bookings_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.

Comment thread frontend/src/pages/ReservationsPage.tsx
Comment thread frontend/src/pages/ReservationsPage.tsx
Comment thread frontend/src/pages/ReservationsPage.tsx Outdated
Comment thread frontend/src/pages/__tests__/Reservationspage.test.tsx
@conorheffron
conorheffron marked this pull request as ready for review May 30, 2026 21:06
conorheffron and others added 2 commits May 30, 2026 22:06
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>
@conorheffron

Copy link
Copy Markdown
Owner

@copilot resolve the merge conflicts in this pull request

Copilot AI requested a review from conorheffron June 1, 2026 01:08

Copilot AI commented Jun 1, 2026

Copy link
Copy Markdown
Contributor Author

@copilot resolve the merge conflicts in this pull request

Merge conflicts resolved. The conflicts were in 4 files:

  • backend/hr/views.py: Replaced basic auth checks with permission-based checks from main
  • backend/hr/test_apis.py: Merged auth tests with OpenAPI tests and helper methods
  • frontend/src/pages/ReservationsPage.tsx: Merged imports and DELETE headers
  • frontend/src/pages/__tests__/Reservationspage.test.tsx: Merged test mocks

The resolution adopts main's more robust permission system (_require_api_permission) which checks both authentication and specific model permissions.

Copilot AI changed the title Add session auth views and enforce authenticated update/delete booking operations Add session auth views and enforce permission-based update/delete booking operations Jun 1, 2026
@conorheffron

Copy link
Copy Markdown
Owner

@copilot resolve the merge conflicts in this pull request

@conorheffron

Copy link
Copy Markdown
Owner

@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

Copilot AI commented Jun 1, 2026

Copy link
Copy Markdown
Contributor Author

@copilot resolve the merge conflicts in this pull request

Merge conflicts resolved. The conflicts were in 4 files:

  • backend/hr/views.py: Kept both auth methods (auth_status, login, logout) and main's current_user method
  • backend/hr/test_apis.py: Kept both auth tests and current_user tests
  • frontend/src/components/Navbar.tsx: Combined auth-aware login/logout toggle with main's user dropdown
  • frontend/src/components/__tests__/Navbar.test.tsx: Combined all tests (auth + user display)

Also fixed ReservationsPage test that needed a MemoryRouter wrapper for the Link component rendered in unauthenticated state. All 44 backend and 74 frontend tests pass.

@conorheffron

Copy link
Copy Markdown
Owner

@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

Copilot AI commented Jun 5, 2026

Copy link
Copy Markdown
Contributor Author

@copilot resolve the merge conflicts in this pull request

Merge conflicts resolved in commit 48a4668. Conflicts were in 2 files:

  • backend/hr/test_apis.py: Merged clear-all user fixtures (auth_user, staff_user, superuser) alongside the existing auth test user
  • frontend/src/pages/ReservationsPage.tsx: Combined isAuthenticated and clearingAll state, removed duplicate getCSRFToken import, and auth-gated the "Clear all" button

All 48 backend and 76 frontend tests pass.

Copilot AI requested a review from conorheffron June 5, 2026 21:15
@conorheffron
conorheffron merged commit 1fe8f7f into main Jun 5, 2026
10 checks passed
@github-project-automation github-project-automation Bot moved this from In review to Done in @conorheffron's booking-sys Jun 5, 2026
@conorheffron
conorheffron deleted the copilot/build-login-logout-views branch June 5, 2026 21:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request python Pull requests that update python code python-code Backend related tasks on python/django side

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Build login & logout views with general app auth for Update & Delete Ops

3 participants