Skip to content

Commit 6f1b764

Browse files
committed
Fix rubcopo errors
1 parent e44ecd2 commit 6f1b764

4 files changed

Lines changed: 11 additions & 12 deletions

File tree

app/lib/error/calnet_error.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
module Error
2-
# Raised calnet error when it returns an unexpected response,
3-
# e.g. missing email value because of the schema attribute name changed unexpected by Calnet from 'berkeleyEduAlternateId' to 'berkeleyEduAlternateID' .
2+
# Raised calnet error when it returns an unexpected response, such as missing expected attributes
43
class CalnetError < ApplicationError
54
end
65
end

app/models/user.rb

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def from_omniauth(auth)
2626

2727
private
2828

29-
# rubocop:disable Metrics/MethodLength
29+
# rubocop:disable Metrics/AbcSize, Metrics/MethodLength
3030
def auth_params_from(auth)
3131
auth_extra = auth['extra']
3232
verify_calnet_attributes!(auth_extra)
@@ -49,7 +49,7 @@ def auth_params_from(auth)
4949
alma_admin: cal_groups.include?(ALMA_ADMIN_GROUP)
5050
}
5151
end
52-
# rubocop:enable Metrics/MethodLength
52+
# rubocop:enable Metrics/AbcSize, Metrics/MethodLength
5353

5454
# Verifies that auth_extra contains all required CalNet attributes with exact case-sensitive names
5555
# For array attributes, at least one value in the array must be present in auth_extra
@@ -67,15 +67,15 @@ def verify_calnet_attributes!(auth_extra)
6767

6868
return if missing.empty?
6969

70-
current_calnet_keys = list_auth_extra_keys(auth_extra)
71-
msg = "Cannot find CalNet schema attribute(s) (case-sensitive): #{missing.join(', ')}. The current CalNet schema attributes: #{current_calnet_keys.join(', ')}."
72-
Rails.logger.error(msg)
73-
raise Error::CalnetError, msg
70+
raise_missing_calnet_attribute_error(auth_extra, missing)
7471
end
7572

76-
# list all keys except duo keys
77-
def list_auth_extra_keys(auth_extra)
78-
auth_extra.keys.reject { |k| k.start_with?('duo') }.sort
73+
def raise_missing_calnet_attribute_error(auth_extra)
74+
missing_attrs = "Expected Calnet attribute(s) not found (case-sensitive): #{missing.join(', ')}."
75+
actual_calnet_keys = auth_extra.keys.reject { |k| k.start_with?('duo') }.sort
76+
msg = "#{missing_attrs} The actual CalNet attributes: #{actual_calnet_keys.join(', ')}. The user is #{auth_extra['displayname']}"
77+
Rails.logger.error(msg)
78+
raise Error::CalnetError, msg
7979
end
8080

8181
# Gets an attribute value from auth_extra, handling both string and array attribute names

cleanup_calnet_extra.rb

Whitespace-only changes.

spec/models/user_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
'berkeleyEduCSID' => 'expected cs id',
3030
'berkeleyEduIsMemberOf' => [],
3131
'berkeleyEduUCPathID' => 'expected UC Path ID',
32-
'berkeleyEduAlternatid' => 'expected email', # intentionally wrong case to simulate renamed attribute: berkeleyEduAlternatid instead of berkeleyEduAlternateID
32+
'berkeleyEduAlternatid' => 'expected email', # intentionally wrong case to simulate wrong attribute
3333
'departmentNumber' => 'expected dept. number',
3434
'displayName' => 'expected display name',
3535
'employeeNumber' => 'expected employee ID',

0 commit comments

Comments
 (0)