Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clear PatronData.authorization_expires if it is no longer set #2147

Merged
merged 1 commit into from
Oct 31, 2024
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
12 changes: 8 additions & 4 deletions src/palace/manager/api/sip/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -420,16 +420,20 @@ def info_to_patrondata(
patrondata.fines = MoneyUtility.parse(fines)
if "sipserver_patron_class" in info:
patrondata.external_type = info["sipserver_patron_class"]

# If we don't have any expiry information, we set it to NO_VALUE,
# so the expiry gets cleared if there once was an expiry, and there
# no longer is, since this can prevent borrowing otherwise.
patron_expiry = PatronData.NO_VALUE
for expire_field in [
"sipserver_patron_expiration",
"polaris_patron_expiration",
]:
if expire_field in info:
value = info.get(expire_field)
value = self.parse_date(value)
if value:
patrondata.authorization_expires = value
if (expiry := self.parse_date(info.get(expire_field))) is not None:
patron_expiry = expiry
break
patrondata.authorization_expires = patron_expiry

if self.patron_status_should_block:
patrondata.block_reason = self.info_to_patrondata_block_reason(
Expand Down
10 changes: 5 additions & 5 deletions tests/manager/api/sip/test_authentication_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ def test_remote_authenticate(
assert "[email protected]" == patrondata.email_address
assert "LE CARRÉ, JOHN" == patrondata.personal_name
assert 0 == patrondata.fines
assert patrondata.authorization_expires is None
assert PatronData.NO_VALUE == patrondata.authorization_expires
assert patrondata.external_type is None
assert PatronData.NO_VALUE == patrondata.block_reason

Expand Down Expand Up @@ -417,7 +417,7 @@ def test_encoding(
assert "[email protected]" == patrondata.email_address
assert "LE CARRÉ, JOHN" == patrondata.personal_name
assert 0 == patrondata.fines
assert patrondata.authorization_expires is None
assert PatronData.NO_VALUE == patrondata.authorization_expires
assert patrondata.external_type is None
assert PatronData.NO_VALUE == patrondata.block_reason

Expand Down Expand Up @@ -560,7 +560,7 @@ def test_info_to_patrondata_validate_password(
assert "[email protected]" == patron.email_address
assert "LE CARRÉ, JOHN" == patron.personal_name
assert 0 == patron.fines
assert patron.authorization_expires is None
assert PatronData.NO_VALUE == patron.authorization_expires
assert patron.external_type is None
assert PatronData.NO_VALUE == patron.block_reason

Expand Down Expand Up @@ -592,7 +592,7 @@ def test_info_to_patrondata_no_validate_password(
assert "[email protected]" == patron.email_address
assert "LE CARRÉ, JOHN" == patron.personal_name
assert 0 == patron.fines
assert patron.authorization_expires is None
assert PatronData.NO_VALUE == patron.authorization_expires
assert patron.external_type is None
assert PatronData.NO_VALUE == patron.block_reason

Expand All @@ -606,7 +606,7 @@ def test_info_to_patrondata_no_validate_password(
assert "[email protected]" == patron.email_address
assert "SHELDON, ALICE" == patron.personal_name
assert 0 == patron.fines
assert patron.authorization_expires is None
assert PatronData.NO_VALUE == patron.authorization_expires
assert patron.external_type is None
assert "no borrowing privileges" == patron.block_reason

Expand Down