-
Notifications
You must be signed in to change notification settings - Fork 24
Rename public_registration to public_forms with variant-aware routing #1599
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,16 +1,23 @@ | ||
| module Events | ||
| class PublicRegistrationsController < ApplicationController | ||
| class PublicFormsController < ApplicationController | ||
| HEADINGS = { | ||
| "registration" => "Registration", | ||
| "scholarship" => "Scholarship application", | ||
| "bulk_payment" => "Bulk payment", | ||
| "ce_credit" => "Continuing education credit" | ||
| }.freeze | ||
|
|
||
| skip_before_action :authenticate_user!, only: [ :new, :create, :show ] | ||
| before_action :set_event | ||
| before_action :ensure_registerable, only: [ :new, :create ] | ||
|
|
||
| rescue_from ActionController::InvalidAuthenticityToken do | ||
| flash[:alert] = "Your session has expired. Please try submitting the form again." | ||
| redirect_to new_event_public_registration_path(@event) | ||
| redirect_to public_form_new_path | ||
| end | ||
|
|
||
| def new | ||
| authorize! :public_registration, to: :new? | ||
| authorize! :public_form, to: :new? | ||
|
|
||
| @form = registration_form | ||
| unless @form | ||
|
|
@@ -25,10 +32,10 @@ def new | |
| end | ||
|
|
||
| def create | ||
| authorize! :public_registration, to: :create? | ||
| authorize! :public_form, to: :create? | ||
|
|
||
| if params[:public_registration][:website_url].present? | ||
| redirect_to new_event_public_registration_path(@event) | ||
| redirect_to public_form_new_path | ||
| return | ||
| end | ||
|
|
||
|
|
@@ -76,7 +83,7 @@ def create | |
| end | ||
|
|
||
| def show | ||
| authorize! :public_registration, to: :show? | ||
| authorize! :public_form, to: :show? | ||
|
|
||
| if params[:reg].present? | ||
| registration = EventRegistration.find_by!(slug: params[:reg], event_id: @event.id) | ||
|
|
@@ -148,9 +155,31 @@ def registration_form | |
| @event.registration_form | ||
| end | ||
|
|
||
| def form_role | ||
| EventForm::ROLES.include?(params[:form_role]) ? params[:form_role] : "registration" | ||
| end | ||
| helper_method :form_role | ||
|
|
||
| def scholarship_mode? | ||
| params[:scholarship_requested] == "true" | ||
| if form_role == "scholarship" | ||
| params[:scholarship_requested] != "false" | ||
| else | ||
| params[:scholarship_requested] == "true" | ||
| end | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🤖 From Claude: Scholarship default differs by variant: the |
||
| end | ||
|
|
||
| def public_form_new_path | ||
| send("new_event_#{form_role}_form_path", @event) | ||
| end | ||
|
|
||
| def public_form_submit_path | ||
| send("event_#{form_role}_form_path", @event) | ||
| end | ||
|
|
||
| def public_form_heading | ||
| HEADINGS.fetch(form_role) | ||
| end | ||
| helper_method :public_form_new_path, :public_form_submit_path, :public_form_heading | ||
|
|
||
| def split_form_params(all_params) | ||
| reg_field_ids = @form.form_fields.pluck(:id).map(&:to_s) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -130,7 +130,12 @@ | |
| post :send_reminder | ||
| end | ||
| resource :registrations, only: %i[ create destroy ], module: :events, as: :registrant_registration | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🤖 From Claude: The |
||
| resource :public_registration, only: [ :new, :create, :show ], module: :events | ||
| EventForm::ROLES.each do |form_role| | ||
| actions = form_role == "registration" ? %i[ new create show ] : %i[ new create ] | ||
| resource :"#{form_role}_form", only: actions, | ||
| controller: "public_forms", module: :events, | ||
| defaults: { form_role: form_role } | ||
| end | ||
| end | ||
| resources :people do | ||
| collection do | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤖 From Claude:
form_variantis whitelisted againstVARIANTSand falls back to"registration", so an unknown variant in the URL degrades to the default flow rather than blowing up the path helpers below.