Skip to content

Commit 0fe73db

Browse files
authored
Merge pull request #1908 from NYPL-Simplified/qa
Deploy 4.1.6 to Production
2 parents d1bab60 + 62d2a16 commit 0fe73db

File tree

7 files changed

+39
-4
lines changed

7 files changed

+39
-4
lines changed

api/authenticator.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2703,6 +2703,7 @@ def oauth_authentication_callback(self, _db, params):
27032703
patron_info=patron_info,
27042704
root_lane=root_lane,
27052705
is_new=patrondata.is_new,
2706+
age_group=patron.external_type,
27062707
)
27072708
return redirect(client_redirect_uri + "#" + urllib.parse.urlencode(params))
27082709

@@ -2828,6 +2829,7 @@ def basic_auth_temp_token(self, params, _db):
28282829
expires_in=BasicAuthTempTokenController.TOKEN_DURATION.seconds,
28292830
root_lane=root_lane,
28302831
is_new=is_new,
2832+
age_group=patron.external_type,
28312833
)
28322834

28332835
return flask.jsonify(data)

core/facets.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ class FacetConstants(object):
4242
ORDER_SERIES_POSITION = 'series'
4343
ORDER_WORK_ID = 'work_id'
4444
ORDER_RANDOM = 'random'
45+
ORDER_RELEVANCE = 'relevance'
4546
# Some order facets, like series and work id,
4647
# only make sense in certain contexts.
4748
# These are the options that can be enabled
@@ -51,6 +52,7 @@ class FacetConstants(object):
5152
ORDER_AUTHOR,
5253
ORDER_ADDED_TO_COLLECTION,
5354
ORDER_RANDOM,
55+
ORDER_RELEVANCE,
5456
]
5557

5658
ORDER_ASCENDING = "asc"
@@ -88,6 +90,7 @@ class FacetConstants(object):
8890
ORDER_SERIES_POSITION: _('Series Position'),
8991
ORDER_WORK_ID : _('Work ID'),
9092
ORDER_RANDOM : _('Random'),
93+
ORDER_RELEVANCE : _('Relevance'),
9194

9295
AVAILABLE_NOW : _("Available now"),
9396
AVAILABLE_ALL : _("All"),

core/opds.py

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import datetime
22
import logging
3-
from urllib.parse import quote
3+
from urllib.parse import quote, parse_qsl
44
from collections import (
55
defaultdict,
66
)
@@ -1019,9 +1019,27 @@ def make_link(ep):
10191019
# Add "up" link.
10201020
AcquisitionFeed.add_link_to_feed(feed=opds_feed.feed, rel="up", href=annotator.lane_url(lane), title=str(lane.display_name))
10211021

1022-
# Add URLs to change faceted views
1023-
for args in cls.facet_links(annotator, facets):
1024-
AcquisitionFeed.add_link_to_feed(feed=opds_feed.feed, **args)
1022+
# Add URLs to change enabled faceted views
1023+
enabled_order_facets = list(facets.enabled_facets)[0]
1024+
all_order_facets = filter(
1025+
lambda facet: "Sort by" in facet.values(),
1026+
cls.facet_links(annotator, facets)
1027+
)
1028+
original_facet = facets.order
1029+
for facet in all_order_facets:
1030+
order = dict(parse_qsl(facet["href"])).get('order')
1031+
if order in enabled_order_facets:
1032+
facets.order = order
1033+
if order == original_facet:
1034+
facet = cls.facet_link(href=facet["href"], title=facet["title"], facet_group_name="Sort by", is_active=True)
1035+
else:
1036+
facet = cls.facet_link(href=facet["href"], title=facet["title"], facet_group_name="Sort by", is_active=False)
1037+
# cls.facet_links generates a /feed/ url, but we want to use
1038+
# search_url to generate a /search/ url. We also want to generate
1039+
# the facet url for this given ordering facet instead of the original facet.
1040+
facet["href"] = annotator.search_url(lane, query, pagination=None, facets=facets)
1041+
AcquisitionFeed.add_link_to_feed(feed=opds_feed.feed, **facet)
1042+
facets.order = original_facet
10251043

10261044
# We do not add breadcrumbs to this feed since you're not
10271045
# technically searching the this lane; you are searching the

core/tests/test_facets.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,6 @@ def test_enable_facet(self):
3838
config.enable_facet(order_by, Facets.ORDER_RANDOM)
3939
assert Facets.ORDER_RANDOM in config.enabled_facets(order_by)
4040
assert config.default_facet(order_by) != Facets.ORDER_RANDOM
41+
42+
config.enable_facet(order_by, Facets.ORDER_RELEVANCE)
43+
assert Facets.ORDER_RELEVANCE in config.enabled_facets(order_by)

core/tests/test_opds.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1296,6 +1296,9 @@ def make_page(pagination):
12961296
assert 'Title' in sort_by_facets
12971297
assert 'Author' in sort_by_facets
12981298

1299+
[active_facet] = [facet['title'] for facet in facets if getattr(facet, "activefacet", False) == 'true']
1300+
assert active_facet == 'Author'
1301+
12991302
# The feed has no breadcrumb links, since we're not
13001303
# searching the lane -- just using some aspects of the lane
13011304
# to guide the search.

docker/gunicorn.conf.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
bind = ["127.0.0.1:8000"] # listen on 8000, only on the loopback address
2222
workers = (2 * multiprocessing.cpu_count()) + 1
2323
threads = 2
24+
max_requests = 500
25+
max_requests_jitter = 50
2426
pythonpath = ",".join([
2527
str(VENV_ACTUAL),
2628
SIMPLIFIED_HOME,

tests/test_authenticator.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2474,6 +2474,7 @@ def test_authentication_creates_missing_patron(self):
24742474
permanent_id=self._str,
24752475
authorization_identifier=self._str,
24762476
fines=Money(1, "USD"),
2477+
external_type='H',
24772478
)
24782479

24792480
library = self._library()
@@ -2490,6 +2491,7 @@ def test_authentication_creates_missing_patron(self):
24902491
assert (patrondata.authorization_identifier ==
24912492
patron.authorization_identifier)
24922493
assert provider.patron_is_new is True
2494+
assert patron.external_type == patrondata.external_type
24932495

24942496
# Information not relevant to the patron's identity was stored
24952497
# in the Patron object after it was created.
@@ -2793,6 +2795,7 @@ def __init__(self, library, _db, external_authenticate_url, patron, root_lane=No
27932795
self.patrondata = PatronData(personal_name="Abcd", is_new=is_new)
27942796
self.root_lane = root_lane
27952797
self.is_new = self.patrondata.is_new
2798+
self.age_group = self.patron.external_type
27962799

27972800
def external_authenticate_url(self, state, _db):
27982801
return self.url + "?state=" + state
@@ -2878,6 +2881,7 @@ def test_oauth_authentication_callback(self):
28782881
assert self.oauth1.token.credential == provider_token
28792882
assert str(self.oauth1.root_lane) in fragments.get('root_lane')[0]
28802883
assert str(self.oauth1.is_new) == fragments.get('is_new')[0]
2884+
assert str(self.oauth1.age_group) == fragments.get('age_group')[0]
28812885

28822886
# Successful callback through OAuth provider 2.
28832887
params = dict(code="foo", state=json.dumps(dict(provider=self.oauth2.NAME)))

0 commit comments

Comments
 (0)