Skip to content

WAIT: Apply registrant's org type & website to linked organizations#1827

Draft
maebeale wants to merge 3 commits into
mainfrom
maebeale/org-agency-type-website
Draft

WAIT: Apply registrant's org type & website to linked organizations#1827
maebeale wants to merge 3 commits into
mainfrom
maebeale/org-agency-type-website

Conversation

@maebeale

@maebeale maebeale commented Jun 22, 2026

Copy link
Copy Markdown
Collaborator

🤖 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 FormAnswer rows — they were never written to the Organization's agency_type / website_url columns. Linking a registrant to an org (new or existing) now applies what they typed.

What

  • select_organization and create_organization apply the registrant's agency_type / agency_website answers to the linked org.
  • Applies to both new orgs (create_organization) and existing orgs (select_organization).
  • Overrides curated values — the registrant's answer wins (per request). A blank answer is skipped so it can't wipe a curated value.
  • Primary submission = newest one that collected an org address. A registrant can have several submissions, and not every form asks for org info, so the newest overall may carry none. We pick the newest submission with 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. Consolidated the editor's duplicate "primary" logic into the shared primary_submission_entry helper so display and applied values stay in sync.

Safety

  • Every org change is captured as an Ahoy lifecycle event (AhoyTrackable#after_update) with before/after values and Current.user, so overrides are auditable.

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? }

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 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

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 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>
@maebeale maebeale changed the title Apply registrant's org type & website to linked organizations WAIT: Apply registrant's org type & website to linked organizations Jun 22, 2026
# matches the editor.
def primary_submission_entry(entries)
newest_first = entries.reverse
newest_first.find { |entry| entry[:agency_city].present? } ||

Copy link
Copy Markdown
Collaborator Author

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 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant