Skip to content

Commit f81bda9

Browse files
committed
Only query profiles with authenticated ORCIDs
1 parent 0c35174 commit f81bda9

2 files changed

Lines changed: 15 additions & 6 deletions

File tree

app/models/profile.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,9 @@ def self.starting_with(query)
7272
end
7373

7474
def self.query(query, limit = nil)
75-
q = visible.select(:id, :firstname, :surname, :orcid, :orcid_authenticated).starting_with(query).distinct
75+
q = visible.where.not(orcid: nil).where(orcid_authenticated: true)
76+
.select(:id, :firstname, :surname, :orcid, :orcid_authenticated)
77+
.starting_with(query).distinct
7678
q = q.limit(limit) if limit
7779
q.order(firstname: :asc, surname: :asc, orcid: :asc)
7880
end

test/models/profile_test.rb

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -183,15 +183,22 @@ class ProfileTest < ActiveSupport::TestCase
183183
end
184184

185185
test 'query' do
186-
regi = Profile.query('regi')
187-
assert_equal 1, regi.length
188-
assert_includes regi, profiles(:one)
186+
josi = Profile.query('josi')
187+
assert_equal 1, josi.length
188+
assert_includes josi, profiles(:trainer_one_profile).becomes(Profile) # Need to cast back to Profile because it is a Trainer otherwise
189+
190+
# Excludes unauthenticated orcids
191+
unauth = profiles(:trainer_two_profile)
192+
assert_includes Profile.starting_with('luci'), unauth
193+
unauth_q = Profile.query('luci')
194+
assert_equal 0, unauth_q.length
189195

190196
# Excludes non-visible:
191197
banned = profiles(:banned_user_profile)
192198
banned.update!(firstname: 'Banned')
199+
assert banned.authenticate_orcid('0009-0006-0987-5702')
193200
assert_includes Profile.starting_with('banned'), banned
194-
banned = Profile.query('Banned')
195-
assert_equal 0, banned.length
201+
banned_q = Profile.query('Banned')
202+
assert_equal 0, banned_q.length
196203
end
197204
end

0 commit comments

Comments
 (0)