Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,6 @@ jobs:
MEMCACHE_SERVERS: localhost:${{ job.services.memcached.ports[11211] }}
REDIS_URL: redis://localhost:${{ job.services.redis.ports[6379] }}
ORCID_CLIENT_ID: ${{ secrets.ORCID_CLIENT_ID_FOR_TESTING }}
ORCID_AUTO_UPDATE_CLIENT_ID: ${{ secrets.ORCID_CLIENT_ID_FOR_TESTING }}
ORCID_SEARCH_AND_LINK_CLIENT_ID: ${{ secrets.ORCID_CLIENT_ID_FOR_TESTING }}
ORCID_TOKEN: ${{ secrets.ORCID_TOKEN_FOR_TESTING }}
run: |
bundle exec rubocop
Expand Down
17 changes: 16 additions & 1 deletion app/controllers/users/omniauth_callbacks_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ def globus

def orcid
auth = request.env["omniauth.auth"]
omni_params = request.env["omniauth.params"]
omniauth = flash[:omniauth] || {}

if current_user.present?
Expand All @@ -126,6 +127,14 @@ def orcid
if @user.persisted?
sign_in @user

# Refresh ORCID token if the flag isn't explicitly false
if omni_params["fetch_token"] != "false"
@user.update(orcid_expires_at: User.timestamp(auth.credentials),
orcid_token: auth.credentials.token)
logger.info "ORCID token: #{@user.orcid_token} (#{auth.credentials.token})"
flash[:notice] = "ORCID token successfully refreshed."
end

cookies[:_datacite] = encode_cookie(@user.jwt)

if stored_location_for(:user) == ENV["BLOG_URL"] + "/admin/"
Expand All @@ -142,7 +151,13 @@ def orcid

netlify_response(token: token, content: content)
else
redirect_to stored_location_for(:user) || setting_path("me")

# Redirect to Commons if the flag isn't explicitly false. Otherwise redirect to profile settings
if omni_params["redirect_to_commons"] != "false"
redirect_to "#{ENV['COMMONS_URL']}/orcid.org/#{current_user.orcid}"
else
redirect_to stored_location_for(:user) || setting_path("me")
end
end
else
flash[:alert] = @user.errors.map { |k, v| "#{k}: #{v}" }.join("<br />").html_safe || "Error signing in with #{provider}"
Expand Down
223 changes: 0 additions & 223 deletions app/controllers/users/orcid_controller.rb

This file was deleted.

11 changes: 1 addition & 10 deletions app/models/claim.rb
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ def collect_data(options = {})
return OpenStruct.new(body: { "errors" => [{ "title" => "Missing data" }] }) if work.data.nil?

# orcid_token has expired, but is not default 1970-01-01
return OpenStruct.new(body: { "errors" => [{ "status" => 401, "title" => "token has expired." }] }) if orcid_token_expired
return OpenStruct.new(body: { "errors" => [{ "status" => 401, "title" => "token has expired." }] }) if (Date.new(1970, 1, 2).beginning_of_day..Date.today.end_of_day) === user.orcid_expires_at

# Don't go to orcid if we've got a claimed_at date but marked as still to create with no put_code
# return OpenStruct.new(body: { "skip" => true, "reason" => "Already claimed." }) if to_be_created? && !put_code.present? && claimed_at.present?
Expand All @@ -280,15 +280,6 @@ def create_uuid
write_attribute(:uuid, SecureRandom.uuid) if uuid.blank?
end

def orcid_token
source_id == "orcid_search" ? user.orcid_search_and_link_access_token : user.orcid_auto_update_access_token
end

def orcid_token_expired
expires_at = source_id == "orcid_search" ? user.orcid_search_and_link_expires_at : user.orcid_auto_update_expires_at
(Date.new(1970, 1, 2).beginning_of_day..Date.today.end_of_day) === expires_at
end

def work
sandbox = ENV["SANDBOX"].present? || (ENV["ORCID_URL"] == "https://sandbox.orcid.org")
# Note that if this is ever intended in future to support claiming for non datacite dois
Expand Down
24 changes: 2 additions & 22 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,6 @@ class User < ApplicationRecord
indexes :role_id, type: :keyword
indexes :role_name, type: :keyword
indexes :orcid_token, type: :keyword
indexes :orcid_auto_update_access_token, type: :keyword
indexes :orcid_auto_update_refresh_token, type: :keyword
indexes :orcid_auto_update_expires_at, type: :date
indexes :orcid_search_and_link_access_token, type: :keyword
indexes :orcid_search_and_link_refresh_token, type: :keyword
indexes :orcid_search_and_link_expires_at, type: :date
indexes :created, type: :date
indexes :updated, type: :date
indexes :orcid_expires_at, type: :date
Expand Down Expand Up @@ -112,12 +106,6 @@ def as_indexed_json(_options = {})
"is_active" => is_active,
"orcid_token" => orcid_token,
"orcid_expires_at" => orcid_expires_at,
"orcid_auto_update_access_token" => orcid_auto_update_access_token,
"orcid_auto_update_refresh_token" => orcid_auto_update_refresh_token,
"orcid_auto_update_expires_at" => orcid_auto_update_expires_at,
"orcid_search_and_link_access_token" => orcid_search_and_link_access_token,
"orcid_search_and_link_refresh_token" => orcid_search_and_link_refresh_token,
"orcid_search_and_link_expires_at" => orcid_search_and_link_expires_at,
"claims_count" => claims_count,
}
end
Expand All @@ -133,10 +121,6 @@ def self.query_aggregations
}
end

def self.from_orcid(uid)
where(uid: uid).first_or_create
end

def self.from_omniauth(auth, options = {})
where(provider: options[:provider], uid: options[:uid] || auth.uid).first_or_create
end
Expand Down Expand Up @@ -319,10 +303,7 @@ def self.get_auth_hash(auth, options = {})
github: options.fetch("github", nil),
github_uid: options.fetch("github_uid", nil),
github_token: options.fetch("github_token", nil),
email: auth.extra.id_info? ? auth.extra.id_info.email : nil,
orcid_token: auth.credentials.token,
orcid_expires_at: User.timestamp(auth.credentials)
}.compact
email: auth.extra.id_info? ? auth.extra.id_info.email : nil }.compact
end

def self.timestamp(credentials)
Expand Down Expand Up @@ -382,8 +363,7 @@ def get_data(options = {})

Array.wrap(works).select do |work|
work.extend Hashie::Extensions::DeepFetch
source_client_id = work.deep_fetch("work-summary", 0, "source", "source-client-id", "path") { nil }
source_client_id == ENV["ORCID_AUTO_UPDATE_CLIENT_ID"] || source_client_id == ENV["ORCID_SEARCH_AND_LINK_CLIENT_ID"]
work.deep_fetch("work-summary", 0, "source", "source-client-id", "path") { nil } == ENV["ORCID_CLIENT_ID"]
end
end

Expand Down
26 changes: 6 additions & 20 deletions app/views/settings/_show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -75,28 +75,14 @@
</div>
<div class="panel-body">
<dl class="dl-horizontal">
<dt>Link Works to ORCID</dt>
<dt>ORCID Permissions</dt>
<dd>
<% if @user.orcid_search_and_link_access_token %>
<p>Revoke access for DataCite to link DataCite DOIs to you ORCID record using the "Add to ORCID Record" button in DataCite Commons</p>
<%= link_to "<img id=\"orcid-logo\" src=\"#{ENV["CDN_URL"]}/images/orcid.png\" alt=\"ORCID icon\"/>&nbsp;Click to Disable".html_safe, :orcid_search_and_link_revoke, method: :get, :id => "orcid-search-and-link-disable", class: 'btn btn-social btn-orcid btn-fill' %>
<% if @user.orcid_expires_at && Time.zone.now < @user.orcid_expires_at %>
<p>Delete ORCID token to no longer allow DataCite to update your ORCID record.</p>
<%= link_to "<img id=\"orcid-logo\" src=\"#{ENV["CDN_URL"]}/images/orcid.png\" alt=\"ORCID icon\"/>&nbsp;Delete ORCID Token".html_safe, setting_path("me", user: { orcid_token: nil, orcid_expires_at: Time.zone.now }), { method: :put, remote: true, class: 'btn btn-social btn-orcid btn-fill' } %>
<% else %>
<p>Allow DataCite to link DataCite DOIs to you ORCID record using the "Add to ORCID Record" button in DataCite Commons</p>
<%= link_to "<img id=\"orcid-logo\" src=\"#{ENV["CDN_URL"]}/images/orcid.png\" alt=\"ORCID icon\"/>&nbsp;Click to Enable".html_safe, :orcid_search_and_link_auth, method: :get, :id => "orcid-search-and-link-enable", class: 'btn btn-social btn-orcid btn-fill' %>
<% end %>
</dd>
</dl>
</div>
<div class="panel-body">
<dl class="dl-horizontal">
<dt>ORCID Auto-Update</dt>
<dd>
<% if @user.orcid_auto_update_access_token %>
<p>Revoke access DataCite to add Works to your ORCID record automatically when your ORCID is included as a creator in a DataCite DOI metadata</p>
<%= link_to "<img id=\"orcid-logo\" src=\"#{ENV["CDN_URL"]}/images/orcid.png\" alt=\"ORCID icon\"/>&nbsp;Click to Disable".html_safe, :orcid_auto_update_revoke, method: :get, :id => "orcid-auto-update-disable", class: 'btn btn-social btn-orcid btn-fill' %>
<% else %>
<p>Allow DataCite to add Works to your ORCID record automatically when your ORCID is included as a creator in a DataCite DOI metadata</p>
<%= link_to "<img id=\"orcid-logo\" src=\"#{ENV["CDN_URL"]}/images/orcid.png\" alt=\"ORCID icon\"/>&nbsp;Click to Enable".html_safe, :orcid_auto_update_auth, method: :get, :id => "orcid-auto-update-enable", class: 'btn btn-social btn-orcid btn-fill' %>
<p>Get ORCID token to allow DataCite to update your ORCID record.</p>
<%= link_to "<img id=\"orcid-logo\" src=\"#{ENV["CDN_URL"]}/images/orcid.png\" alt=\"ORCID icon\"/>&nbsp;Get ORCID Token".html_safe, user_orcid_omniauth_authorize_path(redirect_to_commons: false), method: :post, :id => "sign-in-orcid", class: 'btn btn-social btn-orcid btn-fill' %>
<% end %>
</dd>
</dl>
Expand Down
1 change: 0 additions & 1 deletion config/initializers/devise.rb
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,6 @@
ENV["ORCID_CLIENT_SECRET"],
member: ENV["ORCID_MEMBER"],
sandbox: (ENV["ORCID_URL"] == "https://sandbox.orcid.org"),
scope: "/authenticate",
provider_ignores_state: true

config.omniauth :github, ENV["GITHUB_CLIENT_ID"],
Expand Down
Loading