From 187259c8d0e2d182f3ec098a316af9fb8045c703 Mon Sep 17 00:00:00 2001 From: Changaco Date: Tue, 26 Sep 2023 13:54:28 +0200 Subject: [PATCH 1/4] tweak the arguments and behaviour of `set_tip_to()` --- liberapay/models/participant.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/liberapay/models/participant.py b/liberapay/models/participant.py index a44b66005..220e82d50 100644 --- a/liberapay/models/participant.py +++ b/liberapay/models/participant.py @@ -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 @@ -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() @@ -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 From 8adc5b242b8e8f907d7023489807a8dd9599427d Mon Sep 17 00:00:00 2001 From: Changaco Date: Thu, 28 Sep 2023 12:48:29 +0200 Subject: [PATCH 2/4] fix unintended JSON responses to generic HTTP queries --- liberapay/main.py | 2 ++ liberapay/utils/state_chain.py | 6 ++++++ tests/py/test_search.py | 6 ++++++ 3 files changed, 14 insertions(+) diff --git a/liberapay/main.py b/liberapay/main.py index 0a54b2a27..a8c02b351 100644 --- a/liberapay/main.py +++ b/liberapay/main.py @@ -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, @@ -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, diff --git a/liberapay/utils/state_chain.py b/liberapay/utils/state_chain.py index 89fc6ee60..e67beb863 100644 --- a/liberapay/utils/state_chain.py +++ b/liberapay/utils/state_chain.py @@ -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. """ diff --git a/tests/py/test_search.py b/tests/py/test_search.py index d4b996dde..22fb01539 100644 --- a/tests/py/test_search.py +++ b/tests/py/test_search.py @@ -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') @@ -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' From 07ab70c8a83de97a0e522fdfa1983bce5adb4e0a Mon Sep 17 00:00:00 2001 From: Changaco Date: Thu, 28 Sep 2023 13:55:44 +0200 Subject: [PATCH 3/4] tweak a search test to be less sensitive --- tests/py/test_search.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/py/test_search.py b/tests/py/test_search.py index 22fb01539..fad3b7149 100644 --- a/tests/py/test_search.py +++ b/tests/py/test_search.py @@ -36,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' From 0964ad4022177c7200f431e1ee5c76b91298fa7d Mon Sep 17 00:00:00 2001 From: Changaco Date: Fri, 29 Sep 2023 22:23:18 +0200 Subject: [PATCH 4/4] add JCB to supported card brands --- templates/macros/payment-methods.html | 4 ++-- www/about/faq.spt | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/templates/macros/payment-methods.html b/templates/macros/payment-methods.html index 700b045fc..cee07765c 100644 --- a/templates/macros/payment-methods.html +++ b/templates/macros/payment-methods.html @@ -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 @@ -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 diff --git a/www/about/faq.spt b/www/about/faq.spt index 7c99b1d38..35b810d5d 100644 --- a/www/about/faq.spt +++ b/www/about/faq.spt @@ -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"] ) }}