Skip to content

Commit

Permalink
Merge pull request #1910 from NYPL-Simplified/SMA-523-add-open-access…
Browse files Browse the repository at this point in the history
…-until-date

Sma 523 add open access until date
  • Loading branch information
mwbenowitz authored Nov 17, 2023
2 parents 28b876a + b579692 commit ca033a1
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 5 deletions.
3 changes: 2 additions & 1 deletion api/opds.py
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,7 @@ def open_access_link(self, pool, lpdm):
always_available = OPDSFeed.makeelement(
"{%s}availability" % OPDSFeed.OPDS_NS, status="available"
)

link_tag.append(always_available)
return link_tag

Expand Down Expand Up @@ -1130,7 +1131,7 @@ def fulfill_link(self, license_pool, active_loan, delivery_mechanism,
active_loan=active_loan
)

children = AcquisitionFeed.license_tags(license_pool, active_loan, None)
children = AcquisitionFeed.license_tags(license_pool, active_loan, None, rel=rel, library=self.library)
link_tag.extend(children)

children = self.drm_device_registration_tags(
Expand Down
14 changes: 10 additions & 4 deletions core/opds.py
Original file line number Diff line number Diff line change
Expand Up @@ -1650,7 +1650,7 @@ def indirect_acquisition(cls, indirect_types):
return top_level_parent

@classmethod
def license_tags(cls, license_pool, loan, hold):
def license_tags(cls, license_pool, loan, hold, rel=None, library=None):
# Generate a list of licensing tags. These should be inserted
# into a <link> tag.
tags = []
Expand Down Expand Up @@ -1688,10 +1688,16 @@ def license_tags(cls, license_pool, loan, hold):
else:
status = 'reserved'
since = hold.start
elif (license_pool.open_access or license_pool.unlimited_access or license_pool.self_hosted or (
elif (license_pool.open_access or rel == OPDSFeed.OPEN_ACCESS_REL):
status = 'available'

default_loan_period = collection.default_loan_period(library) if library else collection.STANDARD_DEFAULT_LOAN_PERIOD

since = license_pool.availability_time
until = datetime.datetime.utcnow() + datetime.timedelta(days=default_loan_period)
elif (license_pool.unlimited_access or license_pool.self_hosted or (
license_pool.licenses_available > 0 and
license_pool.licenses_owned > 0)
):
license_pool.licenses_owned > 0)):
status = 'available'
else:
status='unavailable'
Expand Down
27 changes: 27 additions & 0 deletions core/tests/test_opds.py
Original file line number Diff line number Diff line change
Expand Up @@ -1625,6 +1625,33 @@ def test_license_tags_show_self_hosted_books(self):
assert 'status' in tags[0].attrib
assert 'available' == tags[0].attrib['status']

def test_license_tags_open_access(self):
# Arrange
edition, pool = self._edition(with_license_pool=True)
pool.open_access = True
pool.self_hosted = False
pool.unlimited_access = False
creation_time = datetime.datetime.utcnow()

# Act
tags = AcquisitionFeed.license_tags(
pool, None, None
)

# Assert
assert 1 == len(tags)

[tag] = tags

assert ('status' in tag.attrib) == True
assert 'available' == tag.attrib['status']
assert 'since' in tag.attrib
assert tag.attrib['since'] == pool.availability_time.strftime('%Y-%m-%dT%H:%M:%S+00:00')
assert 'until' in tag.attrib
assert tag.attrib['until'] == (creation_time + datetime.timedelta(days=21)).strftime('%Y-%m-%dT%H:%M:%SZ')
assert ('holds' in tag.attrib) == False
assert ('copies' in tag.attrib) == False

def test_single_entry(self):

# Here's a Work with two LicensePools.
Expand Down

0 comments on commit ca033a1

Please sign in to comment.