uc3-dmp-rds 0.0.16 → 0.0.18
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/uc3-dmp-rds/authenticator.rb +5 -23
- data/lib/uc3-dmp-rds/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ef65457155892c90bf5172d0a6bdbcf81f65a9c207f460f37100995f6895f1a6
|
4
|
+
data.tar.gz: 31d3dd6a9c5a831f3aff7c9407dadc0cc1957b19058003fa85f3638dd55b59ab
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '0196dd990fa57ea307f7a29888f2d96863b764ab20ec0df43d61a7d6180d855b5f3b07c511f3b255e5f70cd10e9a108edc46aa4f3bb034d520112ceecf3cb969'
|
7
|
+
data.tar.gz: 630ea47371bb9a4e353423e3eca70df20302e92716e2ff0020d98b7a80d8a8957392754234176bc92e587929216ecb0a9d988bf5c1e8ada16cd175a88317a03f
|
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
require 'active_record'
|
4
4
|
require 'active_record_simple_execute'
|
5
|
+
require 'json'
|
5
6
|
require 'mysql2'
|
6
7
|
|
7
8
|
module Uc3DmpRds
|
@@ -17,19 +18,11 @@ module Uc3DmpRds
|
|
17
18
|
# Look up the user based on the API token. Will fail if Uc3DmpRds::Adapter does not
|
18
19
|
# have an established connection!
|
19
20
|
def authenticate(token:)
|
20
|
-
|
21
|
-
puts "Authenticator called"
|
22
|
-
|
23
|
-
|
24
21
|
raise AuthenticatorError, MSG_INVALID_TOKEN if token.nil? || token.to_s.strip.empty?
|
25
22
|
|
26
|
-
puts "TOKEN: #{token}"
|
27
|
-
|
28
23
|
users = _query_user(token: token)
|
29
24
|
raise AuthenticatorError, MSG_INVALID_TOKEN unless users.is_a?(Array) && users.any?
|
30
25
|
|
31
|
-
puts "FOUND USER!"
|
32
|
-
|
33
26
|
user = users.first
|
34
27
|
raise AuthenticatorError, MSG_INACTIVE_USER unless user['active']
|
35
28
|
|
@@ -57,35 +50,24 @@ puts "FOUND USER!"
|
|
57
50
|
AND i.identifier_scheme_id IN (SELECT sch.id FROM identifier_schemes sch WHERE sch.name = 'orcid')
|
58
51
|
WHERE users.api_token = :token
|
59
52
|
SQL
|
60
|
-
|
61
|
-
puts sql
|
62
|
-
|
63
53
|
users = ActiveRecord::Base.simple_execute(sql, token: token.to_s.strip)
|
64
54
|
end
|
65
55
|
|
66
56
|
# Convert the ActiveRecord query results into a JSON object
|
67
57
|
def _serialize_user(user:)
|
68
|
-
|
69
|
-
puts "DB RESULTS:"
|
70
|
-
puts user
|
71
|
-
|
72
|
-
return {} if user.nil? || user['mbox'].nil?
|
58
|
+
return {} if user.nil? || user['email'].nil?
|
73
59
|
|
74
60
|
hash = {
|
75
61
|
name: [user['surname'], user['firstname']].join(', '),
|
76
62
|
mbox: user['email'],
|
77
|
-
admin: !user['
|
63
|
+
admin: !user['perm'].nil?
|
78
64
|
}
|
79
65
|
hash[:user_id] = { type: 'orcid', identifier: user['orcid'] } unless user['orcid'].nil?
|
80
|
-
return hash
|
66
|
+
return hash if user['org_name'].nil?
|
81
67
|
|
82
68
|
hash[:affiliation] = { name: user.fetch('ror_name', user['org_name']) }
|
83
69
|
hash[:affiliation][:affiliation_id] = { type: 'ror', identifier: user['ror_id'] } unless user['ror_id'].nil?
|
84
|
-
|
85
|
-
puts "HASH:"
|
86
|
-
puts hash
|
87
|
-
|
88
|
-
hash
|
70
|
+
JSON.parse(hash.to_json)
|
89
71
|
end
|
90
72
|
end
|
91
73
|
end
|
data/lib/uc3-dmp-rds/version.rb
CHANGED