Skip to content

Commit

Permalink
Clear authorization_expires if it is no longer set.
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathangreen committed Oct 31, 2024
1 parent fefed3d commit 120ee02
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
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

0 comments on commit 120ee02

Please sign in to comment.