-
Notifications
You must be signed in to change notification settings - Fork 24
WAIT: Apply registrant's org type & website to linked organizations #1827
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 |
|---|---|---|
|
|
@@ -187,9 +187,10 @@ def link_organization | |
| # duplicate data), so we surface them all rather than silently picking one. | ||
| @submitted_entries = registration_submission_entries(@event_registration) | ||
| @form_submission = @submitted_entries.first&.fetch(:submission) | ||
| # The "primary" submitted org/title β the first submission that named an org | ||
| # (else the first submission) β drives the suggested-match and comparison logic. | ||
| primary = @submitted_entries.find { |entry| entry[:org_name].present? } || @submitted_entries.first | ||
| # The "primary" submitted org/title β the newest submission that named an org | ||
| # (else the newest submission) β drives the suggested-match and comparison logic, | ||
| # and is the same submission whose details linking applies to the org. | ||
| primary = primary_submission_entry(@submitted_entries) | ||
| @submitted_org_name = primary && primary[:org_name] | ||
| @submitted_position = primary && primary[:position] | ||
| # Each distinct submitted org name that isn't already in the database gets its | ||
|
|
@@ -219,6 +220,8 @@ def select_organization | |
| training_date: @event_registration.event.start_date | ||
| ) | ||
|
|
||
| apply_submitted_organization_attributes(organization, @event_registration) | ||
|
|
||
| @event_registration.event_registration_organizations | ||
| .find_or_create_by!(organization: organization) | ||
|
|
||
|
|
@@ -251,6 +254,9 @@ def create_organization | |
| job_title: submitted_position(@event_registration), | ||
| training_date: @event_registration.event.start_date | ||
| ) | ||
|
|
||
| apply_submitted_organization_attributes(organization, @event_registration) | ||
|
|
||
| @event_registration.event_registration_organizations.find_or_create_by!(organization: organization) | ||
|
|
||
| notice = existing ? "#{organization.name} linked." : "#{organization.name} created and linked." | ||
|
|
@@ -375,17 +381,21 @@ def csv_export(registrations) | |
| end | ||
| end | ||
|
|
||
| # Each registration-form submission with the org name and position the registrant | ||
| # entered on it: [{ submission:, org_name:, position: }], oldest first. | ||
| # Each registration-form submission with the org details the registrant entered on | ||
| # it: [{ submission:, org_name:, position:, agency_type:, agency_website: }], oldest | ||
| # first. | ||
| def registration_submission_entries(registration) | ||
| form = registration.event.registration_form | ||
| return [] unless form | ||
|
|
||
| field_ids = form.form_fields | ||
| .where(field_identifier: %w[agency_name agency_position]) | ||
| .where(field_identifier: %w[agency_name agency_position agency_city agency_type agency_website]) | ||
| .pluck(:field_identifier, :id).to_h | ||
| name_field_id = field_ids["agency_name"] | ||
| position_field_id = field_ids["agency_position"] | ||
| city_field_id = field_ids["agency_city"] | ||
| type_field_id = field_ids["agency_type"] | ||
| website_field_id = field_ids["agency_website"] | ||
|
|
||
| entries = registration.registrant.form_submissions | ||
| .where(form: form) | ||
|
|
@@ -396,7 +406,10 @@ def registration_submission_entries(registration) | |
| { | ||
| submission: submission, | ||
| org_name: name_field_id && answers[name_field_id]&.submitted_answer, | ||
| position: position_field_id && answers[position_field_id]&.submitted_answer | ||
| position: position_field_id && answers[position_field_id]&.submitted_answer, | ||
| agency_city: city_field_id && answers[city_field_id]&.submitted_answer, | ||
| agency_type: type_field_id && answers[type_field_id]&.submitted_answer, | ||
| agency_website: website_field_id && answers[website_field_id]&.submitted_answer | ||
| } | ||
| end | ||
|
|
||
|
|
@@ -418,13 +431,43 @@ def submitted_agency_names(registration) | |
| .uniq { |name| name.downcase } | ||
| end | ||
|
|
||
| # The "primary" entry among a registrant's submission entries β the one whose | ||
| # details we apply to a linked org and surface in the editor. Not every form asks | ||
| # for organization info, so the newest submission overall may carry none; we pick | ||
| # the NEWEST submission that actually collected an org address (agency_city present | ||
| # β the same signal public_registration uses to build the address), falling back to | ||
| # the newest that named an org, then the newest overall. Entries come oldest-first, | ||
| # so we scan from the end. link_organization picks the same one, so what we apply | ||
| # matches the editor. | ||
| def primary_submission_entry(entries) | ||
| newest_first = entries.reverse | ||
| newest_first.find { |entry| entry[:agency_city].present? } || | ||
| newest_first.find { |entry| entry[:org_name].present? } || | ||
| newest_first.first | ||
| end | ||
|
|
||
| # The job title/position the registrant typed for their organization on the | ||
| # registration form. Uses the same "primary" submission as link_organization | ||
| # (the first submission that named an org, else the first), so the title applied | ||
| # when linking matches what the editor shows. | ||
| # registration form, from the primary submission. | ||
| def submitted_position(registration) | ||
| entries = registration_submission_entries(registration) | ||
| primary = entries.find { |entry| entry[:org_name].present? } || entries.first | ||
| primary && primary[:position] | ||
| primary_submission_entry(registration_submission_entries(registration))&.dig(:position) | ||
| end | ||
|
|
||
| # The Organization Type and Website the registrant typed on the registration form, | ||
| # as Organization attributes ({ agency_type:, website_url: }) β only the values the | ||
| # registrant actually provided, so a blank answer never clobbers a curated value. | ||
| def submitted_organization_attributes(registration) | ||
| entry = primary_submission_entry(registration_submission_entries(registration)) | ||
| return {} unless entry | ||
|
|
||
| { agency_type: entry[:agency_type], website_url: entry[:agency_website] } | ||
| .select { |_, value| value.present? } | ||
|
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: This |
||
| end | ||
|
|
||
| # Overwrite the org's Organization Type and Website with what the registrant typed. | ||
| # We intentionally override curated values here (admins asked for the registrant's | ||
| # answer to win); every change is captured as an Ahoy lifecycle event. | ||
| def apply_submitted_organization_attributes(organization, registration) | ||
| attributes = submitted_organization_attributes(registration) | ||
| organization.update!(attributes) if attributes.any? | ||
| end | ||
| end | ||
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: Primary now keys on
agency_city(the signalpublic_registrationuses for whether a submission carries an org address), not org name β a later submission from a form that did not ask for org info no longer wins. Falls back to newest-named, then newest overall, so name-only or org-less data still degrades gracefully.