ucb_rails_user 4.1.0 → 4.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/models/ucb_rails_user/user_uc_path_service.rb +45 -21
- data/lib/ucb_rails_user/version.rb +1 -1
- metadata +11 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7a1de8958c36cbeeb3541649d812e7288468672f9352ec84749810fccaf81005
|
4
|
+
data.tar.gz: e2262f788179205abf8dc7d4558a434f3826130f6d713448ef90a783e2341fe1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 27314e556fa6987b12779ea570dacbd3f5089a7cfdef91a316020f13754ceb147cd74de4e3e468a298109cc1336beef659708507bde98605743242e9cd4f6c91
|
7
|
+
data.tar.gz: dbb93ff5a2cde7347e2b5441155edafae6f18557cbaf584ac6f89fdb34adda7b67dc36b8f43a5c571e2fb0b6de8eefd71dacb6f3a3e6cd04458a56acd1d417fe
|
@@ -4,20 +4,38 @@ class UcbRailsUser::UserUcPathService
|
|
4
4
|
|
5
5
|
class << self
|
6
6
|
|
7
|
+
def create_or_update_user_from_employee_id(employee_id)
|
8
|
+
ucpath_entry = ucpath_client.fetch_employee_data_with_employee_id(employee_id)
|
9
|
+
return nil unless ucpath_entry.present?
|
10
|
+
user = User.find_or_initialize_by(employee_id: employee_id)
|
11
|
+
update_user_record_from_ucpath_entry!(user, ucpath_entry)
|
12
|
+
end
|
13
|
+
|
7
14
|
def create_or_update_user_from_ldap_uid(ldap_uid)
|
8
|
-
ucpath_entry = ucpath_client.
|
15
|
+
ucpath_entry = ucpath_client.fetch_employee_data_with_ldap_uid(ldap_uid)
|
9
16
|
return nil unless ucpath_entry.present?
|
17
|
+
user = User.find_or_initialize_by(ldap_uid: ldap_uid)
|
18
|
+
update_user_record_from_ucpath_entry!(user, ucpath_entry)
|
19
|
+
end
|
10
20
|
|
11
|
-
|
21
|
+
def ucpath_client
|
22
|
+
UcPathClient.new
|
23
|
+
end
|
24
|
+
|
25
|
+
def update_user_record_from_ucpath_entry!(user, ucpath_entry)
|
26
|
+
user.tap do |u|
|
12
27
|
name_entry = parse_name(ucpath_entry)
|
13
|
-
|
14
|
-
|
15
|
-
|
28
|
+
u.first_name = name_entry["givenName"]
|
29
|
+
u.last_name = name_entry["familyName"]
|
30
|
+
u.employee_id ||= ucpath_entry["identifiers"]&.detect do |id|
|
16
31
|
id["type"] == "hr-employee-id"
|
17
32
|
end&.fetch("id")
|
18
|
-
|
19
|
-
|
20
|
-
|
33
|
+
u.ldap_uid ||= ucpath_entry["identifiers"]&.detect do |id|
|
34
|
+
id["type"] == "campus-uid"
|
35
|
+
end&.fetch("id")
|
36
|
+
u.email = parse_email(ucpath_entry)
|
37
|
+
u.inactive_flag = false # any way to pull this from the API?
|
38
|
+
u.save!
|
21
39
|
end
|
22
40
|
end
|
23
41
|
|
@@ -42,32 +60,38 @@ class UcbRailsUser::UserUcPathService
|
|
42
60
|
email_entry&.fetch("emailAddress")
|
43
61
|
end
|
44
62
|
|
45
|
-
def ucpath_client
|
46
|
-
UcPathClient.new
|
47
|
-
end
|
48
|
-
|
49
63
|
end
|
50
64
|
|
51
65
|
class UcPathClient
|
52
66
|
attr_reader :app_id, :app_key, :endpoint
|
53
67
|
|
54
68
|
def initialize
|
55
|
-
|
56
|
-
Rails.application.credentials.ucpath ||
|
57
|
-
|
58
|
-
|
59
|
-
|
69
|
+
base_credentials =
|
70
|
+
Rails.application.credentials.ucpath&.with_indifferent_access ||
|
71
|
+
Rails.application.credentials.hcm&.with_indifferent_access ||
|
72
|
+
Rails.application.credentials.fetch(:"ucb-hcm", {})&.with_indifferent_access
|
73
|
+
env_credentials = base_credentials&.fetch(Rails.env, {})
|
74
|
+
@app_id = env_credentials&.fetch(:app_id, nil) || base_credentials&.fetch(:app_id, nil)
|
75
|
+
@app_key = env_credentials&.fetch(:app_key, nil) || base_credentials&.fetch(:app_key, nil)
|
76
|
+
@endpoint = env_credentials&.fetch(:endpoint, nil) || base_credentials&.fetch(:endpoint, nil)
|
60
77
|
end
|
61
78
|
|
62
|
-
def
|
79
|
+
def fetch_employee_data_with_ldap_uid(ldap_uid)
|
80
|
+
fetch_employee_data(ldap_uid, "campus-uid")
|
81
|
+
end
|
82
|
+
|
83
|
+
def fetch_employee_data_with_employee_id(employee_id)
|
84
|
+
fetch_employee_data(employee_id, "hr-employee-id")
|
85
|
+
end
|
86
|
+
|
87
|
+
def fetch_employee_data(id, id_type)
|
63
88
|
if [app_id, app_key, endpoint].any?(&:blank?)
|
64
89
|
Rails.logger.warn missing_api_values_message
|
65
90
|
return nil
|
66
91
|
end
|
67
|
-
|
68
92
|
response =
|
69
|
-
Faraday.get("#{endpoint}/employees/#{
|
70
|
-
req.params["id-type"] =
|
93
|
+
Faraday.get("#{endpoint}/employees/#{id}") do |req|
|
94
|
+
req.params["id-type"] = id_type
|
71
95
|
req.headers["Accept"] = "application/json"
|
72
96
|
req.headers["app_id"] = app_id
|
73
97
|
req.headers["app_key"] = app_key
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ucb_rails_user
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.1.
|
4
|
+
version: 4.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Steve Downey
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2022-
|
14
|
+
date: 2022-09-14 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: rails
|
@@ -107,16 +107,22 @@ dependencies:
|
|
107
107
|
name: omniauth
|
108
108
|
requirement: !ruby/object:Gem::Requirement
|
109
109
|
requirements:
|
110
|
-
- - "
|
110
|
+
- - ">="
|
111
111
|
- !ruby/object:Gem::Version
|
112
112
|
version: '1.8'
|
113
|
+
- - "<"
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
version: '3.0'
|
113
116
|
type: :runtime
|
114
117
|
prerelease: false
|
115
118
|
version_requirements: !ruby/object:Gem::Requirement
|
116
119
|
requirements:
|
117
|
-
- - "
|
120
|
+
- - ">="
|
118
121
|
- !ruby/object:Gem::Version
|
119
122
|
version: '1.8'
|
123
|
+
- - "<"
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '3.0'
|
120
126
|
- !ruby/object:Gem::Dependency
|
121
127
|
name: omniauth-cas
|
122
128
|
requirement: !ruby/object:Gem::Requirement
|
@@ -386,7 +392,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
386
392
|
- !ruby/object:Gem::Version
|
387
393
|
version: '0'
|
388
394
|
requirements: []
|
389
|
-
rubygems_version: 3.
|
395
|
+
rubygems_version: 3.3.7
|
390
396
|
signing_key:
|
391
397
|
specification_version: 4
|
392
398
|
summary: Rails engine for UCB user accounts
|