Skip to content

COORDINATE: Add OrganizationType base-data model backing org and registration forms#1886

Open
maebeale wants to merge 3 commits into
mainfrom
maebeale/organization-type-model
Open

COORDINATE: Add OrganizationType base-data model backing org and registration forms#1886
maebeale wants to merge 3 commits into
mainfrom
maebeale/organization-type-model

Conversation

@maebeale

@maebeale maebeale commented Jun 23, 2026

Copy link
Copy Markdown
Collaborator

🤖 PR, suggested 👤 review level: 📖 Read — new Publishable base-data model with a schema-only migration (no data transform); contained logic, low blast radius

What is the goal of this PR and why is this important?

The "Organization Type" classification list was hardcoded and duplicated in two places (the organization profile form and the public registration form builder). This makes it an admin-managed, Publishable OrganizationType model under Base data, so the list can change without a deploy.

How did you approach the change?

  • New OrganizationType model (Publishable, name + published + description), mirroring the Sector base-data pattern: controller, policy, decorator, factory, full CRUD views, route, admin "Base data" card.
  • Organization belongs_to :organization_type (optional). Profile form, index ("Designations" cell), and show page now read from the association.
  • Public registration form builder reads options from OrganizationType.published_names, falling back to the canonical defaults when none are seeded (keeps test DBs without seeds working).
  • Canonical four are seeded as published via db/seeds.rb; the catch-all is plain "Other". agency_type_other (the free-text "Other" specify field) is retained.

Anything else to add?

  • Migration is schema-only (adds the nullable organization_type_id reference) — no data backfill. Existing organizations are left unclassified rather than mapped from their legacy agency_type strings.
  • The agency_type (string) column is left in place rather than dropped; the form no longer writes it.
  • New specs: model, request (CRUD + dependent nullify), and a form-builder case asserting it reads published type names.


organization.where.not(agency_type: [ nil, "" ]).find_each do |org|
match = org_type.where("LOWER(name) = LOWER(?)", org.agency_type).first
org.update_columns(organization_type_id: match.id) if match

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: Backfill uses lightweight anonymous AR classes (not the real models) so the migration stays stable if OrganizationType/Organization change later, and update_columns to skip validations/callbacks during the data move. Mapping is case-insensitive against the seeded type names.


# Published names for the forms, falling back to the canonical defaults when
# nothing is seeded yet.
def self.published_names

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: Fallback to DEFAULT_NAMES keeps the org + registration forms populated when no types are published yet — notably fresh test DBs that do not load seeds, so the existing form-builder spec stays green without seeding.

@maebeale maebeale force-pushed the maebeale/organization-type-model branch from 16ad678 to 2dbeb8b Compare June 23, 2026 10:48
Copilot AI review requested due to automatic review settings June 23, 2026 10:48

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@maebeale maebeale changed the title Add OrganizationType base-data model backing org and registration forms WAIT: Add OrganizationType base-data model backing org and registration forms Jun 23, 2026
@maebeale maebeale force-pushed the maebeale/organization-type-model branch from 1bcd8ec to 0a853fb Compare June 23, 2026 12:01
@maebeale maebeale marked this pull request as ready for review July 4, 2026 14:49
Copilot AI review requested due to automatic review settings July 4, 2026 14:49
@maebeale maebeale force-pushed the maebeale/organization-type-model branch from b9d2721 to 05fa647 Compare July 4, 2026 14:51
@maebeale maebeale changed the title WAIT: Add OrganizationType base-data model backing org and registration forms Add OrganizationType base-data model backing org and registration forms Jul 4, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 29 out of 29 changed files in this pull request and generated 1 comment.

Comments suppressed due to low confidence (1)

config/routes.rb:208

  • should-fix: This new resource adds a full RESTful route, but there’s no corresponding routing spec (other base-data resources like sectors and organization_statuses have one), so route regressions won’t be caught.
    get :download
  end
  resources :sectors do

Comment on lines +108 to 115
<%= f.association :organization_type,
label: "Organization Type",
as: :select,
collection: OrganizationType.published.ordered,
include_blank: true,
required: true,
collection: [
"501c3/nonprofit",
"For-profit",
"Government agency",
"Other (please specify below)"
],
selected: f.object.agency_type,
input_html: {
value: f.object.agency_type,
class: "rounded-md border-gray-300 shadow-sm focus:ring-blue-500 focus:border-blue-500"
} %>
Copilot AI review requested due to automatic review settings July 4, 2026 14:53

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 29 out of 29 changed files in this pull request and generated 4 comments.

Comment on lines +108 to 112
<%= f.association :organization_type,
label: "Organization Type",
as: :select,
collection: OrganizationType.published.ordered,
include_blank: true,
required: true,
Comment on lines 407 to +409
position = add_field(form, position, "Organization Type", :single_select_radio,
key: "agency_type", group: "person_contact_info", required: false,
options: [
"501c3/nonprofit", "For-profit", "Government agency",
"Other (please specify below)"
])
options: OrganizationType.published_names)
Comment on lines +5 to +8
create_table :organization_types do |t|
t.string :name
t.text :description
t.boolean :published, default: false, null: false
Comment thread config/routes.rb
Comment on lines 191 to 193
resources :organization_statuses
resources :organization_types
resources :affiliations, only: :destroy
maebeale and others added 3 commits July 4, 2026 12:37
Replace the hardcoded "Organization Type" classification list (duplicated
across the organization profile form and the public registration form
builder) with an admin-managed, Publishable OrganizationType model under
"Base data". Organizations now belong_to :organization_type, and the
profile form, index, and show read from the association. Existing
agency_type strings are backfilled onto the matching types so no data is
lost; the canonical four are seeded as published.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Drop the "(please specify below)" parenthetical from the option label. The
migration backfill aliases the legacy string onto the renamed record so
existing organizations keep their classification.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Keep it schema-only (add the nullable reference). The canonical types are
still seeded via db/seeds.rb; existing organizations are left unclassified
rather than mapped from their legacy agency_type strings.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@maebeale maebeale force-pushed the maebeale/organization-type-model branch from 05fa647 to 7dc8076 Compare July 4, 2026 16:38
maebeale added a commit that referenced this pull request Jul 4, 2026
When linking/creating an org from a registrant's submission on the org-linking
page, optionally apply the org info the registrant typed, gated by a per-form
"populate" toggle (zero JS):
- Create-and-link (new org) and suggested matches default the toggle on (very
  likely the registrant's org); the manual search box defaults off (often an
  unrelated established org).
- When applying: website and organization type overwrite the org's values (each
  logged to Ahoy update.organization); the address is additive — added as a new
  primary, or a same-street record refreshed instead of duplicated; demoted
  addresses stay active.
- Create-and-link with the toggle off creates the org bare; an existing same-name
  org is only linked unless the toggle is on.

Organization type is set via the OrganizationType association (PR #1886): the
submitted type name is resolved to an OrganizationType record (case-insensitive).
Website stored as typed (#1765). Phone is not populated (no org phone field).

Also fixes a latent bug: PublicRegistration passed nil street/zip to NOT NULL
address columns, 500-ing when a registrant filled a city but no zip; coerce to "".

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@maebeale maebeale changed the title Add OrganizationType base-data model backing org and registration forms COORDINATE: Add OrganizationType base-data model backing org and registration forms Jul 4, 2026
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.

3 participants