From 6b0b7f57e0d123919bb27dca90cc65cb8a592974 Mon Sep 17 00:00:00 2001 From: Finn Bacall Date: Wed, 15 Apr 2026 17:07:03 +0100 Subject: [PATCH 1/3] Fix 500 error when a person is linked to a non-trainer profile. Fixes #1280 --- app/helpers/materials_helper.rb | 3 ++- test/controllers/materials_controller_test.rb | 22 +++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/app/helpers/materials_helper.rb b/app/helpers/materials_helper.rb index d3a5f59db..d7b72b8fc 100644 --- a/app/helpers/materials_helper.rb +++ b/app/helpers/materials_helper.rb @@ -105,7 +105,8 @@ def display_people(resource, attribute) display_attribute(resource, attribute) do |values| html = values.map do |person| if person.profile - link_to(person.profile.full_name, person.profile) + target = person.profile.is_a?(Trainer) ? person.profile : person.profile.user + link_to(person.profile.full_name, target) elsif person.orcid.present? image_tag('ORCID-iD_icon_vector.svg', size: 16) + ' ' + external_link(person.display_name, person.orcid_url) diff --git a/test/controllers/materials_controller_test.rb b/test/controllers/materials_controller_test.rb index 5fab13938..383a1c8a5 100644 --- a/test/controllers/materials_controller_test.rb +++ b/test/controllers/materials_controller_test.rb @@ -1629,6 +1629,28 @@ class MaterialsControllerTest < ActionController::TestCase end end + test 'should display non-trainer author with linked ORCID' do + jc = profiles(:trainer_one_profile) + jc.update_column(:public, false) + jc.update_column(:type, 'Profile') + assert @material.update(authors: [{ name: 'John Doe' }, + { name: 'Jane Smith', orcid: '0000-0001-9999-9990' }], + contributors: [{ name: 'Jos Ca', orcid: '0000-0002-1825-0097' }]) + + get :show, params: { id: @material.id } + + assert_select '.authors', text: 'Authors: John Doe, Jane Smith' + assert_select '.authors a', count: 1 do + assert_select '[href=?]', 'https://orcid.org/0000-0001-9999-9990' + end + + assert_select '.contributors', { text: 'Contributors: Josiah Carberry' }, + "Should use name from person's profile, if linked" + assert_select '.contributors a', count: 1 do + assert_select '[href=?]', user_path(jc.user) + end + end + test 'should update material authors using structured authors' do sign_in @material.user update = @updated_material.merge(authors: [ From 4a788f36c60376f9b5534ea916cb53c5053b212d Mon Sep 17 00:00:00 2001 From: Finn Bacall Date: Wed, 15 Apr 2026 17:15:19 +0100 Subject: [PATCH 2/3] Apply suggestions from code review Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- test/controllers/materials_controller_test.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/controllers/materials_controller_test.rb b/test/controllers/materials_controller_test.rb index 383a1c8a5..68f29d4b5 100644 --- a/test/controllers/materials_controller_test.rb +++ b/test/controllers/materials_controller_test.rb @@ -1629,10 +1629,10 @@ class MaterialsControllerTest < ActionController::TestCase end end - test 'should display non-trainer author with linked ORCID' do + test 'should display non-trainer contributor with linked ORCID' do jc = profiles(:trainer_one_profile) - jc.update_column(:public, false) - jc.update_column(:type, 'Profile') + jc.update!(public: false) + jc = Profile.find(jc.id) assert @material.update(authors: [{ name: 'John Doe' }, { name: 'Jane Smith', orcid: '0000-0001-9999-9990' }], contributors: [{ name: 'Jos Ca', orcid: '0000-0002-1825-0097' }]) From bb52f2471a2f55a413fd5ea997895fd1b5c10cee Mon Sep 17 00:00:00 2001 From: Finn Bacall Date: Wed, 15 Apr 2026 17:30:29 +0100 Subject: [PATCH 3/3] Blank out website and image to skip HTTP URL validation --- test/controllers/materials_controller_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/controllers/materials_controller_test.rb b/test/controllers/materials_controller_test.rb index 68f29d4b5..c5ae48ad1 100644 --- a/test/controllers/materials_controller_test.rb +++ b/test/controllers/materials_controller_test.rb @@ -1631,7 +1631,7 @@ class MaterialsControllerTest < ActionController::TestCase test 'should display non-trainer contributor with linked ORCID' do jc = profiles(:trainer_one_profile) - jc.update!(public: false) + jc.update!(public: false, website: nil, image_url: nil) jc = Profile.find(jc.id) assert @material.update(authors: [{ name: 'John Doe' }, { name: 'Jane Smith', orcid: '0000-0001-9999-9990' }],