Skip to content

Commit

Permalink
Merge pull request #2281 from liberapay/various
Browse files Browse the repository at this point in the history
  • Loading branch information
Changaco authored Oct 3, 2023
2 parents 751f57a + 0964ad4 commit 80e5e36
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 12 deletions.
2 changes: 2 additions & 0 deletions liberapay/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
create_response_object,
delegate_error_to_simplate,
detect_obsolete_browsers,
drop_accept_all_header,
enforce_rate_limits,
insert_constants,
merge_responses,
Expand Down Expand Up @@ -211,6 +212,7 @@ def default_body_parser(body_bytes, headers):

canonize,
algorithm['extract_accept_header'],
drop_accept_all_header,
set_default_security_headers,
csrf.add_csrf_token_to_state,
set_up_i18n,
Expand Down
16 changes: 8 additions & 8 deletions liberapay/models/participant.py
Original file line number Diff line number Diff line change
Expand Up @@ -2406,7 +2406,7 @@ def update_receiving(self, cursor=None):


def set_tip_to(self, tippee, periodic_amount, period='weekly', renewal_mode=None,
visibility=None, update_self=True, update_tippee=True):
visibility=None, update_schedule=True, update_tippee=True):
"""Given a Participant or username, and amount as str, returns a dict.
We INSERT instead of UPDATE, so that we have history to explore. The
Expand All @@ -2431,7 +2431,7 @@ def set_tip_to(self, tippee, periodic_amount, period='weekly', renewal_mode=None
raise NoSelfTipping

if periodic_amount == 0:
return self.stop_tip_to(tippee)
return self.stop_tip_to(tippee, update_schedule=update_schedule)

periodic_amount = periodic_amount.convert_if_currency_is_phased_out()
amount = (periodic_amount * PERIOD_CONVERSION_RATES[period]).round_down()
Expand Down Expand Up @@ -2480,12 +2480,12 @@ def set_tip_to(self, tippee, periodic_amount, period='weekly', renewal_mode=None
t.tipper_p = self
t.tippee_p = tippee

if update_self:
# Update giving amount of tipper
updated = self.update_giving()
for u in updated:
if u.id == t.id:
t.set_attributes(is_funded=u.is_funded)
# Update giving amount of tipper
updated = self.update_giving()
for u in updated:
if u.id == t.id:
t.set_attributes(is_funded=u.is_funded)
if update_schedule:
self.schedule_renewals()
if update_tippee and t.is_funded:
# Update receiving amount of tippee
Expand Down
6 changes: 6 additions & 0 deletions liberapay/utils/state_chain.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,12 @@ def canonize(request, response, website):
raise response.redirect(url)


def drop_accept_all_header(accept_header=None):
# This is a temporary workaround for a shortcoming in Aspen
if accept_header == '*/*':
return {'accept_header': None}


def detect_obsolete_browsers(request, response, state):
"""Respond with a warning message if the user agent seems to be obsolete.
"""
Expand Down
4 changes: 2 additions & 2 deletions templates/macros/payment-methods.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"({list_of_card_brands}), or by direct debit of a Euro bank account "
"(for donations in Euro only).",
username=tippee.username,
list_of_card_brands=["Visa", "Mastercard", "American Express", "UnionPay", "Discover", "Diners"],
list_of_card_brands=["Visa", "Mastercard", "American Express", "UnionPay", "Discover", "Diners", "JCB"],
) if tippee.payment_providers == 1 else _(
"Donations to {username} are processed through PayPal.",
username=tippee.username
Expand All @@ -20,7 +20,7 @@
"({list_of_card_brands}), a Euro bank account (SEPA Direct Debit), or "
"a PayPal account.",
username=tippee.username,
list_of_card_brands=["Visa", "Mastercard", "American Express", "UnionPay", "Discover", "Diners"],
list_of_card_brands=["Visa", "Mastercard", "American Express", "UnionPay", "Discover", "Diners", "JCB"],
) }}
% endmacro

Expand Down
8 changes: 7 additions & 1 deletion tests/py/test_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ def test_basic_search_with_results(self):
Community.create('alice', alice)
response = self.client.GET('/search?q=alice')
assert response.code == 200
assert 'alice' in response.text

def test_get_non_existent_user(self):
response = self.client.GET('/search.json?q=alice&scope=usernames')
Expand All @@ -35,7 +36,7 @@ def test_get_stub_user(self):

def test_get_fuzzy_match(self):
self.make_participant('alice')
response = self.client.GET('/search.json?q=alicia&scope=usernames')
response = self.client.GET('/search.json?q=alice_&scope=usernames')
data = json.loads(response.text)['usernames']
assert len(data) == 1
assert data[0]['username'] == 'alice'
Expand All @@ -54,3 +55,8 @@ def test_search_unknown_languages(self):
)
data = json.loads(response.text)
assert len(data['statements']) == 1

def test_html_is_returned_to_client_requesting_anything(self):
r = self.client.GET('/search?q=something', HTTP_ACCEPT=b'*/*')
assert r.code == 200
assert r.headers[b'Content-Type'] == b'text/html; charset=UTF-8'
2 changes: 1 addition & 1 deletion www/about/faq.spt
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ title = _("Frequently Asked Questions")
"well as SEPA Direct Debits (for Euro donations only). If a payment is "
"through PayPal, then it's possible to pay in various ways, however "
"the donor needs to have or create a PayPal account.",
list_of_card_brands=["Visa", "Mastercard", "American Express", "UnionPay", "Discover", "Diners"]
list_of_card_brands=["Visa", "Mastercard", "American Express", "UnionPay", "Discover", "Diners", "JCB"]
) }}</dd>


Expand Down

0 comments on commit 80e5e36

Please sign in to comment.