Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion config/settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand Down
5 changes: 5 additions & 0 deletions config/sis_fields.yml
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,8 @@ SIS:
- name: campus_uid
jpath: "$..identifiers[?(@.type=='campus-uid')].id"
status: OPTIONAL

- name: affiliations
jpath: "$..affiliations"
status: REQUIRED

6 changes: 3 additions & 3 deletions lib/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
27 changes: 23 additions & 4 deletions lib/sis/student.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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']

Expand All @@ -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
Expand All @@ -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
Expand Down
16 changes: 0 additions & 16 deletions spec/data/sis/missing_reg_2222_1.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
75 changes: 71 additions & 4 deletions spec/lib/sis_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -321,28 +321,51 @@
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
expected_expiry_date = '2023-10-31'
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
Expand Down Expand Up @@ -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
Loading