diff --git a/app/controllers/scholarships_controller.rb b/app/controllers/scholarships_controller.rb index 2ffae041a9..8424563c09 100644 --- a/app/controllers/scholarships_controller.rb +++ b/app/controllers/scholarships_controller.rb @@ -13,6 +13,10 @@ def index { grant: :donor }, { recipient: [ { affiliations: { organization: :addresses } }, { event_registrations: :event } ] } ) + if params[:recipient_id].present? + 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 diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 5d84242875..afae537cbc 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -256,7 +256,9 @@ 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" }.freeze # Themed card-style link to a filtered index. The collection drives the diff --git a/app/views/people/_associated_records.html.erb b/app/views/people/_associated_records.html.erb new file mode 100644 index 0000000000..cc5e56fa68 --- /dev/null +++ b/app/views/people/_associated_records.html.erb @@ -0,0 +1,9 @@ +<% return unless person.persisted? %> +<% email = person.preferred_email %> +<% notifications = email.present? ? Notification.email(email) : Notification.none %> + diff --git a/app/views/people/_form.html.erb b/app/views/people/_form.html.erb index 4ea491e6c5..845493f403 100644 --- a/app/views/people/_form.html.erb +++ b/app/views/people/_form.html.erb @@ -479,6 +479,18 @@ + <% if f.object.persisted? %> + <% person = f.object.respond_to?(:object) ? f.object.object : f.object %> +
+
+ Associated records +
+
+ <%= render "associated_records", person: person %> +
+
+ <% end %> + <% if f.object.persisted? %> <% if allowed_to?(:manage?, Comment) %> diff --git a/app/views/scholarships/index.html.erb b/app/views/scholarships/index.html.erb index e6d0b703af..b6c3bbdde2 100644 --- a/app/views/scholarships/index.html.erb +++ b/app/views/scholarships/index.html.erb @@ -24,6 +24,12 @@ + <% if @recipient %> +
+ Filtered to <%= @recipient.name %> + <%= link_to "Clear", scholarships_path, class: "text-blue-600 hover:underline" %> +
+ <% end %> <% if @funder_groups.any? %>
<%= render partial: "funder_group", collection: @funder_groups, as: :funder_group %> diff --git a/spec/requests/people_associated_records_spec.rb b/spec/requests/people_associated_records_spec.rb new file mode 100644 index 0000000000..8803168fe7 --- /dev/null +++ b/spec/requests/people_associated_records_spec.rb @@ -0,0 +1,26 @@ +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, and notifications" do + person = create(:person) + create(:event_registration, registrant: person) + create(:workshop_log, created_by: person.user) + create(:scholarship, recipient: 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(notifications_path(email: person.preferred_email)) + end + end +end diff --git a/spec/requests/scholarships_spec.rb b/spec/requests/scholarships_spec.rb index 2bf600d32e..d7dbbd21d5 100644 --- a/spec/requests/scholarships_spec.rb +++ b/spec/requests/scholarships_spec.rb @@ -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