Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions app/controllers/form_submissions_controller.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
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.

if params[:person_id].present?
submissions = submissions.where(person_id: params[:person_id])
@person = Person.find_by(id: params[:person_id])
end
@form_submissions = submissions.order(created_at: :desc)
end

def show
@form_submission = FormSubmission.find(params[:id])
authorize! @form_submission
Expand Down
12 changes: 8 additions & 4 deletions app/controllers/grants_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@ class GrantsController < ApplicationController

def index
authorize!
@grants = authorized_scope(Grant.all)
.includes(:donor, scholarships: { allocation: :allocatable })
.by_deadline
.page(params[:page])
grants = authorized_scope(Grant.all)
.includes(:donor, scholarships: { allocation: :allocatable })
.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.

end
@grants = grants.page(params[:page])
track_index_intent(Grant, @grants, params)
end

Expand Down
4 changes: 4 additions & 0 deletions app/controllers/scholarships_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ def index
{ 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.

scholarships = scholarships.where(recipient_id: params[:recipient_id])
@recipient = Person.find_by(id: params[:recipient_id])
end
@funder_groups = ScholarshipsGrouping.new(scholarships).funder_groups
@scholarships_count = scholarships.size
end
Expand Down
6 changes: 5 additions & 1 deletion app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,11 @@ def form_field_option_source(field)
people: "fa-user",
organizations: "fa-building",
workshops: "fa-chalkboard-user",
resources: "fa-book"
resources: "fa-book",
scholarships: "fa-graduation-cap",
notifications: "fa-bell",
grants: "fa-hand-holding-dollar",
form_submissions: "fa-file-signature"
}.freeze

# Themed card-style link to a filtered index. The collection drives the
Expand Down
4 changes: 4 additions & 0 deletions app/policies/form_submission_policy.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
class FormSubmissionPolicy < ApplicationPolicy
# See https://actionpolicy.evilmartians.io/#/writing_policies
def index?
admin?
end

def show?
admin?
end
Expand Down
68 changes: 68 additions & 0 deletions app/views/form_submissions/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<% content_for(:page_bg_class, "admin-only bg-blue-100") %>

<div class="form-submissions-index max-w-7xl mx-auto <%= DomainTheme.bg_class_for(:forms) %> border border-gray-200 rounded-xl shadow p-6">
<div class="w-full">
<% if @person %>
<div class="mb-4">
<%= link_to edit_person_path(@person), class: "inline-flex items-center gap-1.5 text-sm text-gray-500 hover:text-gray-700" do %>
<i class="fa-solid fa-arrow-left text-xs"></i> Edit <%= @person.name %>
<% end %>
</div>
<% end %>

<div class="flex items-start gap-4 mb-6">
<span class="hidden sm:flex h-12 w-12 shrink-0 items-center justify-center rounded-xl <%= DomainTheme.bg_class_for(:forms) %> <%= DomainTheme.text_class_for(:forms, intensity: 700) %> border <%= DomainTheme.border_class_for(:forms, intensity: 200) %> shadow-sm">
<i class="fa-solid fa-file-signature text-xl" aria-hidden="true"></i>
</span>
<div>
<h2 class="text-2xl font-semibold text-gray-900 flex items-center gap-2">
Form submissions
<span class="inline-flex items-center rounded-full <%= DomainTheme.bg_class_for(:forms) %> <%= DomainTheme.text_class_for(:forms, intensity: 700) %> border <%= DomainTheme.border_class_for(:forms, intensity: 200) %> px-2.5 py-0.5 text-sm font-semibold"><%= @form_submissions.size %></span>
</h2>
<p class="text-gray-600 mt-1">
<% if @person %>
Forms submitted by <span class="font-medium text-gray-900"><%= @person.name %></span>.
<% else %>
Forms submitted across the site.
<% end %>
</p>
</div>
</div>

<% if @form_submissions.any? %>
<div class="overflow-x-auto bg-white rounded-xl border border-gray-200 shadow-sm">
<table class="w-full border-collapse">
<thead>
<tr class="border-b border-gray-200 bg-gray-50 text-left text-sm text-gray-600">
<th class="px-4 py-3">Form</th>
<th class="px-4 py-3">Role</th>
<th class="px-4 py-3">Event</th>
<% unless @person %><th class="px-4 py-3">Person</th><% end %>
<th class="px-4 py-3">Submitted</th>
<th class="px-4 py-3"></th>
</tr>
</thead>
<tbody>
<% @form_submissions.each do |submission| %>
<tr class="border-b border-gray-100 last:border-0 text-sm text-gray-800">
<td class="px-4 py-3 font-medium"><%= submission.form&.display_name %></td>
<td class="px-4 py-3"><%= submission.role&.humanize %></td>
<td class="px-4 py-3"><%= submission.resolved_event&.name %></td>
<% unless @person %><td class="px-4 py-3"><%= submission.person&.name %></td><% end %>
<td class="px-4 py-3 whitespace-nowrap"><%= submission.created_at.to_fs(:long) %></td>
<td class="px-4 py-3 text-right">
<%= link_to "View", form_submission_path(submission), class: "text-blue-600 hover:underline" %>
</td>
</tr>
<% end %>
</tbody>
</table>
</div>
<% else %>
<div class="bg-white rounded-xl border border-dashed border-gray-300 py-12 text-center">
<i class="fa-solid fa-file-signature text-3xl text-gray-300" aria-hidden="true"></i>
<p class="mt-3 text-gray-500">No form submissions found.</p>
</div>
<% end %>
</div>
</div>
6 changes: 6 additions & 0 deletions app/views/grants/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@
</div>
</div>

<% if @donor %>
<div class="mb-4 flex items-center gap-2 text-sm text-gray-600">
<span>Filtered to <span class="font-medium text-gray-900"><%= @donor.try(:name) || @donor.try(:full_name) %></span></span>
<%= link_to "Clear", grants_path, class: "text-blue-600 hover:underline" %>
</div>
<% end %>
<% if @grants.any? %>
<div class="overflow-x-auto bg-white rounded-xl border border-gray-200 shadow-sm">
<table class="w-full border-collapse" data-controller="table-sort">
Expand Down
11 changes: 11 additions & 0 deletions app/views/people/_associated_records.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<% return unless person.persisted? %>
<% email = person.preferred_email %>
<% notifications = email.present? ? Notification.email(email) : Notification.none %>
<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.

<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 person.grants, params: { donor_id: person.id, donor_type: "Person" } %></li>
<li><%= index_button person.form_submissions, params: { person_id: person.id } %></li>
<li><%= index_button notifications, params: { email: email } %></li>
</ul>
12 changes: 12 additions & 0 deletions app/views/people/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,18 @@
</div>
</div>

<% if f.object.persisted? %>
<% person = f.object.respond_to?(:object) ? f.object.object : f.object %>
<div class="form-group space-y-4 mb-8">
<div class="font-semibold text-gray-700 mb-2">
Associated records
</div>
<div class="rounded-lg border border-gray-200 bg-gray-50 p-4 mb-4 shadow-sm">
<%= render "associated_records", person: person %>
</div>
</div>
<% end %>

<% if f.object.persisted? %>
<!-- Comments -->
<% if allowed_to?(:manage?, Comment) %>
Expand Down
6 changes: 6 additions & 0 deletions app/views/scholarships/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@
</div>
</div>

<% if @recipient %>
<div class="mb-4 flex items-center gap-2 text-sm text-gray-600">
<span>Filtered to <span class="font-medium text-gray-900"><%= @recipient.name %></span></span>
<%= link_to "Clear", scholarships_path, class: "text-blue-600 hover:underline" %>
</div>
<% end %>
<% if @funder_groups.any? %>
<div class="space-y-4">
<%= render partial: "funder_group", collection: @funder_groups, as: :funder_group %>
Expand Down
2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@
patch :update_sections
end
end
resources :form_submissions, only: [ :show ]
resources :form_submissions, only: [ :index, :show ]
resources :grants
resources :scholarships, only: [ :index, :new, :create, :show, :edit, :update, :destroy ] do
member { patch :toggle_tasks }
Expand Down
30 changes: 30 additions & 0 deletions spec/requests/form_submissions_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,36 @@
let(:admin) { create(:user, :admin) }
let(:submission) { create(:form_submission) }

describe "GET /form_submissions" do
context "as an admin" do
before { sign_in admin }

it "lists a person's submissions and links each to its detail page" do
person = create(:person, first_name: "Priya", last_name: "Patel")
other = create(:person)
mine = create(:form_submission, person: person)
theirs = create(:form_submission, person: other)

get form_submissions_path(person_id: person.id)

expect(response).to have_http_status(:ok)
expect(response.body).to include("Priya Patel")
expect(response.body).to include(form_submission_path(mine))
expect(response.body).not_to include(form_submission_path(theirs))
end
end

context "as a non-admin" do
before { sign_in create(:user) }

it "redirects away" do
get form_submissions_path

expect(response).to redirect_to(root_path)
end
end
end

describe "GET /form_submissions/:id" do
context "as an admin" do
before { sign_in admin }
Expand Down
12 changes: 12 additions & 0 deletions spec/requests/grants_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,18 @@
expect(response.body).to include(edit_scholarship_path(scholarship))
expect(response.body).to include("Scholarship")
end

it "filters to a single person donor when donor_id/donor_type are given" do
donor = create(:person, first_name: "Dana", last_name: "Donor")
create(:grant, name: "Dana Fund", donor: donor)
create(:grant, name: "Other Fund", donor: create(:organization, name: "Big Org"))

get grants_url(donor_id: donor.id, donor_type: "Person")

expect(response.body).to include("Filtered to")
expect(response.body).to include("Dana Fund")
expect(response.body).not_to include("Other Fund")
end
end

describe "GET /show" do
Expand Down
30 changes: 30 additions & 0 deletions spec/requests/people_associated_records_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
require "rails_helper"

RSpec.describe "Person edit associated records", type: :request do
let(:admin) { create(:user, :admin) }

before { sign_in admin }

describe "GET /people/:id/edit" do
it "links to the person's filtered registrations, workshop logs, scholarships, grants, form submissions, and notifications" do
person = create(:person)
create(:event_registration, registrant: person)
create(:workshop_log, created_by: person.user)
create(:scholarship, recipient: person)
create(:grant, donor: person)
create(:form_submission, person: person)
create(:notification, recipient_email: person.preferred_email)

get edit_person_path(person)

expect(response).to have_http_status(:ok)
expect(response.body).to include("Associated records")
expect(response.body).to include(event_registrations_path(registrant_id: person.id))
expect(response.body).to include(workshop_logs_person_path(person))
expect(response.body).to include(scholarships_path(recipient_id: person.id))
expect(response.body).to include(CGI.escapeHTML(grants_path(donor_id: person.id, donor_type: "Person")))
expect(response.body).to include(form_submissions_path(person_id: person.id))
expect(response.body).to include(notifications_path(email: person.preferred_email))
end
end
end
13 changes: 13 additions & 0 deletions spec/requests/scholarships_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,19 @@

expect(response.body).to include(grant_path(grant, from_scholarships: true))
end

it "filters to a single recipient when recipient_id is given" do
recipient = create(:person, first_name: "Carmen", last_name: "Gomez")
other = create(:person, first_name: "Jane", last_name: "Doe")
create(:scholarship, recipient: recipient)
create(:scholarship, recipient: other)

get scholarships_path(recipient_id: recipient.id)

expect(response.body).to include("Filtered to")
expect(response.body).to include("Carmen Gomez")
expect(response.body).not_to include("Jane Doe")
end
end
end

Expand Down
1 change: 1 addition & 0 deletions spec/views/page_bg_class_alignment_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@
"app/views/workshop_variation_ideas/index.html.erb" => "admin-only bg-blue-100",
"app/views/grants/index.html.erb" => "admin-only bg-blue-100",
"app/views/scholarships/index.html.erb" => "admin-only bg-blue-100",
"app/views/form_submissions/index.html.erb" => "admin-only bg-blue-100",
# show
"app/views/banners/show.html.erb" => "admin-only bg-blue-100",
"app/views/categories/show.html.erb" => "admin-only bg-blue-100",
Expand Down