uc3-dmp-rds 0.0.11 → 0.0.13
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 +40 -5
- data/lib/uc3-dmp-rds/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1866fcb5ab8870fe909f30010bae7fe9b84ea1b1f8449075dcd7eaf3552e5a92
|
4
|
+
data.tar.gz: 7f01d3802e480af2c253fdf3c56d23fdcb1d624a4511d09938d33dda49a3c192
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cb4f83e0f493c1300f3231bde8c5f7bfb805a0adaf8d15e8d7cd84bc31ff6251917effc5162c6c370dcefce5775a4acda56de14d3728c2d1030c8cbece37e805
|
7
|
+
data.tar.gz: cf06caa490d75570cc0f9211d96d6bcc92aa61abff81160ef70c05355932f7dce4eade037409711ecf7e829ae829b50f465873a341f1d7ed92681cd3fdca4964
|
@@ -14,14 +14,44 @@ module Uc3DmpRds
|
|
14
14
|
MSG_INACTIVE_USER = 'User is inactive'
|
15
15
|
|
16
16
|
class << self
|
17
|
+
# Retrieves the User API token from the headers
|
18
|
+
def token_from_headers(headers: {})
|
19
|
+
return nil unless headers.is_a?(Hash) && headers.keys.any?
|
20
|
+
|
21
|
+
authorization = json.select { |k, _v| k.downcase.strip == 'authorization' }
|
22
|
+
parts = authorization.split(' ')
|
23
|
+
return nil unless parts.first.downcase == 'token' && parts.length == 2
|
24
|
+
|
25
|
+
parts.last.strip
|
26
|
+
end
|
27
|
+
|
28
|
+
# Look up the user based on the API token. Will fail if Uc3DmpRds::Adapter does not
|
29
|
+
# have an established connection!
|
17
30
|
def authenticate(token:)
|
18
31
|
raise AuthenticatorError, MSG_INVALID_TOKEN if token.nil? || token.to_s.strip.empty?
|
19
32
|
|
33
|
+
users = _query_user(token: token)
|
34
|
+
raise AuthenticatorError, MSG_INVALID_TOKEN unless users.is_a?(Array) && users.any?
|
35
|
+
|
36
|
+
user = users.first
|
37
|
+
raise AuthenticatorError, MSG_INACTIVE_USER unless user['active']
|
38
|
+
|
39
|
+
_serialize_user(user: user)
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
# Query ActiveRecord for the User's record
|
45
|
+
def _query_user(token:)
|
46
|
+
return nil if token.nil?
|
47
|
+
|
20
48
|
sql = <<~SQL.squish
|
21
49
|
SELECT users.firstname, users.surname, users.email, users.active, i.value orcid,
|
22
|
-
orgs.name org_name, ro.name ror_name, ro.ror_id
|
50
|
+
orgs.name org_name, ro.name ror_name, ro.ror_id, perms.name perm_name
|
23
51
|
FROM users
|
24
52
|
INNER JOIN orgs ON users.org_id = orgs.id
|
53
|
+
LEFT OUTER JOIN users_perms up ON users.id = up.user_id
|
54
|
+
LEFT OUTER JOIN perms ON up.perm_id = perms.id AND perms.name = 'modify_templates'
|
25
55
|
LEFT OUTER JOIN registry_orgs ro
|
26
56
|
ON orgs.id = ro.org_id
|
27
57
|
LEFT OUTER JOIN identifiers i
|
@@ -32,12 +62,17 @@ module Uc3DmpRds
|
|
32
62
|
LIMIT 1
|
33
63
|
SQL
|
34
64
|
users = ActiveRecord::Base.simple_execute(sql, token: token.to_s.strip)
|
35
|
-
|
65
|
+
end
|
36
66
|
|
37
|
-
|
38
|
-
|
67
|
+
# Convert the ActiveRecord query results into a JSON object
|
68
|
+
def _serialize_user(user:)
|
69
|
+
return {} if user.nil? || user['mbox'].nil?
|
39
70
|
|
40
|
-
hash = {
|
71
|
+
hash = {
|
72
|
+
name: [user['surname'], user['firstname']].join(', '),
|
73
|
+
mbox: user['email'],
|
74
|
+
admin: !user['perm_name'].nil?
|
75
|
+
}
|
41
76
|
hash[:user_id] = { type: 'orcid', identifier: user['orcid'] } unless user['orcid'].nil?
|
42
77
|
return hash.to_json if user['org_name'].nil?
|
43
78
|
|
data/lib/uc3-dmp-rds/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: uc3-dmp-rds
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.13
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brian Riley
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-05-
|
11
|
+
date: 2023-05-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: active_record_simple_execute
|