orcid 0.0.4 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +10 -0
- data/.hound.yml +793 -0
- data/.travis.yml +14 -0
- data/Gemfile +14 -0
- data/README.md +107 -6
- data/Rakefile +17 -9
- data/app/assets/images/orcid/.keep +0 -0
- data/app/controllers/orcid/application_controller.rb +13 -4
- data/app/controllers/orcid/profile_connections_controller.rb +34 -6
- data/app/controllers/orcid/profile_requests_controller.rb +18 -15
- data/app/models/orcid/profile.rb +15 -5
- data/app/models/orcid/profile_connection.rb +20 -20
- data/app/models/orcid/profile_request.rb +39 -20
- data/app/models/orcid/work.rb +45 -55
- data/app/models/orcid/work/xml_parser.rb +45 -0
- data/app/models/orcid/work/xml_renderer.rb +29 -0
- data/app/services/orcid/remote/profile_creation_service.rb +40 -32
- data/app/services/orcid/remote/profile_query_service.rb +82 -0
- data/app/services/orcid/remote/profile_query_service/query_parameter_builder.rb +43 -0
- data/app/services/orcid/remote/profile_query_service/search_response.rb +31 -0
- data/app/services/orcid/remote/service.rb +16 -13
- data/app/services/orcid/remote/work_service.rb +58 -43
- data/app/templates/orcid/work.template.v1.1.xml.erb +32 -1
- data/app/views/orcid/profile_connections/_orcid_connector.html.erb +14 -0
- data/app/views/orcid/profile_connections/new.html.erb +4 -4
- data/bin/rails +8 -0
- data/config/{application.yml → application.yml.example} +3 -13
- data/config/locales/orcid.en.yml +5 -1
- data/config/routes.rb +4 -2
- data/lib/generators/orcid/install/install_generator.rb +46 -7
- data/lib/orcid.rb +23 -11
- data/lib/orcid/configuration.rb +32 -13
- data/lib/orcid/configuration/provider.rb +27 -13
- data/lib/orcid/engine.rb +20 -4
- data/lib/orcid/exceptions.rb +33 -4
- data/lib/orcid/named_callbacks.rb +3 -1
- data/lib/orcid/spec_support.rb +19 -9
- data/lib/orcid/version.rb +1 -1
- data/lib/tasks/orcid_tasks.rake +3 -3
- data/orcid.gemspec +51 -0
- data/rubocop.txt +1164 -0
- data/script/fast_specs +22 -0
- data/spec/controllers/orcid/profile_connections_controller_spec.rb +101 -0
- data/spec/controllers/orcid/profile_requests_controller_spec.rb +116 -0
- data/spec/factories/orcid_profile_requests.rb +11 -0
- data/spec/factories/users.rb +9 -0
- data/spec/fast_helper.rb +12 -0
- data/spec/features/batch_profile_spec.rb +31 -0
- data/spec/features/non_ui_based_interactions_spec.rb +117 -0
- data/spec/features/profile_connection_feature_spec.rb +19 -0
- data/spec/features/public_api_query_spec.rb +36 -0
- data/spec/fixtures/orcid_works.xml +55 -0
- data/spec/lib/orcid/configuration/provider_spec.rb +40 -0
- data/spec/lib/orcid/configuration_spec.rb +38 -0
- data/spec/lib/orcid/named_callbacks_spec.rb +28 -0
- data/spec/lib/orcid_spec.rb +97 -0
- data/spec/models/orcid/profile_connection_spec.rb +81 -0
- data/spec/models/orcid/profile_request_spec.rb +131 -0
- data/spec/models/orcid/profile_spec.rb +76 -0
- data/spec/models/orcid/work/xml_parser_spec.rb +40 -0
- data/spec/models/orcid/work/xml_renderer_spec.rb +18 -0
- data/spec/models/orcid/work_spec.rb +53 -0
- data/spec/services/orcid/remote/profile_creation_service_spec.rb +40 -0
- data/spec/services/orcid/remote/profile_query_service/query_parameter_builder_spec.rb +44 -0
- data/spec/services/orcid/remote/profile_query_service/search_response_spec.rb +14 -0
- data/spec/services/orcid/remote/profile_query_service_spec.rb +118 -0
- data/spec/services/orcid/remote/service_spec.rb +26 -0
- data/spec/services/orcid/remote/work_service_spec.rb +44 -0
- data/spec/spec_helper.rb +99 -0
- data/spec/support/non_orcid_models.rb +11 -0
- data/spec/support/stub_callback.rb +25 -0
- data/spec/test_app_templates/Gemfile.extra +3 -0
- data/spec/test_app_templates/lib/generators/test_app_generator.rb +36 -0
- data/spec/views/orcid/profile_connections/new.html.erb_spec.rb +25 -0
- data/spec/views/orcid/profile_requests/new.html.erb_spec.rb +23 -0
- metadata +119 -29
- data/app/runners/orcid/profile_lookup_runner.rb +0 -33
- data/app/runners/orcid/runner.rb +0 -15
- data/app/services/orcid/remote/profile_lookup_service.rb +0 -56
- data/app/services/orcid/remote/profile_lookup_service/search_response.rb +0 -23
- data/lib/orcid/query_parameter_builder.rb +0 -38
data/.travis.yml
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
source "https://rubygems.org"
|
2
|
+
|
3
|
+
# Declare your gem's dependencies in orcid.gemspec.
|
4
|
+
# Bundler will treat runtime dependencies like base dependencies, and
|
5
|
+
# development dependencies will be added by default to the :development group.
|
6
|
+
gemspec
|
7
|
+
|
8
|
+
# Declare any dependencies that are still in development here instead of in
|
9
|
+
# your gemspec. These might include edge Rails or gems from your path or
|
10
|
+
# Git. Remember to move these dependencies to your gemspec before releasing
|
11
|
+
# your gem to rubygems.org.
|
12
|
+
|
13
|
+
# To use debugger
|
14
|
+
# gem 'debugger'
|
data/README.md
CHANGED
@@ -1,23 +1,124 @@
|
|
1
1
|
# Orcid [](http://badge.fury.io/rb/orcid) [](https://travis-ci.org/jeremyf/orcid)
|
2
2
|
|
3
|
+
A [Rails Engine](https://guides.rubyonrails.org/engines.html) for integrating with [Orcid](https://orcid.org).
|
3
4
|
|
4
|
-
|
5
|
+
To fully interact with the Orcid remote services, you will need to [register your ORCID application profile](#registering-for-an-orcid-application-profile).
|
6
|
+
|
7
|
+
* [Installation](#installation)
|
8
|
+
* [Using the Orcid widget in your application](#using-the-orcid-widget-in-your-application)
|
9
|
+
* [Registering for an ORCID application profile](#registering-for-an-orcid-application-profile)
|
10
|
+
* [Setting up your own ORCIDs in the ORCID Development Sandbox](#setting-up-your-own-orcids-in-the-orcid-development-sandbox)
|
11
|
+
* [Running the tests](#running-the-tests)
|
5
12
|
|
6
13
|
## Installation
|
7
14
|
|
8
15
|
Add this line to your application's Gemfile:
|
9
16
|
|
10
|
-
|
17
|
+
```ruby
|
18
|
+
gem 'orcid'
|
19
|
+
```
|
11
20
|
|
12
21
|
And then execute:
|
13
22
|
|
14
|
-
|
23
|
+
```console
|
24
|
+
$ bundle
|
25
|
+
```
|
26
|
+
|
27
|
+
If bundle fails, you may need to [install Qt](https://github.com/thoughtbot/capybara-webkit/wiki/Installing-Qt-and-compiling-capybara-webkit).
|
28
|
+
|
29
|
+
And then install by running the following:
|
30
|
+
|
31
|
+
```console
|
32
|
+
$ rails generate orcid:install
|
33
|
+
```
|
34
|
+
|
35
|
+
*Note: It will prompt you for your Orcid application secrets.*
|
36
|
+
|
37
|
+
You may find it helpful to review the help text, as there are a few options for the generator.
|
38
|
+
|
39
|
+
```console
|
40
|
+
$ rails generate orcid:install -h
|
41
|
+
```
|
42
|
+
|
43
|
+
## Using the Orcid widget in your application
|
44
|
+
|
45
|
+
In order to facilitate integration of this ORCID gem into your application, a widget has been provided to offer these functions:
|
46
|
+
|
47
|
+
1. Enter a known ORCID and connect to the ORCID repository.
|
48
|
+
1. Look up the ORCID of the current user of your application.
|
49
|
+
1. Create an ORCID to be associated with the current user of your application.
|
50
|
+
|
51
|
+
The widget is contained in the partial `app/views/orcid/profile_connections/_orcid_connector.html.erb`.
|
52
|
+
|
53
|
+
An example use of the partial is shown below.
|
54
|
+
|
55
|
+
```ruby
|
56
|
+
# The `if defined?(Orcid)` could be viewed as a courtesy.
|
57
|
+
# Don't attempt to render this partial if the Orcid gem is not being used.
|
58
|
+
if defined?(Orcid)
|
59
|
+
<%= render partial: 'orcid/profile_connections/orcid_connector', locals: {default_search_text: current_user.name } %>
|
60
|
+
end
|
61
|
+
```
|
62
|
+
|
63
|
+
## Registering for an ORCID application profile
|
64
|
+
|
65
|
+
Your application which will interface with ORCID must be registered with ORCID. Note that you will want to register your production
|
66
|
+
application separately from the development sandbox.
|
67
|
+
|
68
|
+
1. Go to http://support.orcid.org/knowledgebase/articles/116739-register-a-client-application
|
69
|
+
1. Read the information on the entire page, in particular, the 'Filling in the client application form' and 'About Redirect URIs' sections.
|
70
|
+
1. Click on 'register a client application', http://orcid.org/organizations/integrators/create-client-application
|
71
|
+
1. There you will be given a choice of registering for the Development Sandbox or the Production Registry.
|
72
|
+
1. Fill in the other information as appropriate for your organization. If you are doing development, select Development Sandbox.
|
73
|
+
1. For the URL of the home page of your application, you must use an https:// URL. If you are going to be doing development work locally
|
74
|
+
on your own machine where your application's server will run, enter https://localhost:3000 for the URL of your home page (or as appropriate
|
75
|
+
to your local development environment). See **NOTE: Application home page URL** below.
|
76
|
+
1. You must enter at least one Redirect URI, which should be https://localhost:3000/users/auth/orcid/callback
|
77
|
+
1. Another suggested Redirect URI is https://developers.google.com/oauthplayground
|
78
|
+
|
79
|
+
Within a day or so, you will receive an email with an attached xml file containing the client-id and client-secret which must be used in the application.yml
|
80
|
+
file discussed below.
|
81
|
+
|
82
|
+
### NOTE: Application home page URL
|
83
|
+
You must enter the same URL for the application home page on the form as you would enter into your browser. For example, if you specify "https://localhost:3000" on
|
84
|
+
the ORCID registration form, then you MUST invoke your application via the browser with "https://localhost:3000" in order for all of the ORCID functionality to work.
|
85
|
+
|
86
|
+
For development work in particular, there are multiple ways to specify the local machine: 127.0.0.1, ::1, 192.168.1.1, and localhost. It is strongly recommended that you use 'localhost'
|
87
|
+
in the ORCID form's URL for your application and when invoking your application from the browser rather than using any IP address for your local machine.
|
88
|
+
|
89
|
+
## Setting up your own ORCIDs in the ORCID Development Sandbox
|
90
|
+
|
91
|
+
[Read more about the ORCID Sandbox](http://support.orcid.org/knowledgebase/articles/166623-about-the-orcid-sandbox).
|
92
|
+
|
93
|
+
1. Register two ORCID users: https://sandbox-1.orcid.org/register (make sure to use <blah>@mailinator.com as your email)
|
94
|
+
Save the email addresses, orcid ids, and passwords for editing the application.yml later.
|
95
|
+
1. Go to mailinator (http://mailinator.com/) and claim 1 ORCID by clicking the verify link in the email.
|
96
|
+
1. Go to the ORCID sandbox https://sandbox.orcid.org, log in and click on *Account Settings* (https://sandbox.orcid.org/account). On the Account Settings page,
|
97
|
+
click on Email and select the little icon with the group of heads to make your Primary Email publicly accessible.
|
98
|
+
|
99
|
+
## Setting up the config/application.yml file
|
100
|
+
Customize the sample application.yml file by first copying it to config/application.yml and opening it for editing.
|
101
|
+
|
102
|
+
```console
|
103
|
+
$ cp config/application.yml.sample config/application.yml
|
104
|
+
```
|
105
|
+
|
106
|
+
## Running the tests
|
107
|
+
|
108
|
+
Run `rake` to generate the dummy app and run the offline tests.
|
109
|
+
|
110
|
+
To run the online tests, you'll need ORCID application credentials:
|
15
111
|
|
16
|
-
|
112
|
+
1. Register for an ORCID app. See **Registering for an ORCID application profile** above. (This may take several days to complete.)
|
113
|
+
1. Register two ORCID users in the ORCID Development Sandbox. See **Setting up your own ORCIDs in the ORCID Development Sandbox** above.
|
114
|
+
1. Update the application.yml with your information. See **Setting up the config/application.yml file** above.
|
17
115
|
|
18
|
-
|
116
|
+
Run the online tests with
|
19
117
|
|
118
|
+
```console
|
119
|
+
$ rake spec:online
|
120
|
+
```
|
20
121
|
|
21
122
|
## TODO Items
|
22
123
|
|
23
|
-
* When searching for your profile, expose Name and associated DOI as query parameters.
|
124
|
+
* When searching for your profile, expose Name and associated DOI as query parameters.
|
data/Rakefile
CHANGED
@@ -8,7 +8,7 @@ Bundler::GemHelper.install_tasks
|
|
8
8
|
|
9
9
|
|
10
10
|
begin
|
11
|
-
APP_RAKEFILE = File.expand_path(
|
11
|
+
APP_RAKEFILE = File.expand_path('../spec/internal/Rakefile', __FILE__)
|
12
12
|
load 'rails/tasks/engine.rake'
|
13
13
|
rescue LoadError
|
14
14
|
puts "Unable to load all app tasks for #{APP_RAKEFILE}"
|
@@ -18,30 +18,38 @@ require 'engine_cart/rake_task'
|
|
18
18
|
require 'rspec/core/rake_task'
|
19
19
|
|
20
20
|
namespace :spec do
|
21
|
-
RSpec::Core::RakeTask.new(:all) do
|
21
|
+
RSpec::Core::RakeTask.new(:all) do
|
22
22
|
ENV['COVERAGE'] = 'true'
|
23
23
|
end
|
24
24
|
desc 'Only run specs that do not require net connect'
|
25
25
|
RSpec::Core::RakeTask.new(:offline) do |t|
|
26
|
-
t.rspec_opts =
|
26
|
+
t.rspec_opts = '--tag ~requires_net_connect'
|
27
27
|
end
|
28
28
|
|
29
29
|
desc 'Only run specs that require net connect'
|
30
30
|
RSpec::Core::RakeTask.new(:online) do |t|
|
31
|
-
t.rspec_opts =
|
31
|
+
t.rspec_opts = '--tag requires_net_connect'
|
32
32
|
end
|
33
33
|
|
34
34
|
desc 'Run the Travis CI specs'
|
35
35
|
task :travis do
|
36
36
|
ENV['RAILS_ENV'] = 'test'
|
37
|
-
ENV['SPEC_OPTS'] =
|
37
|
+
ENV['SPEC_OPTS'] = '--profile 20'
|
38
|
+
ENV['ORCID_APP_ID'] = 'bleck'
|
39
|
+
ENV['ORCID_APP_SECRET'] = 'bleck'
|
38
40
|
Rake::Task['engine_cart:clean'].invoke
|
39
41
|
Rake::Task['engine_cart:generate'].invoke
|
40
42
|
Rake::Task['spec:offline'].invoke
|
41
43
|
end
|
42
44
|
end
|
43
|
-
Rake::Task["default"].clear rescue nil
|
44
|
-
Rake::Task["spec"].clear
|
45
45
|
|
46
|
-
|
47
|
-
|
46
|
+
begin
|
47
|
+
Rake::Task['default'].clear
|
48
|
+
rescue RuntimeError
|
49
|
+
# This isn't a big deal if we don't have a default
|
50
|
+
end
|
51
|
+
|
52
|
+
Rake::Task['spec'].clear
|
53
|
+
|
54
|
+
task spec: 'spec:offline'
|
55
|
+
task default: 'spec:travis'
|
File without changes
|
@@ -1,14 +1,23 @@
|
|
1
1
|
module Orcid
|
2
|
-
|
2
|
+
# The foundation for Orcid controllers. A few helpful accessors.
|
3
|
+
class ApplicationController < Orcid.parent_controller.constantize
|
3
4
|
private
|
4
|
-
|
5
|
-
|
6
|
-
|
5
|
+
|
6
|
+
def redirecting_because_user_has_connected_orcid_profile
|
7
|
+
if orcid_profile
|
8
|
+
flash[:notice] = I18n.t(
|
9
|
+
'orcid.requests.messages.previously_connected_profile',
|
10
|
+
orcid_profile_id: orcid_profile.orcid_profile_id
|
11
|
+
)
|
7
12
|
redirect_to main_app.root_path
|
8
13
|
return true
|
9
14
|
else
|
10
15
|
return false
|
11
16
|
end
|
12
17
|
end
|
18
|
+
|
19
|
+
def orcid_profile
|
20
|
+
@orcid_profile ||= Orcid.profile_for(current_user)
|
21
|
+
end
|
13
22
|
end
|
14
23
|
end
|
@@ -1,23 +1,26 @@
|
|
1
1
|
module Orcid
|
2
|
+
# Responsible for negotiating a user request Profile Creation.
|
2
3
|
class ProfileConnectionsController < Orcid::ApplicationController
|
3
4
|
respond_to :html
|
4
5
|
before_filter :authenticate_user!
|
5
6
|
|
6
7
|
def index
|
7
|
-
|
8
|
+
redirecting_because_user_does_not_have_a_connected_orcid_profile ||
|
9
|
+
redirecting_because_user_must_verify_their_connected_profile ||
|
10
|
+
redirecting_because_user_has_verified_their_connected_profile
|
8
11
|
end
|
9
12
|
|
10
13
|
def new
|
11
|
-
return false if
|
14
|
+
return false if redirecting_because_user_has_connected_orcid_profile
|
12
15
|
assign_attributes(new_profile_connection)
|
13
|
-
respond_with(new_profile_connection)
|
16
|
+
respond_with(orcid, new_profile_connection)
|
14
17
|
end
|
15
18
|
|
16
19
|
def create
|
17
|
-
return false if
|
20
|
+
return false if redirecting_because_user_has_connected_orcid_profile
|
18
21
|
assign_attributes(new_profile_connection)
|
19
22
|
create_profile_connection(new_profile_connection)
|
20
|
-
respond_with(new_profile_connection)
|
23
|
+
respond_with(orcid, new_profile_connection)
|
21
24
|
end
|
22
25
|
|
23
26
|
protected
|
@@ -39,8 +42,33 @@ module Orcid
|
|
39
42
|
end
|
40
43
|
|
41
44
|
def new_profile_connection
|
42
|
-
@profile_connection ||=
|
45
|
+
@profile_connection ||= begin
|
46
|
+
Orcid::ProfileConnection.new(params[:profile_connection])
|
47
|
+
end
|
43
48
|
end
|
44
49
|
|
50
|
+
def redirecting_because_user_does_not_have_a_connected_orcid_profile
|
51
|
+
return false if orcid_profile
|
52
|
+
flash[:notice] = I18n.t(
|
53
|
+
'orcid.connections.messages.profile_connection_not_found'
|
54
|
+
)
|
55
|
+
redirect_to orcid.new_profile_connection_path
|
56
|
+
end
|
57
|
+
|
58
|
+
def redirecting_because_user_must_verify_their_connected_profile
|
59
|
+
return false unless orcid_profile
|
60
|
+
return false if orcid_profile.verified_authentication?
|
61
|
+
|
62
|
+
redirect_to user_omniauth_authorize_url('orcid')
|
63
|
+
end
|
64
|
+
|
65
|
+
def redirecting_because_user_has_verified_their_connected_profile
|
66
|
+
orcid_profile = Orcid.profile_for(current_user)
|
67
|
+
notice = I18n.t(
|
68
|
+
'orcid.connections.messages.verified_profile_connection_exists',
|
69
|
+
orcid_profile_id: orcid_profile.orcid_profile_id
|
70
|
+
)
|
71
|
+
redirect_to('/', flash: { notice: notice })
|
72
|
+
end
|
45
73
|
end
|
46
74
|
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
module Orcid
|
2
|
+
# Responsible for helping a user request a new Orcid Profile.
|
2
3
|
class ProfileRequestsController < Orcid::ApplicationController
|
3
4
|
respond_to :html
|
4
5
|
before_filter :authenticate_user!
|
@@ -7,40 +8,40 @@ module Orcid
|
|
7
8
|
helper_method :profile_request
|
8
9
|
|
9
10
|
def show
|
10
|
-
return false if
|
11
|
+
return false if redirecting_because_user_has_connected_orcid_profile
|
11
12
|
return false if redirecting_because_no_profile_request_was_found
|
12
|
-
respond_with(existing_profile_request)
|
13
|
+
respond_with(orcid, existing_profile_request)
|
13
14
|
end
|
14
15
|
|
15
16
|
def new
|
16
|
-
return false if
|
17
|
+
return false if redirecting_because_user_has_connected_orcid_profile
|
17
18
|
return false if redirecting_because_user_has_existing_profile_request
|
18
19
|
assign_attributes(new_profile_request)
|
19
|
-
respond_with(new_profile_request)
|
20
|
+
respond_with(orcid, new_profile_request)
|
20
21
|
end
|
21
22
|
|
22
23
|
def create
|
23
|
-
return false if
|
24
|
+
return false if redirecting_because_user_has_connected_orcid_profile
|
24
25
|
return false if redirecting_because_user_has_existing_profile_request
|
25
26
|
assign_attributes(new_profile_request)
|
26
27
|
create_profile_request(new_profile_request)
|
27
|
-
respond_with(new_profile_request)
|
28
|
+
respond_with(orcid, new_profile_request)
|
28
29
|
end
|
29
30
|
|
30
31
|
protected
|
31
32
|
|
32
33
|
def redirecting_because_no_profile_request_was_found
|
33
34
|
return false if existing_profile_request
|
34
|
-
flash[:notice] = I18n.t(
|
35
|
-
|
36
|
-
|
35
|
+
flash[:notice] = I18n.t(
|
36
|
+
'orcid.requests.messages.existing_request_not_found'
|
37
|
+
)
|
38
|
+
redirect_to orcid.new_profile_request_path
|
37
39
|
end
|
38
40
|
|
39
41
|
def redirecting_because_user_has_existing_profile_request
|
40
|
-
return false
|
41
|
-
flash[:notice] = I18n.t(
|
42
|
-
redirect_to profile_request_path
|
43
|
-
true
|
42
|
+
return false unless existing_profile_request
|
43
|
+
flash[:notice] = I18n.t('orcid.requests.messages.existing_request')
|
44
|
+
redirect_to orcid.profile_request_path
|
44
45
|
end
|
45
46
|
|
46
47
|
def existing_profile_request
|
@@ -60,8 +61,10 @@ module Orcid
|
|
60
61
|
end
|
61
62
|
|
62
63
|
def profile_request_params
|
63
|
-
return {} unless params.
|
64
|
-
params[:profile_request].permit(
|
64
|
+
return {} unless params.key?(:profile_request)
|
65
|
+
params[:profile_request].permit(
|
66
|
+
:given_names, :family_name, :primary_email, :primary_email_confirmation
|
67
|
+
)
|
65
68
|
end
|
66
69
|
end
|
67
70
|
end
|
data/app/models/orcid/profile.rb
CHANGED
@@ -1,16 +1,27 @@
|
|
1
1
|
module Orcid
|
2
|
+
# Provides a container around an Orcid Profile and its relation to the Orcid
|
3
|
+
# Works.
|
2
4
|
class Profile
|
3
|
-
|
4
|
-
|
5
|
+
attr_reader(
|
6
|
+
:orcid_profile_id, :mapper, :remote_service, :xml_renderer, :xml_parser
|
7
|
+
)
|
5
8
|
private :mapper
|
6
9
|
def initialize(orcid_profile_id, config = {})
|
7
10
|
@orcid_profile_id = orcid_profile_id
|
8
11
|
@mapper = config.fetch(:mapper) { Orcid.mapper }
|
9
|
-
@remote_service = config.fetch(:remote_service)
|
12
|
+
@remote_service = config.fetch(:remote_service) do
|
13
|
+
Orcid::Remote::WorkService
|
14
|
+
end
|
10
15
|
@xml_renderer = config.fetch(:xml_renderer) { Orcid::Work::XmlRenderer }
|
11
16
|
@xml_parser = config.fetch(:xml_parser) { Orcid::Work::XmlParser }
|
12
17
|
end
|
13
18
|
|
19
|
+
# Answers the question: Has the user been authenticated via the ORCID
|
20
|
+
# system.
|
21
|
+
def verified_authentication?
|
22
|
+
Orcid.authenticated_orcid?(orcid_profile_id)
|
23
|
+
end
|
24
|
+
|
14
25
|
def remote_works(options = {})
|
15
26
|
@remote_works = nil if options.fetch(:force, false)
|
16
27
|
@remote_works ||= begin
|
@@ -35,10 +46,9 @@ module Orcid
|
|
35
46
|
|
36
47
|
# Note: We can handle
|
37
48
|
def normalize_work(*works)
|
38
|
-
Array(works).
|
49
|
+
Array.wrap(works).map do |work|
|
39
50
|
mapper.map(work, target: 'orcid/work')
|
40
51
|
end
|
41
52
|
end
|
42
|
-
|
43
53
|
end
|
44
54
|
end
|
@@ -6,7 +6,7 @@ module Orcid
|
|
6
6
|
include ActiveModel::Validations
|
7
7
|
extend ActiveModel::Naming
|
8
8
|
|
9
|
-
|
9
|
+
class_attribute :available_query_attribute_names
|
10
10
|
self.available_query_attribute_names = [:email, :text]
|
11
11
|
|
12
12
|
available_query_attribute_names.each do |attribute_name|
|
@@ -19,27 +19,30 @@ module Orcid
|
|
19
19
|
validates :user, presence: true
|
20
20
|
validates :orcid_profile_id, presence: true
|
21
21
|
|
22
|
-
|
23
|
-
|
24
|
-
|
22
|
+
def save(collaborators = {})
|
23
|
+
persister = collaborators.fetch(:persister) do
|
24
|
+
Orcid.method(:connect_user_and_orcid_profile)
|
25
|
+
end
|
25
26
|
valid? ? persister.call(user, orcid_profile_id) : false
|
26
27
|
end
|
27
28
|
|
28
|
-
def persisted
|
29
|
+
def persisted?
|
30
|
+
false
|
31
|
+
end
|
29
32
|
|
30
|
-
attr_writer :
|
31
|
-
def
|
32
|
-
@
|
33
|
+
attr_writer :profile_query_service
|
34
|
+
def profile_query_service
|
35
|
+
@profile_query_service ||= default_profile_query_service
|
33
36
|
end
|
34
|
-
private :
|
37
|
+
private :profile_query_service
|
35
38
|
|
36
|
-
def
|
37
|
-
|
38
|
-
on.found {|results| self.orcid_profile_candidates = results }
|
39
|
+
def default_profile_query_service
|
40
|
+
Remote::ProfileQueryService.new do |on|
|
41
|
+
on.found { |results| self.orcid_profile_candidates = results }
|
39
42
|
on.not_found { self.orcid_profile_candidates = [] }
|
40
|
-
|
43
|
+
end
|
41
44
|
end
|
42
|
-
private :
|
45
|
+
private :default_profile_query_service
|
43
46
|
|
44
47
|
def with_orcid_profile_candidates
|
45
48
|
yield(orcid_profile_candidates) if query_requested?
|
@@ -52,22 +55,19 @@ module Orcid
|
|
52
55
|
end
|
53
56
|
|
54
57
|
def lookup_profile_candidates
|
55
|
-
if query_requested?
|
56
|
-
profile_lookup_service.call(query_attributes)
|
57
|
-
end
|
58
|
+
profile_query_service.call(query_attributes) if query_requested?
|
58
59
|
end
|
59
60
|
private :lookup_profile_candidates
|
60
61
|
|
61
62
|
def query_requested?
|
62
|
-
|
63
|
+
available_query_attribute_names.any? do |attribute_name|
|
63
64
|
attributes[attribute_name].present?
|
64
|
-
|
65
|
+
end
|
65
66
|
end
|
66
67
|
private :query_requested?
|
67
68
|
|
68
69
|
def query_attributes
|
69
70
|
attributes.slice(*available_query_attribute_names)
|
70
71
|
end
|
71
|
-
|
72
72
|
end
|
73
73
|
end
|