Skip to content

Commit 42c8190

Browse files
AP-468 add priority job feature (#3)
1 parent cf65c3f commit 42c8190

13 files changed

Lines changed: 497 additions & 25 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,4 +140,4 @@ Note - to run the test suite you need to change the LDAP setting in your `.env`
140140
- Move 'create_user_record' from user.rb to a separate class
141141
- Add a check to make sure all necessary config settings are set!
142142
- Setup a rake command to run the test suite
143-
- Reduce some of the complexity in the complexity so I can remove some of the rubocop disables
143+
- Reduce some of the complexity so I can remove some of the rubocop disables

config/settings.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Settings:
66
upload_host: "upload.lib.berkeley.edu"
77
upload_user: "ssullivan"
88
last_alma_purge: "2023-06-30"
9-
application_version: "1.6.1"
9+
application_version: "1.6.2"
1010

1111
# TODO - flesh this out
1212
# http://docopt.org/

config/ucpath_codes.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,3 +137,8 @@ EmployeeIDs Overlap With Inactive StudentIDs:
137137
- "10152922"
138138
- "10159568"
139139
- "10162123"
140+
141+
# These jobs will always be considered "eligible" regardless
142+
# of any student affiliations
143+
Priority Job Codes:
144+
- "006761"

lib/alma/xml_writer.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ def ensure_open!
4242

4343
def prolog_and_opening_tag
4444
tag = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
45-
tag += "<!-- GIT_SHA:#{ENV['GIT_SHA']} -->\n"
46-
tag += "<!-- DOCKER_TAG:#{ENV['DOCKER_TAG']} -->\n"
47-
tag += "<!-- VERSION: #{ENV['VERSION']} -->\n"
45+
tag += "<!-- GIT_SHA:#{ENV.fetch('GIT_SHA', nil)} -->\n"
46+
tag += "<!-- DOCKER_TAG:#{ENV.fetch('DOCKER_TAG', nil)} -->\n"
47+
tag += "<!-- VERSION: #{ENV.fetch('VERSION', nil)} -->\n"
4848
tag += "<!-- CHANGE_LOG_COUNT: #{change_log_count} -->\n"
4949
tag += "<users>\n"
5050
tag

lib/ldap/api.rb

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,21 +39,18 @@ def fetch_ldap_rec(id)
3939

4040
private
4141

42-
# rubocop:disable Metrics/MethodLength
4342
def ldap_connection
4443
Net::LDAP.new host: host,
4544
port: 636,
4645
encryption: {
47-
method: :simple_tls,
48-
tls_options: OpenSSL::SSL::SSLContext::DEFAULT_PARAMS
46+
method: :simple_tls
4947
},
5048
auth: {
5149
method: :simple,
5250
username: 'uid=library-hrms-epl,ou=applications,dc=berkeley,dc=edu',
5351
password: pass
5452
}
5553
end
56-
# rubocop:enable Metrics/MethodLength
5754

5855
def host
5956
Config.secrets.ldap.host

lib/ucpath/jobs.rb

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@ def eligible_job?
3131

3232
# Extract the data from the raw jobs into the fields we need
3333
# config/ucpath_fields.yml contains the fields/jpath we want to extract
34-
def find_eligible_job(raw_jobs)
35-
raw_jobs.first.each do |job_hash|
36-
job = OpenStruct.new(
37-
Config.ucpath_job_fields.to_h do |field|
38-
[field['name'], JsonPath.on(job_hash, field['jpath']).first || '']
39-
end
40-
)
34+
def find_eligible_job(job_list)
35+
priority_job_hash = find_priority_jobs(job_list)
36+
37+
return map_job_to_struct(priority_job_hash) if priority_job_hash
38+
39+
job_list.first.each do |job_hash|
40+
job = map_job_to_struct(job_hash)
4141

4242
# First one - save it incase we don't find any eligible jobs!
4343
@first_job ||= job
@@ -73,6 +73,23 @@ def check_if_eligible(j)
7373
end
7474
# rubocop :enable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
7575

76+
def find_priority_jobs(job_list)
77+
job_list.flatten.find do |jh|
78+
job_code = jh.dig('position', 'jobCode', 'code', 'code')
79+
status = jh.dig('position', 'active', 'code')
80+
81+
Config.check_ucpath_code('Priority Job Codes', job_code) && status == 'A'
82+
end
83+
end
84+
85+
def map_job_to_struct(job_hash)
86+
OpenStruct.new(
87+
Config.ucpath_job_fields.to_h do |field|
88+
[field['name'], JsonPath.on(job_hash, field['jpath']).first || '']
89+
end
90+
)
91+
end
92+
7693
def fetch_jobs(id)
7794
logger.info "#{id} - Fetching ucpath jobs data"
7895
User.fetch_ucpath_jobs(id)

lib/ucpath/user.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,11 @@ def eligible?
130130
def create_user_record
131131
rec.primary_id = ucpath_rec.ucpath_employee_id
132132

133+
job_code = jobs.job.job_code || nil
134+
priority_job = Config.check_ucpath_code('Priority Job Codes', job_code)
135+
133136
# STUDENT CHECK - berkeleyeduaffiliations in Student Affiliation (ldap_fields.yml)
134-
if ldap&.berkeleyeduaffiliations
137+
if !priority_job && ldap&.berkeleyeduaffiliations
135138
ldap.berkeleyeduaffiliations.each do |affiliation|
136139
if Config.student_affiated? affiliation
137140
logger.info "#{id} - Ineligible: ldap student affiliation: #{affiliation}"
@@ -142,7 +145,6 @@ def create_user_record
142145

143146
# CONTINGENT WORKER CHECK
144147
# AP-361: Thou Shalt not pass if the user has a Contingent Worker Job Code!
145-
job_code = jobs.job.job_code || nil
146148
if job_code && Config.check_ucpath_code('Contingent Worker Job Code', job_code)
147149
logger.info "#{id} - Ineligible: Contingent Worker Job Code: #{job_code}"
148150
return nil
@@ -222,7 +224,7 @@ def create_user_record
222224
rec.identifiers = create_identifiers
223225

224226
# USER_ROLES - DROP (according to D.Rez, Alma should assign)
225-
# USER_STATISTICS - TBD (addording to J.Gosselar these have yet to be determined)
227+
# USER_STATISTICS - TBD (according to J.Gosselar these have yet to be determined)
226228

227229
# SET USER ELIGIBILITY
228230
self.eligible = true

0 commit comments

Comments
 (0)