uc3-dmp-rds 0.0.13 → 0.0.15

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1866fcb5ab8870fe909f30010bae7fe9b84ea1b1f8449075dcd7eaf3552e5a92
4
- data.tar.gz: 7f01d3802e480af2c253fdf3c56d23fdcb1d624a4511d09938d33dda49a3c192
3
+ metadata.gz: ab8baeefeaefa3440ab7fd1dd17f82597e3a0bdebf56ca00a204cab9fee9fdb0
4
+ data.tar.gz: 6517005d0c6dee5e89274063811ecc73e8f97f25e6e363ed807c4fd2d05d267f
5
5
  SHA512:
6
- metadata.gz: cb4f83e0f493c1300f3231bde8c5f7bfb805a0adaf8d15e8d7cd84bc31ff6251917effc5162c6c370dcefce5775a4acda56de14d3728c2d1030c8cbece37e805
7
- data.tar.gz: cf06caa490d75570cc0f9211d96d6bcc92aa61abff81160ef70c05355932f7dce4eade037409711ecf7e829ae829b50f465873a341f1d7ed92681cd3fdca4964
6
+ metadata.gz: f82f8dcd0237f542278a0a296a2a4aac96cc99c50455eae77e66e192cc4b64b451d4bb5fa5b2bca8c38fd3d12bd906c17d0b0a2bb7d309d83b30d4ccbaf7d624
7
+ data.tar.gz: edcda33c09cef2fae6de7a85cf345c4cd75a915b7575830096d22f7e7fe876ee829b402519003c72f1f3dfc07d340c14c6cb1b753d675b8ee68bd569b9975eac
@@ -14,25 +14,18 @@ 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
17
  # Look up the user based on the API token. Will fail if Uc3DmpRds::Adapter does not
29
18
  # have an established connection!
30
19
  def authenticate(token:)
31
20
  raise AuthenticatorError, MSG_INVALID_TOKEN if token.nil? || token.to_s.strip.empty?
32
21
 
22
+ puts "TOKEN: #{token}"
23
+
33
24
  users = _query_user(token: token)
34
25
  raise AuthenticatorError, MSG_INVALID_TOKEN unless users.is_a?(Array) && users.any?
35
26
 
27
+ puts "FOUND USER!"
28
+
36
29
  user = users.first
37
30
  raise AuthenticatorError, MSG_INACTIVE_USER unless user['active']
38
31
 
@@ -47,11 +40,11 @@ module Uc3DmpRds
47
40
 
48
41
  sql = <<~SQL.squish
49
42
  SELECT users.firstname, users.surname, users.email, users.active, i.value orcid,
50
- orgs.name org_name, ro.name ror_name, ro.ror_id, perms.name perm_name
43
+ orgs.name org_name, ro.name ror_name, ro.ror_id,
44
+ (SELECT perms.name FROM users_perms up LEFT OUTER JOIN perms ON up.perm_id = perms.id
45
+ WHERE users.id = up.user_id AND perms.name = 'modify_templates') perm
51
46
  FROM users
52
47
  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'
55
48
  LEFT OUTER JOIN registry_orgs ro
56
49
  ON orgs.id = ro.org_id
57
50
  LEFT OUTER JOIN identifiers i
@@ -59,13 +52,19 @@ module Uc3DmpRds
59
52
  AND i.identifiable_type = 'User'
60
53
  AND i.identifier_scheme_id IN (SELECT sch.id FROM identifier_schemes sch WHERE sch.name = 'orcid')
61
54
  WHERE users.api_token = :token
62
- LIMIT 1
63
55
  SQL
56
+
57
+ puts sql
58
+
64
59
  users = ActiveRecord::Base.simple_execute(sql, token: token.to_s.strip)
65
60
  end
66
61
 
67
62
  # Convert the ActiveRecord query results into a JSON object
68
63
  def _serialize_user(user:)
64
+
65
+ puts "DB RESULTS:"
66
+ puts user
67
+
69
68
  return {} if user.nil? || user['mbox'].nil?
70
69
 
71
70
  hash = {
@@ -78,7 +77,11 @@ module Uc3DmpRds
78
77
 
79
78
  hash[:affiliation] = { name: user.fetch('ror_name', user['org_name']) }
80
79
  hash[:affiliation][:affiliation_id] = { type: 'ror', identifier: user['ror_id'] } unless user['ror_id'].nil?
81
- hash.to_json
80
+
81
+ puts "HASH:"
82
+ puts hash
83
+
84
+ hash
82
85
  end
83
86
  end
84
87
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Uc3DmpRds
4
- VERSION = '0.0.13'
4
+ VERSION = '0.0.15'
5
5
  end
data/lib/uc3-dmp-rds.rb CHANGED
@@ -2,6 +2,7 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require 'uc3-dmp-rds/adapter'
5
+ require 'uc3-dmp-rds/authenticator'
5
6
 
6
7
  # RDS Database adapter
7
8
  module Uc3DmpRds
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.13
4
+ version: 0.0.15
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-25 00:00:00.000000000 Z
11
+ date: 2023-05-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: active_record_simple_execute