WAIT: Apply registrant's org type & website to linked organizations#1827
WAIT: Apply registrant's org type & website to linked organizations#1827maebeale wants to merge 3 commits into
Conversation
Registration captured Organization Type and Website only as FormAnswer rows; they were never written to the Organization's agency_type / website_url columns. Both org-linking actions now apply the registrant's answers to the org — for new orgs (create_organization) and existing ones (select_organization) alike — overriding any curated value so the registrant's answer wins. A blank answer is skipped so it can't wipe a curated value, and every change is captured as an Ahoy lifecycle event. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
| return {} unless entry | ||
|
|
||
| { agency_type: entry[:agency_type], website_url: entry[:agency_website] } | ||
| .select { |_, value| value.present? } |
There was a problem hiding this comment.
🤖 From Claude: This presence filter is the one judgment call: we override curated agency_type/website_url with the registrant's answer, but a blank answer is dropped so it can't wipe a curated value. If you ever want new-org vs. existing-org to differ (e.g. backfill-only for existing), this is the seam to branch on.
A registrant can have multiple registration-form submissions; the latest one reflects their current org details. Treat the newest submission (that named an org) as primary instead of the oldest, so the type/website/position we apply — and what the editor surfaces — come from their latest answer. Consolidates the duplicate "primary submission" logic the editor had into the shared helper. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
| # scan from the end. link_organization picks the same one, so what we apply matches | ||
| # the editor. | ||
| def primary_submission_entry(entries) | ||
| entries.reverse.find { |entry| entry[:org_name].present? } || entries.last |
There was a problem hiding this comment.
🤖 From Claude: Primary = the newest submission that named an org (entries are oldest-first, so we scan from the end). link_organization now calls this same helper, so the answers the editor surfaces match the ones linking applies — previously the editor had its own inline first-named copy of this logic.
Not every registration form asks for organization info, so the newest submission overall may carry none. Select the newest submission whose org address was filled in (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. Keeps the applied org details from latching onto a later, unrelated submission. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
| # matches the editor. | ||
| def primary_submission_entry(entries) | ||
| newest_first = entries.reverse | ||
| newest_first.find { |entry| entry[:agency_city].present? } || |
There was a problem hiding this comment.
🤖 From Claude: Primary now keys on agency_city (the signal public_registration uses 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.
🤖 PR, suggested 👤 review level: 📖 Read — light-logic: contained change to two org-linking actions plus the editor's "primary submission" pick
Why
Registration captures Organization Type and Website only as
FormAnswerrows — they were never written to the Organization'sagency_type/website_urlcolumns. Linking a registrant to an org (new or existing) now applies what they typed.What
select_organizationandcreate_organizationapply the registrant'sagency_type/agency_websiteanswers to the linked org.create_organization) and existing orgs (select_organization).agency_citypresent (the same signalpublic_registrationuses to build the address), falling back to the newest that named an org, then the newest overall. Consolidated the editor's duplicate "primary" logic into the sharedprimary_submission_entryhelper so display and applied values stay in sync.Safety
AhoyTrackable#after_update) with before/after values andCurrent.user, so overrides are auditable.