diff --git a/README.md b/README.md index ae6a3fb..bbb96be 100644 --- a/README.md +++ b/README.md @@ -130,6 +130,9 @@ docker build -t alma-user-load . # Run a specific test (by line number) > docker compose -f docker-compose.local.yml run --rm shell bundle exec rspec spec/lib/helpers_spec.rb:34 + +# Run rubocop via docker: +> docker compose -f docker-compose.local.yml run --rm shell bundle exec rubocop ``` ### For convenience, setup an alias: diff --git a/config/settings.yml b/config/settings.yml index 8df8c40..cd4f139 100644 --- a/config/settings.yml +++ b/config/settings.yml @@ -6,7 +6,7 @@ settings: ucpath_upload_path: "/alma/patron_employees/" upload_host: "upload.lib.berkeley.edu" upload_user: "ssullivan" - application_version: "1.6.15" + application_version: "1.6.16" # TODO - flesh this out # http://docopt.org/ diff --git a/config/sis_fields.yml b/config/sis_fields.yml index 5529668..2604d1f 100644 --- a/config/sis_fields.yml +++ b/config/sis_fields.yml @@ -110,3 +110,8 @@ SIS: - name: campus_uid jpath: "$..identifiers[?(@.type=='campus-uid')].id" status: OPTIONAL + + - name: affiliations + jpath: "$..affiliations" + status: REQUIRED + diff --git a/lib/helpers/application_helper.rb b/lib/helpers/application_helper.rb index 7988fd6..a2e69d5 100644 --- a/lib/helpers/application_helper.rb +++ b/lib/helpers/application_helper.rb @@ -13,9 +13,9 @@ def upcath_expire_date(group, expdate = nil) expdate end - def sis_expire_date(withcncl = '') - return create_expected_end_date if [5, 8, 12].include? Date.today.month - return Date.today.to_s if withcncl && withcncl == 'CAN' + def sis_expire_date(active_student) + return create_expected_end_date if [5, 8, 12].include?(Date.today.month) + return Date.today.to_s unless active_student create_expected_end_date end diff --git a/lib/sis/student.rb b/lib/sis/student.rb index b6c4c2d..e5f85df 100644 --- a/lib/sis/student.rb +++ b/lib/sis/student.rb @@ -31,7 +31,7 @@ def initialize(user) private - # rubocop:disable Metrics/AbcSize, Metrics/MethodLength + # rubocop:disable Metrics/AbcSize def create_user_record rec.primary_id = user['student_id'] @@ -46,8 +46,10 @@ def create_user_record set_user_group # EXPIRY_DATE - withcncl = user['withcncl'] || '' - rec.expiry_date = Helpers::ApplicationHelper.sis_expire_date(withcncl) + # 2026-07-30: Per SIS: the easiest way to define if a student is + # active or not is using their AFFILIATIONS. If they have an 'active' + # affiliation (other than 'ALUMFOREVER') the student is active. + rec.expiry_date = Helpers::ApplicationHelper.sis_expire_date(active?) # PURGE_DATE (expiry date plus one year) rec.purge_date = Date.iso8601(rec.expiry_date).next_year.to_s @@ -61,7 +63,24 @@ def create_user_record # MISC. HARDCODED VALUES set_static_values end - # rubocop:enable Metrics/AbcSize, Metrics/MethodLength + # rubocop:enable Metrics/AbcSize + + def active? + # An active student will have a type other than ALUMFORMER AND an ACTIVE status + return false unless user['affiliations'] + + user['affiliations'].each do |a| + type = a['type']['code'] + status = a['status']['code'] + + # ALUMFORMER is NOT an active student - ignore this affiliation + next if type == 'ALUMFORMER' + + return true if status == 'ACT' + end + + false + end # rubocop:disable Metrics/MethodLength def set_user_group diff --git a/spec/data/sis/missing_reg_2222_1.json b/spec/data/sis/missing_reg_2222_1.json index 525a56e..339103b 100644 --- a/spec/data/sis/missing_reg_2222_1.json +++ b/spec/data/sis/missing_reg_2222_1.json @@ -75,22 +75,6 @@ "fromDate": "1902-02-01" } ], - "affiliations": [ - { - "type": { - "code": "GRADUATE", - "description": "Graduate Student", - "formalDescription": "An individual with a Graduate-based Career/Program/Plan." - }, - "detail": "Active", - "status": { - "code": "ACT", - "description": "Active", - "formalDescription": "Active" - }, - "fromDate": "2015-12-15" - } - ], "addresses": [ { "type": { diff --git a/spec/lib/sis_spec.rb b/spec/lib/sis_spec.rb index 5821607..a7a43b2 100644 --- a/spec/lib/sis_spec.rb +++ b/spec/lib/sis_spec.rb @@ -321,13 +321,25 @@ end end - it 'sets expiry date to default if student not withcncl and month not May, Aug, Dec' do + it 'sets expiry date to default if student is active and month not May, Aug, Dec' do allow(Date).to receive(:today).and_return Date.new(2022, 1, 15) + + affiliations = [{ + 'type' => { + 'code' => 'UNDERGRAD' + }, + 'status' => { + 'code' => 'ACT' + }, + 'fromDate' => '2015-12-14' + }] + user = { 'student_id' => '12345', 'prim_name_givenname' => 'Thor', 'prim_name_familyname' => 'Odinson', - 'acadcareer_code' => 'GRAD' + 'acadcareer_code' => 'GRAD', + 'affiliations' => affiliations } student = SIS::Student.new user @@ -335,14 +347,25 @@ expect(student.rec.expiry_date).to eq(expected_expiry_date) end - it 'sets expiry date to default if student withcncl is empty string and month not May, Aug, Dec' do + it 'sets expiry date to default if student has an active affiliation and month not May, Aug, Dec' do allow(Date).to receive(:today).and_return Date.new(2022, 1, 15) + + affiliations = [{ + 'type' => { + 'code' => 'UNDERGRAD' + }, + 'status' => { + 'code' => 'ACT' + }, + 'fromDate' => '2015-12-14' + }] + user = { 'student_id' => '12345', 'prim_name_givenname' => 'Thor', 'prim_name_familyname' => 'Odinson', 'acadcareer_code' => 'GRAD', - 'withcncl' => '' + 'affiliations' => affiliations } student = SIS::Student.new user @@ -415,5 +438,49 @@ expect(student.rec.user_group).to eq(value) end end + + it 'sets expiry date to "today" if student has no active affiliations and month not May, Aug, Dec' do + allow(Date).to receive(:today).and_return Date.new(2022, 1, 15) + + affiliations = [{ + 'type' => { + 'code' => 'UNDERGRAD' + }, + 'status' => { + 'code' => 'INA' + }, + 'fromDate' => '2015-12-14' + }] + + user = { + 'student_id' => '12345', + 'prim_name_givenname' => 'Thor', + 'prim_name_familyname' => 'Odinson', + 'acadcareer_code' => 'GRAD', + 'affiliations' => affiliations + } + + student = SIS::Student.new user + expected_expiry_date = '2022-01-15' + expect(student.rec.expiry_date).to eq(expected_expiry_date) + end + + it 'sets expiry date to "today" if student has no affiliations at all and month not May, Aug, Dec' do + allow(Date).to receive(:today).and_return Date.new(2022, 1, 15) + + affiliations = nil + + user = { + 'student_id' => '12345', + 'prim_name_givenname' => 'Thor', + 'prim_name_familyname' => 'Odinson', + 'acadcareer_code' => 'GRAD', + 'affiliations' => affiliations + } + + student = SIS::Student.new user + expected_expiry_date = '2022-01-15' + expect(student.rec.expiry_date).to eq(expected_expiry_date) + end end # rubocop:enable Metrics/BlockLength