Skip to content

Add associated records links to person edit#1889

Open
maebeale wants to merge 3 commits into
mainfrom
maebeale/person-edit-related-records
Open

Add associated records links to person edit#1889
maebeale wants to merge 3 commits into
mainfrom
maebeale/person-edit-related-records

Conversation

@maebeale

@maebeale maebeale commented Jun 23, 2026

Copy link
Copy Markdown
Collaborator

🤖 PR, suggested 👤 review level: 🔬 Inspect — adds a new admin-only form-submissions index/route/policy plus filters on the scholarships and grants indexes

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

  • Mirror the organization edit page's "Associated records" section on the person edit page so admins can jump straight to a person's related records.

How did you approach the change?

  • New people/_associated_records.html.erb partial, rendered in the person form (persisted only), styled to match the org version.
  • Six cards, each linking to a person-scoped destination:
    • Event registrations — existing filtered index (registrant_id)
    • Workshop logs — the per-person workshop_logs_person_path view
    • Scholarships — added a recipient_id filter to the index (previously grouped by funder only) + "Filtered to " banner
    • Grants — added a polymorphic donor filter (donor_id + donor_type) to the index + banner
    • Form submissionsnew admin-only index + list view (there was no index at all before; a person's submissions were only reachable one-off from an event registration)
    • Notifications — existing email filter, scoped to the person's preferred_email
  • Only admins reach the person edit page (PersonPolicy#edit? == admin?), so no per-card auth guards are needed. The new form-submissions index is admin?-gated in its policy.

Anything else to add?

  • Request specs cover all six links rendering, plus the new scholarships/grants filters and the form-submissions index (scoping + non-admin redirect).

Admins need to jump from a person's edit page to the records tied to
that person, the same way the organization edit page already links out
to its associated records. Surfaces the destinations that actually scope
to the person: their event registrations (filtered index) and workshop
logs (the per-person view).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@@ -0,0 +1,5 @@
<% return unless person.persisted? %>
<ul class="grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 gap-x-6 gap-y-2">
<li><%= index_button person.event_registrations, params: { registrant_id: person.id } %></li>

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: Only these two records get cards because they have person-scoped destinations: registrations filter on registrant_id, and workshop_logs_person_path is the per-person view. Scholarships/grants/form-submissions have no person-filtered index, so a card would land on an unfiltered list — omitted intentionally.

Adds two more cards to the person edit "Associated records" section.
Scholarships needed a recipient_id filter on its index (it only grouped
by funder before) so the card lands on that person's awards rather than
the full list; notifications reuse the existing email filter.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
{ grant: :donor },
{ recipient: [ { affiliations: { organization: :addresses } }, { event_registrations: :event } ] }
)
if params[:recipient_id].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: The scholarships index previously only grouped by funder with no per-recipient view, so this adds a recipient_id filter (applied before grouping) so the person-edit card lands on just that person's awards.

@maebeale maebeale changed the title Add associated records links to person edit WAIT: Add associated records links to person edit Jun 23, 2026
@maebeale maebeale marked this pull request as ready for review July 4, 2026 14:38
Copilot AI review requested due to automatic review settings July 4, 2026 14:38
@maebeale maebeale changed the title WAIT: Add associated records links to person edit Add associated records links to person edit 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

Adds an “Associated records” section to the person edit form (mirroring the org edit UX) so admins can jump directly to a person’s related records, and introduces a recipient_id filter on the scholarships index to support that navigation.

Changes:

  • Add people/_associated_records.html.erb and render it from the person form for persisted people.
  • Add recipient_id filtering to scholarships index + a “Filtered to … / Clear” banner.
  • Add request coverage for the new person edit links and the scholarships recipient filter.

Reviewed changes

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

Show a summary per file
File Description
spec/requests/scholarships_spec.rb Adds request spec asserting scholarships index filters by recipient_id.
spec/requests/people_associated_records_spec.rb New request spec asserting the associated-records links render on person edit.
app/views/scholarships/index.html.erb Adds a recipient filter banner with a clear link when scoped.
app/views/people/_form.html.erb Renders the new associated records block for persisted people.
app/views/people/_associated_records.html.erb New partial rendering card links to registrations, workshop logs, scholarships, notifications.
app/helpers/application_helper.rb Adds icons for the new index_button cards (scholarships/notifications).
app/controllers/scholarships_controller.rb Implements recipient_id filtering and sets @recipient for the banner.

Comment on lines +6 to +8
<li><%= index_button(person.user&.workshop_logs || WorkshopLog.none, path: workshop_logs_person_path(person)) %></li>
<li><%= index_button person.scholarships, params: { recipient_id: person.id } %></li>
<li><%= index_button notifications, params: { email: email } %></li>
Rounds out the person edit "Associated records" section. Grants gained
a polymorphic donor filter on its index so the card scopes to that
person's donations. Form submissions had no index at all, so this adds
a person-scoped index (admin-only) and list view — previously a person's
submissions were only reachable one-off via an event registration.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
class FormSubmissionsController < ApplicationController
def index
authorize! FormSubmission
submissions = FormSubmission.includes(:form, :event, :person)

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: New admin-only index — form submissions had no list view before, so a person's submissions were only reachable one-off from an event registration. Not using authorized_scope because FormSubmissionPolicy has no relation scope and the action is already admin?-gated.

.by_deadline
if params[:donor_id].present? && Grant::DONOR_TYPES.include?(params[:donor_type])
grants = grants.where(donor_id: params[:donor_id], donor_type: params[:donor_type])
@donor = grants.first&.donor

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: Resolve the donor via grants.first&.donor (already eager-loaded) rather than params[:donor_type].constantize — Brakeman flags reflection on a param even behind the DONOR_TYPES whitelist.

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.

2 participants