Skip to content

Commit 168a538

Browse files
committed
user: Use either capitalisation for email attr
It looks like CalNet may be sending *either* capitalisation for the email attribute, as sometimes users have emails set and other times they don't (even the same user). Ref: AP-583
1 parent f0f5ce3 commit 168a538

3 files changed

Lines changed: 36 additions & 4 deletions

File tree

.idea/altmedia.iml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/models/user.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def from_omniauth(auth)
2323

2424
private
2525

26-
# rubocop:disable Metrics/MethodLength
26+
# rubocop:disable Metrics/AbcSize, Metrics/MethodLength
2727
def auth_params_from(auth)
2828
auth_extra = auth['extra']
2929
cal_groups = auth_extra['berkeleyEduIsMemberOf'] || []
@@ -34,7 +34,7 @@ def auth_params_from(auth)
3434
cs_id: auth_extra['berkeleyEduCSID'],
3535
department_number: auth_extra['departmentNumber'],
3636
display_name: auth_extra['displayName'],
37-
email: auth_extra['berkeleyEduAlternateID'],
37+
email: auth_extra['berkeleyEduAlternateID'] || auth_extra['berkeleyEduAlternateId'],
3838
employee_id: auth_extra['employeeNumber'],
3939
given_name: auth_extra['givenName'],
4040
student_id: auth_extra['berkeleyEduStuID'],
@@ -45,7 +45,7 @@ def auth_params_from(auth)
4545
alma_admin: cal_groups.include?(ALMA_ADMIN_GROUP)
4646
}
4747
end
48-
# rubocop:enable Metrics/MethodLength
48+
# rubocop:enable Metrics/AbcSize, Metrics/MethodLength
4949
end
5050

5151
# Affiliations per CalNet (attribute `berkeleyEduAffiliations` e.g.

spec/models/user_spec.rb

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,38 @@
8888
expect(user.framework_admin).to eq(false)
8989
expect(user.alma_admin).to eq(false)
9090
end
91+
92+
it 'handles a user with old style email attribute' do
93+
auth = {
94+
'provider' => 'calnet',
95+
'extra' => {
96+
'berkeleyEduAffiliations' => 'expected affiliation',
97+
'departmentNumber' => 'expected dept. number',
98+
'displayName' => 'expected display name',
99+
'berkeleyEduAlternateId' => 'expected email',
100+
'employeeNumber' => 'expected employee ID',
101+
'givenName' => 'expected given name',
102+
'berkeleyEduStuID' => 'expected student ID',
103+
'surname' => 'expected surname',
104+
'berkeleyEduUCPathID' => 'expected UC Path ID',
105+
'uid' => 'expected UID'
106+
}
107+
}
108+
109+
user = User.from_omniauth(auth)
110+
expect(user.affiliations).to eq('expected affiliation')
111+
expect(user.department_number).to eq('expected dept. number')
112+
expect(user.display_name).to eq('expected display name')
113+
expect(user.email).to eq('expected email')
114+
expect(user.employee_id).to eq('expected employee ID')
115+
expect(user.given_name).to eq('expected given name')
116+
expect(user.student_id).to eq('expected student ID')
117+
expect(user.surname).to eq('expected surname')
118+
expect(user.ucpath_id).to eq('expected UC Path ID')
119+
expect(user.uid).to eq('expected UID')
120+
expect(user.framework_admin).to eq(false)
121+
expect(user.alma_admin).to eq(false)
122+
end
91123
end
92124

93125
describe :authenticated? do

0 commit comments

Comments
 (0)