Skip to content

Commit 3b25f53

Browse files
committed
Distinguish authenticated/unauthenticated ORCID IDs. #783
1 parent 39adbba commit 3b25f53

9 files changed

Lines changed: 56 additions & 4 deletions

File tree

Lines changed: 5 additions & 0 deletions
Loading
Lines changed: 4 additions & 0 deletions
Loading

app/helpers/users_helper.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,19 @@ def self.user_profile_resource_limit
55
30
66
end
77

8+
def orcid_link(profile, *opts)
9+
content_tag(:span) do
10+
if profile.orcid_authenticated?
11+
concat image_tag('ORCID-iD_icon_vector.svg', size: 16)
12+
concat ' '
13+
concat external_link(profile.orcid.sub(OrcidValidator::ORCID_PREFIX, ''), profile.orcid, *opts)
14+
else profile.orcid.present?
15+
concat image_tag('ORCID-iD_icon_unauth_vector.svg', size: 16)
16+
concat ' '
17+
concat external_link(profile.orcid.sub(OrcidValidator::ORCID_PREFIX, ''), profile.orcid, *opts)
18+
concat ' (Unauthenticated)'
19+
end
20+
end
21+
end
22+
823
end

app/views/trainers/show.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
<!-- Field: orcid -->
2222
<% if @trainer.orcid.present? %>
2323
<div class="url-wrap">
24-
<%= external_link @trainer.orcid, @trainer.orcid, class: 'h5', target: '_blank', rel: 'noopener', track: true %>
24+
<%= orcid_link(@trainer, class: 'h5', track: true) %>
2525
</div>
2626
<% end %>
2727

app/views/users/show.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
<% if @user.profile.orcid.blank? %>
5151
<span class="empty">None specified</span>
5252
<% else %>
53-
<%= link_to @user.profile.orcid, @user.profile.orcid, rel: 'nofollow', target: '_blank' %>
53+
<%= orcid_link(@user.profile) %>
5454
<% end %>
5555
</p>
5656

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class AddOrcidAuthenticatedToProfiles < ActiveRecord::Migration[7.2]
2+
def change
3+
add_column :profiles, :orcid_authenticated, :boolean, default: false
4+
end
5+
end

db/schema.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#
1111
# It's strongly recommended that you check this file into your version control system.
1212

13-
ActiveRecord::Schema[7.2].define(version: 2025_03_25_151745) do
13+
ActiveRecord::Schema[7.2].define(version: 2025_10_13_115523) do
1414
# These are extensions that must be enabled in order to support this database
1515
enable_extension "plpgsql"
1616

@@ -452,6 +452,7 @@
452452
t.string "social_media", default: [], array: true
453453
t.string "type", default: "Profile"
454454
t.string "fields", default: [], array: true
455+
t.boolean "orcid_authenticated", default: false
455456
t.index ["slug"], name: "index_profiles_on_slug", unique: true
456457
end
457458

test/fixtures/profiles.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ trainer_one_profile:
6868
expertise_technical: ['python', 'R']
6969
public: true
7070
type: Trainer
71+
orcid_authenticated: true
7172

7273
trainer_two_profile:
7374
user: private_user
@@ -76,13 +77,14 @@ trainer_two_profile:
7677
image_url:
7778
email: samael@research.org
7879
website: ''
79-
orcid: ''
80+
orcid: https://orcid.org/0000-0002-0048-3300
8081
description: none
8182
location: 'Sydney, Australia'
8283
experience: much
8384
expertise_technical: ['java', 'python', 'ruby']
8485
public: false
8586
type: Profile
87+
orcid_authenticated: false
8688

8789
admin_trainer_profile:
8890
user: admin_trainer

test/helpers/users_helper_test.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
require 'test_helper'
2+
3+
class UsersHelperTest < ActionView::TestCase
4+
include ApplicationHelper
5+
6+
test 'displays authenticated orcid link' do
7+
profile = profiles(:trainer_one_profile)
8+
l = orcid_link(profile)
9+
assert_includes l, 'ORCID-iD_icon_vector.svg'
10+
assert_not_includes l, 'Unauthenticated'
11+
end
12+
13+
test 'displays unauthenticated orcid link' do
14+
profile = profiles(:trainer_two_profile)
15+
l = orcid_link(profile)
16+
assert_includes l, 'ORCID-iD_icon_unauth_vector.svg'
17+
assert_includes l, 'Unauthenticated'
18+
end
19+
20+
end

0 commit comments

Comments
 (0)