Skip to content

Commit 4e89ee6

Browse files
Add SIS Ignore by student ID feature (#13)
* Add SIS ignore feature * Move log line from method back to run_sis
1 parent 8a7b93d commit 4e89ee6

5 files changed

Lines changed: 108 additions & 28 deletions

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ UCPath: https://developers.api.berkeley.edu/api/8
2525
SIS: https://developers.api.berkeley.edu/api/6
2626
Additional data is pulled from CalNet via LDAP
2727

28+
Note - the sis_ignore_ids.txt file contains a list of student_ids which will be ignored by the SIS run. This is so employees who take classes (usually UC Extension), don't have their Alma UCPath record over-written by their SIS record.
29+
2830
### Schedule
2931

3032
* SIS : Monday and Wednesday Mornings 1am

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.9"
9+
application_version: "1.6.10"
1010

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

config/sis_ignore_ids.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# SIS Student_IDs to exclude from student load
2+
3042087233

lib/sis.rb

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
require 'set'
12
require_relative 'sis/api'
23
require_relative 'sis/student'
34

@@ -10,24 +11,49 @@ module SIS
1011
include SIS::API
1112

1213
def run_sis(setup)
14+
# Load the Ignore list: see AP-636 for details
15+
ignore_list = load_ignored_sis_ids
16+
1317
term_id = setup.term_id || SIS::API.current_term
1418
as_of_date = SIS::API.as_of_date
19+
writer = Alma::XMLWriter.new(setup.xml_path)
1520

1621
logger.info "Running SIS\nTerm ID: #{term_id}\nRequest Root: #{sis_root} As-of-Date #{as_of_date}"
1722

18-
#----------------------------------------------------------------#
19-
# Setup our XML file
20-
writer = Alma::XMLWriter.new(setup.xml_path)
23+
process_users(term_id, as_of_date, ignore_list, writer)
24+
finalize_output(writer, setup)
25+
end
2126

22-
#----------------------------------------------------------------#
23-
# Fetch the entire set of users by term
27+
def process_users(term_id, as_of_date, ignore_list, writer)
2428
raw_users = SIS::API.fetch_by_term(term_id, as_of_date)
29+
2530
raw_users.each do |user|
31+
next if ignored_user?(user, ignore_list)
32+
2633
writer.write(SIS::Student.new(user))
2734
end
35+
end
2836

37+
def finalize_output(writer, setup)
2938
writer.close
30-
3139
Helpers::FileZip.zipit!(setup.zip_path, setup.xml_path)
3240
end
41+
42+
def load_ignored_sis_ids(path = 'config/sis_ignore_ids.txt')
43+
return Set.new unless File.exist?(path)
44+
45+
File.readlines(path, chomp: true)
46+
.map(&:strip)
47+
.reject { |line| line.empty? || line.start_with?('#') }
48+
.to_set
49+
end
50+
51+
def ignored_user?(user, ignore_list)
52+
student_id = user['student_id']
53+
54+
return false unless ignore_list.include?(student_id)
55+
56+
logger.info "Skipping User #{student_id}: listed in SIS ignore file"
57+
true
58+
end
3359
end

spec/lib/sis_spec.rb

Lines changed: 71 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,37 +4,87 @@
44
require 'stub_helper'
55
require 'nokogiri'
66

7-
# rubocop :disable Lint/ConstantDefinitionInBlock, Style/MutableConstant
7+
# rubocop :disable Lint/ConstantDefinitionInBlock, Style/MutableConstant, Metrics/BlockLength:
88
describe SIS do
9-
it 'runs sis' do
10-
# Make VERSION dynamic:
11-
# Note - applicaiton_version is set in config/settings.yml: applicaiton_version
12-
expected_version = (ENV['VERSION'] || '1.0.0').to_s
9+
describe '#run_sis' do
10+
it 'runs sis' do
11+
# Make VERSION dynamic:
12+
# Note - applicaiton_version is set in config/settings.yml: applicaiton_version
13+
expected_version = (ENV['VERSION'] || '1.0.0').to_s
1314

14-
expected_file = File.read('spec/data/sis/expected_xml_3.xml')
15+
expected_file = File.read('spec/data/sis/expected_xml_3.xml')
1516

16-
allow(Date).to receive(:today).and_return Date.new(2022, 6, 1)
17-
expected_file.gsub!(/<!-- VERSION: .+? -->/, "<!-- VERSION: #{expected_version} -->")
17+
allow(Date).to receive(:today).and_return Date.new(2022, 6, 1)
18+
expected_file.gsub!(/<!-- VERSION: .+? -->/, "<!-- VERSION: #{expected_version} -->")
1819

19-
term_id = '2222'
20-
stub_past_sis_data(term_id, '2022-04-10', 1)
21-
stub_past_sis_data(term_id, '2022-04-10', 2)
22-
stub_sis_data(term_id, 1)
23-
stub_sis_data(term_id, 2)
20+
term_id = '2222'
21+
stub_past_sis_data(term_id, '2022-04-10', 1)
22+
stub_past_sis_data(term_id, '2022-04-10', 2)
23+
stub_sis_data(term_id, 1)
24+
stub_sis_data(term_id, 2)
25+
26+
Dir.mktmpdir do |dir|
27+
outpath = Pathname.new(dir)
28+
29+
ARGV = ['--type', 'sis', '-s', '2022-04-10', '--term', '2222', '--outdir', outpath]
30+
setup = Helpers::Setup.new
31+
SIS.run_sis setup
32+
33+
expect(File.exist?(setup.zip_path)).to eq(true)
34+
expect(File.read(setup.xml_path)).to eq(expected_file)
35+
end
36+
end
37+
38+
it 'skips users listed in the SIS ignore file' do
39+
allow(Date).to receive(:today).and_return Date.new(2022, 6, 1)
40+
41+
term_id = '2222'
42+
stub_past_sis_data(term_id, '2022-04-10', 1)
43+
stub_past_sis_data(term_id, '2022-04-10', 2)
44+
stub_sis_data(term_id, 1)
45+
stub_sis_data(term_id, 2)
46+
47+
allow(SIS).to receive(:load_ignored_sis_ids).and_return(Set['10162050'])
2448

25-
Dir.mktmpdir do |dir|
26-
outpath = Pathname.new(dir)
49+
Dir.mktmpdir do |dir|
50+
outpath = Pathname.new(dir)
2751

28-
ARGV = ['--type', 'sis', '-s', '2022-04-10', '--term', '2222', '--outdir', outpath]
29-
setup = Helpers::Setup.new
30-
SIS.run_sis setup
52+
ARGV = ['--type', 'sis', '-s', '2022-04-10', '--term', '2222', '--outdir', outpath]
53+
setup = Helpers::Setup.new
54+
55+
SIS.run_sis(setup)
56+
57+
xml = Nokogiri::XML(File.read(setup.xml_path))
58+
primary_ids = xml.xpath('//user/primary_id').map(&:text)
59+
60+
expect(primary_ids).not_to include('30012345')
61+
expect(primary_ids.length).to eq(1)
62+
end
63+
end
64+
end
65+
66+
describe '.load_ignored_sis_ids' do
67+
it 'loads ignored sis ids from a text file' do
68+
Dir.mktmpdir do |dir|
69+
path = File.join(dir, 'sis_ignore_ids.txt')
70+
71+
File.write(path, <<~TEXT)
72+
# Ignore these users
73+
30000001
74+
75+
30000002
76+
TEXT
77+
78+
expect(SIS.load_ignored_sis_ids(path)).to eq(Set['30000001', '30000002'])
79+
end
80+
end
3181

32-
expect(File.exist?(setup.zip_path)).to eq(true)
33-
expect(File.read(setup.xml_path)).to eq(expected_file)
82+
it 'returns an empty set when the file does not exist' do
83+
expect(SIS.load_ignored_sis_ids('does/not/exist.txt')).to eq(Set.new)
3484
end
3585
end
3686
end
37-
# rubocop :enable Lint/ConstantDefinitionInBlock, Style/MutableConstant
87+
# rubocop :enable Lint/ConstantDefinitionInBlock, Style/MutableConstant, Metrics/BlockLength:
3888

3989
# rubocop:disable Metrics/BlockLength
4090
describe SIS::API do

0 commit comments

Comments
 (0)