identity-vault/app/controllers/portal/addresses_controller.rb
nora 105e4b7a7c
Now you're thinking with portals! (#89)
* Extract verification flow logic into VerificationFlow concern

Move document submission handling and helper methods from
VerificationsController into a reusable concern:
- setup_document_step, handle_document_submission
- process_legal_name, process_aadhaar_number
- create_verification, document_params
- verification_should_redirect? helper

Extract document form into shared partial for reuse across
regular and portal verification flows.

* Extract address building into AddressManagement concern

Move build_address helper into a shared concern for reuse
between AddressesController and Portal::AddressesController.

* Add PortalFlow concern and base controller for external app flows

PortalFlow provides secure redirect handling for portal flows:
- Validates return URLs against registered Program redirect URIs
- Stores validated URLs in session to prevent tampering
- Allows localhost in non-production environments
- Provides redirect helpers with portal_status query param

Portal::BaseController uses logged_out layout with portal_wrapper
content block for minimal UI.

* Add portal controllers and routes for external app integration

Portal::VerificationsController handles document verification flow
triggered by external OAuth apps, with status-based redirects.

Portal::AddressesController handles address collection with manage
view for users who already have addresses.

Routes:
- GET/POST/DELETE /portal/verify
- GET/POST /portal/address
- GET /portal/address/done

Also adds make_primary member route to addresses resource.

* Add HTMX support to AddressesController for dynamic updates

Refactor AddressesController:
- Extract create/primary logic into helper methods
- Add HTMX-aware response methods for partial updates
- Support portal context detection for shared address list

Add partials:
- _address_list.html.erb: Shared address list with HTMX actions
- _edit_form.html.erb: Inline edit form for HTMX requests
- Update _form.html.erb with HTMX form attributes when target provided

Address list supports both regular and portal contexts with
appropriate HTMX targets and translations.

* Add portal views and translations

Portal views:
- verifications/document.html.erb: Document upload for portal flow
- verifications/pending.html.erb: Pending verification status
- addresses/portal.html.erb: Initial address collection form
- addresses/manage.html.erb: Address list for existing addresses

Update logged_out layout to support portal_wrapper content block
with minimal brand header for portal flows. Add HTMX CSRF header.

Add translations for portal verification and address flows.

* Add Program.official scope and update address styles

Add scope to filter HQ-official programs.

Update address styles for portal and HTMX address management:
- Improved address card layout with flex
- Add address card and button styles
- Pending verification card styles
- Portal done button styling

* fix address nit?
2025-12-09 12:46:05 -05:00

36 lines
828 B
Ruby

class Portal::AddressesController < Portal::BaseController
include AddressManagement
def portal
@addresses = current_identity.addresses
build_address
render @addresses.any? ? :manage : :portal
end
def create
@address = current_identity.addresses.new(address_params)
if @address.save
set_primary_if_needed
redirect_to_simple_return
else
render :portal
end
end
def done
redirect_to_simple_return
end
private
def address_params
params.require(:address).permit(:first_name, :last_name, :line_1, :line_2, :city, :state, :postal_code, :country, :phone_number)
end
def set_primary_if_needed
if current_identity.primary_address.nil? || current_identity.addresses.count == 1
current_identity.update(primary_address: @address)
end
end
end