Auth prereqs: session sub, accepted status, CrewMember auto-create, current_crew_member helper #195

Closed
opened 2026-06-10 01:49:14 +00:00 by ldraney · 0 comments
Owner

Type

Feature

Lineage

Prereq for #123 (client request UI), #176 (projects display), #179 (admin workflow), #180 (comments). Part of Phase 3.

Repo

ldraney/landscaping-assistant

User Story

As a developer building the service request UI, I need the session to contain the Keycloak sub, an accepted status on ServiceRequest, and a guaranteed CrewMember record for every user so FK references and access control work correctly.

Context

Three gaps identified during scope review of #123 and #176:

  1. Session stores username/email/roles but not the Keycloak sub (UUID). Needed to match owner_sub on properties for client access control.
  2. ServiceRequest needs an accepted state between quoted and paid — work often begins after bid acceptance, before payment.
  3. Clients may not have a CrewMember record, but ServiceRequest and PropertyComment require crew_member_id FK. Auto-create on login.
  4. Controllers need a current_crew_member helper to get the CrewMember record for the logged-in user.

File Targets

  • app/controllers/sessions_controller.rb (update — add sub to session, find_or_create CrewMember)
  • app/controllers/application_controller.rb (update — add current_crew_member helper)
  • app/models/service_request.rb (update — add accepted status and transitions)
  • spec/models/service_request_spec.rb (update — test new transitions)

Acceptance Criteria

  • Session hash includes sub: auth.uid (Keycloak UUID)
  • ServiceRequest STATUSES includes "accepted"
  • Transitions: quoted → accepted, accepted → paid, accepted → scheduled
  • quoted → paid is NO LONGER valid (must go through accepted)
  • CrewMember record find_or_created on login with correct role mapping
  • current_crew_member helper available in controllers and views

Test Expectations

  • spec/models/service_request_spec.rb: new transition specs
  • Run: bundle exec rspec

Constraints

  • No UI changes — model and controller only
  • Keep changes minimal

Feature Flag

None

Checklist

  • PR opened
  • Tests pass
  • No unrelated changes
  • #122 — ServiceRequest model (MERGED, this patches it)
  • #123 — Client request UI (blocked on this)
  • #176 — Projects display (blocked on this)
  • #180 — Property comments (needs current_crew_member)
### Type Feature ### Lineage Prereq for #123 (client request UI), #176 (projects display), #179 (admin workflow), #180 (comments). Part of Phase 3. ### Repo `ldraney/landscaping-assistant` ### User Story As a developer building the service request UI, I need the session to contain the Keycloak sub, an `accepted` status on ServiceRequest, and a guaranteed CrewMember record for every user so FK references and access control work correctly. ### Context Three gaps identified during scope review of #123 and #176: 1. Session stores username/email/roles but not the Keycloak `sub` (UUID). Needed to match `owner_sub` on properties for client access control. 2. ServiceRequest needs an `accepted` state between `quoted` and `paid` — work often begins after bid acceptance, before payment. 3. Clients may not have a CrewMember record, but ServiceRequest and PropertyComment require `crew_member_id` FK. Auto-create on login. 4. Controllers need a `current_crew_member` helper to get the CrewMember record for the logged-in user. ### File Targets - `app/controllers/sessions_controller.rb` (update — add sub to session, find_or_create CrewMember) - `app/controllers/application_controller.rb` (update — add current_crew_member helper) - `app/models/service_request.rb` (update — add accepted status and transitions) - `spec/models/service_request_spec.rb` (update — test new transitions) ### Acceptance Criteria - [ ] Session hash includes `sub: auth.uid` (Keycloak UUID) - [ ] ServiceRequest STATUSES includes "accepted" - [ ] Transitions: quoted → accepted, accepted → paid, accepted → scheduled - [ ] quoted → paid is NO LONGER valid (must go through accepted) - [ ] CrewMember record find_or_created on login with correct role mapping - [ ] `current_crew_member` helper available in controllers and views ### Test Expectations - `spec/models/service_request_spec.rb`: new transition specs - Run: `bundle exec rspec` ### Constraints - No UI changes — model and controller only - Keep changes minimal ### Feature Flag None ### Checklist - [ ] PR opened - [ ] Tests pass - [ ] No unrelated changes ### Related - #122 — ServiceRequest model (MERGED, this patches it) - #123 — Client request UI (blocked on this) - #176 — Projects display (blocked on this) - #180 — Property comments (needs current_crew_member)
Sign in to join this conversation.
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
ldraney/landscaping-assistant#195
No description provided.