Skip to content

Commit

Permalink
Merge pull request #292 from CDL-Dryad/curator-orcid-trigger
Browse files Browse the repository at this point in the history
Display ORCID invite links to curators
  • Loading branch information
sfisher authored Dec 8, 2020
2 parents 91f5bda + 0452950 commit e67ffd9
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 6 deletions.
28 changes: 27 additions & 1 deletion spec/models/stash_engine/author_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ module StashEngine
describe Author do

before(:each) do
@resource = create(:resource)
@ident = create(:identifier)
@resource = create(:resource,
identifier: @ident,
tenant_id: 'dryad')
end

describe :new do
Expand Down Expand Up @@ -35,6 +38,29 @@ module StashEngine
end
end

describe :orcid_invite_path do
it 'generates an orcid_invite_path when needed' do
author = create(:author)
expect(author.orcid_invite_path).to include('invitation')
end

it 'delivers the correct orcid_invite_path' do
author = create(:author,
resource: @resource)
orcid_invite = StashEngine::OrcidInvitation.create(
email: author.author_email,
identifier_id: @resource.identifier_id,
first_name: author.author_first_name,
last_name: author.author_last_name,
secret: SecureRandom.urlsafe_base64,
invited_at: Time.new.utc
)

expect(author.orcid_invite_path).to include("invitation=#{orcid_invite.secret}")
expect(author.orcid_invite_path).to include(@resource.identifier.identifier)
end
end

describe :author_orcid do
it 'is optional' do
author = Author.create(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,18 @@
<%= f.hidden_field :id %>
<%= hidden_field_tag(:form_id, form_id) %>
<% end %>

<!-- Begin Orcid ID Component -->
<div class="c-orcid">
<div class="c-orcid">
<% if author&.id &&
author.author_orcid.blank? &&
author.resource.identifier.pub_state == 'published' &&
current_user&.role == 'superuser'
%>
<span>
Link to associate ORCID: <%= author.orcid_invite_path %>
</span>
<% end %>
<% unless author.blank? || author.author_orcid.blank? %>
<span class="c-orcid__icon"></span>
<% if StashEngine.app.orcid.site == "https://sandbox.orcid.org/" %>
Expand All @@ -35,9 +45,9 @@
<%= link_to "https://orcid.org/#{author.author_orcid}", "https://orcid.org/#{author.author_orcid}",target: '_blank', class: 'c-orcid__id' %>
<% end %>
<% end %>
</div>
</div>
<!-- End Orcid ID Component -->

<div>

</div>
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def ajax_blocked

def valid_edit_code?
edit_code = params[:edit_code] || session[:edit_code]
if defined?(resource) && resource.present? && (edit_code == resource.identifier.edit_code)
if defined?(resource) && resource.present? && (edit_code == resource&.identifier&.edit_code)
# Code is valid, so save it in the session for later use (and implicitly return true)
session[:edit_code] = edit_code
else
Expand Down
18 changes: 18 additions & 0 deletions stash/stash_engine/app/models/stash_engine/author.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,24 @@ def init_user_orcid
end
after_save :init_user_orcid

def orcid_invite_path
orcid_invite = StashEngine::OrcidInvitation.where(email: author_email, identifier_id: resource.identifier_id)&.first

# Ensure an invite exists -- it may not for a legacy dataset that never received invites,
# or if the author_email has changed since the original creation.
orcid_invite ||= StashEngine::OrcidInvitation.create(
email: author_email,
identifier_id: resource.identifier_id,
first_name: author_first_name,
last_name: author_last_name,
secret: SecureRandom.urlsafe_base64,
invited_at: Time.new.utc
)

path = StashEngine::Engine.routes.url_helpers.show_path(orcid_invite.identifier.to_s, invitation: orcid_invite.secret)
orcid_invite.landing(path)
end

private

def strip_whitespace
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ class OrcidInvitation < ApplicationRecord
belongs_to :identifier, class_name: 'StashEngine::Identifier'

def resource
@resource ||= identifier.last_submitted_resource
@resource ||= identifier.last_submitted_resource || identifier.latest_resource
end

def tenant
Expand Down

0 comments on commit e67ffd9

Please sign in to comment.