Skip to content

Commit

Permalink
Makes ORCid readonly. (#1218)
Browse files Browse the repository at this point in the history
Closes #518.

- updates psu_identity to 0.4.0
- on login, an actor record gets it's ORCiD from directory-service
  • Loading branch information
whereismyjetpack committed Feb 4, 2022
1 parent 0dc39c7 commit 32319cb
Show file tree
Hide file tree
Showing 11 changed files with 26 additions and 54 deletions.
1 change: 1 addition & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Metrics/BlockLength:

Metrics/CyclomaticComplexity:
Exclude:
- 'app/models/user.rb'
- 'app/services/doi_service.rb'
- 'app/services/authorship_migration/work_version_creation_migration.rb'

Expand Down
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ gem 'omniauth-oauth2', '~> 1.7'
gem 'omniauth-rails_csrf_protection', '~> 1.0'
gem 'paper_trail'
gem 'pg', '>= 0.18', '< 2.0'
gem 'psu_identity', '~> 0.3'
gem 'psu_identity', '0.4.0'
gem 'puma', '~> 4.3'
gem 'pundit'
gem 'qa'
Expand Down
5 changes: 3 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -298,9 +298,10 @@ GEM
pry (~> 0.13.0)
pry-rails (0.3.9)
pry (>= 0.10.4)
psu_identity (0.3.0)
psu_identity (0.4.0)
faraday (~> 1.0)
json
oauth2
rake (>= 12.0)
public_suffix (4.0.6)
puma (4.3.9)
Expand Down Expand Up @@ -550,7 +551,7 @@ DEPENDENCIES
pg (>= 0.18, < 2.0)
pry-byebug
pry-rails
psu_identity (~> 0.3)
psu_identity (= 0.4.0)
puma (~> 4.3)
pundit
qa
Expand Down
1 change: 0 additions & 1 deletion app/controllers/dashboard/profiles_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ def creator_params
:surname,
:display_name,
:email,
:orcid,
user_attributes: [
:id,
:admin_enabled,
Expand Down
9 changes: 9 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ def self.from_omniauth(auth)
actor.email = actor.email.presence || auth.info.email
actor.given_name = actor.given_name.presence || auth.info.given_name
actor.surname = actor.surname.presence || auth.info.surname || auth.info.family_name
actor.orcid = actor.orcid.presence || directory_orcid(auth.uid)
end

transaction do
Expand Down Expand Up @@ -103,4 +104,12 @@ def guest?
def name
actor.display_name
end

def self.directory_orcid(uid)
linked_orcid = PsuIdentity::DirectoryService::Client.new.userid(uid).orc_id
OrcidId.new(linked_orcid).to_s
rescue StandardError => e
logger.error(e)
nil
end
end
3 changes: 2 additions & 1 deletion app/views/dashboard/profiles/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
<%= render 'form_fields/text',
form: form,
attribute: :orcid,
data: { controller: 'inputmask' } %>
data: { controller: 'inputmask' },
readonly: true %>
<%= render 'user_fields', form: form %>
<%= render 'admin_fields', form: form if @actor.user.admin_available? %>
</div>
Expand Down
1 change: 1 addition & 0 deletions app/views/form_fields/_text.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
placeholder: true,
required: local_assigns[:required].presence,
data: local_assigns[:data],
readonly: local_assigns[:readonly].presence,
aria: { describedby: hint.dom_id } %>
<%= form.label attribute %>
Expand Down
2 changes: 1 addition & 1 deletion config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ en:
version_name: For datasets or software using semantic versioning (e.g., x.y.z)
rights: The license you select determines how your work can be used by others. [Read More](https://docs.scholarsphere.psu.edu/guides/licenses/)
actor:
orcid: "This is a 16-digit identifier in the format ####-####-####-####"
orcid: "[Click here to link your ORCiD](https://guides.libraries.psu.edu/orcid)"
display_name: >
When you create new works, this will be used as the initial value for the Creator field. For example, if your
first and last name are Pat Researcher, you might wish to set this to "Dr. Pat Q. Researcher PhD."
Expand Down
4 changes: 1 addition & 3 deletions spec/controllers/dashboard/profiles_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
'display_name' => "Dr. #{actor_attrs[:given_name]} #{actor_attrs[:surname]} PhD",
'given_name' => actor_attrs[:given_name],
'surname' => actor_attrs[:surname],
'email' => actor_attrs[:email],
'orcid' => actor_attrs[:orcid]
'email' => actor_attrs[:email]
}
}

Expand Down Expand Up @@ -61,7 +60,6 @@
expect(actor.given_name).to eq actor_attrs[:given_name]
expect(actor.surname).to eq actor_attrs[:surname]
expect(actor.email).to eq actor_attrs[:email]
expect(actor.orcid).to eq actor_attrs[:orcid]
end

it "redirects to the user's dashboard" do
Expand Down
8 changes: 7 additions & 1 deletion spec/features/dashboard/profile_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@
context 'with a standard user' do
let(:user) { create(:user, opt_in_stats_email: true) }

it 'does not have an editable orcid field' do
visit edit_dashboard_profile_path
expect(page).to have_content('Edit Profile')
expect(page).to have_field('ORCiD', readonly: true)
expect(page).to have_field('Email', readonly: false)
end

it 'displays and updates my profile information' do
visit edit_dashboard_profile_path
expect(page).to have_content('Edit Profile')
Expand All @@ -23,7 +30,6 @@
user.actor.reload
expect(user.actor.given_name).to eq(attributes[:given_name])
expect(user.actor.surname).to eq(attributes[:surname])
expect(user.actor.orcid).to eq(attributes[:orcid])
expect(user.actor.psu_id).to eq(user.access_id)
user.reload
expect(user.opt_in_stats_email).to be(false)
Expand Down
44 changes: 0 additions & 44 deletions spec/models/actor_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,32 +47,6 @@

it { is_expected.not_to be_valid }
end

context 'when orcid is present but psu_id is not' do
subject { build(:actor, psu_id: nil) }

it { is_expected.to be_valid }
end

context 'when psu_id is present but orcid is not' do
subject { build(:actor, orcid: nil) }

it { is_expected.to be_valid }
end

context 'when the psu_id is present and the orcid is invalid' do
subject { build(:actor, orcid: 'asdf') }

it { is_expected.not_to be_valid }
end

context 'when the orcid is present and the psu_id is invalid' do
subject { build(:actor, psu_id: 'abc123') }

before { create(:actor, psu_id: 'abc123') }

it { is_expected.not_to be_valid }
end
end

describe 'after_save' do
Expand Down Expand Up @@ -159,22 +133,4 @@
it_behaves_like 'a singlevalued field', :psu_id
it_behaves_like 'a singlevalued field', :orcid
end

describe '#orcid' do
context 'when set to valid value' do
subject { described_class.new(surname: 'Valid Orcid', orcid: FactoryBotHelpers.generate_orcid) }

it { is_expected.to be_valid }
end

context 'when set to an invalid value' do
subject { actor.errors.full_messages }

let(:actor) { described_class.new(orcid: Faker::Number.leading_zero_number(digits: 15)) }

before { actor.validate }

it { is_expected.to include('ORCiD must be valid') }
end
end
end

0 comments on commit 32319cb

Please sign in to comment.