From cf8031ba290d2ad8fd31667bc70e77becef52d0e Mon Sep 17 00:00:00 2001
From: Changaco
Date: Wed, 28 Jul 2021 09:48:38 +0200
Subject: [PATCH 1/3] harmonize the display of countries in `/admin/users`
---
www/admin/users.spt | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/www/admin/users.spt b/www/admin/users.spt
index 09ef8fdf10..b89366ac77 100644
--- a/www/admin/users.spt
+++ b/www/admin/users.spt
@@ -344,8 +344,13 @@ title = "Users Admin"
% endif
% set ip_address = headers.get('Cf-Connecting-Ip')
% set country_code = headers.get('Cf-Ipcountry')
+ % if country_code
+ % set country_name = locale.countries.get(country_code, country_code)
+ % else
+ % set country_name = 'country unknown'
+ % endif
% if ip_address
- IP address: {{ ip_address }} ({{ country_code or 'country unknown' }})
+ IP address: {{ ip_address }} ({{ country_name }})
% else
IP address: unknown.
% endif
From 55a033046956a15421e63fd5f4863ca735013377 Mon Sep 17 00:00:00 2001
From: Changaco
Date: Wed, 28 Jul 2021 11:36:15 +0200
Subject: [PATCH 2/3] fix the display of IP addresses in `/admin/users`
---
www/admin/users.spt | 8 +++-----
1 file changed, 3 insertions(+), 5 deletions(-)
diff --git a/www/admin/users.spt b/www/admin/users.spt
index b89366ac77..2d0e83ee0e 100644
--- a/www/admin/users.spt
+++ b/www/admin/users.spt
@@ -337,11 +337,8 @@ title = "Users Admin"
% endif
- % if row.sign_up_request|default(None)
- % set headers = row.sign_up_request.get('headers', {})
- % else
- % set headers = {}
- % endif
+ % if row.sign_up_request is defined
+ % set headers = (row.sign_up_request or {}).get('headers', {})
% set ip_address = headers.get('Cf-Connecting-Ip')
% set country_code = headers.get('Cf-Ipcountry')
% if country_code
@@ -355,6 +352,7 @@ title = "Users Admin"
IP address: unknown.
% endif
% endif
+ % endif
Profile descriptions:
% if p.public_name
From 4929a2959a74f9227281d06d34717d51009d70f3 Mon Sep 17 00:00:00 2001
From: Changaco
Date: Sat, 31 Jul 2021 11:00:45 +0200
Subject: [PATCH 3/3] fix the adjusting of automatic renewal amounts
---
liberapay/models/participant.py | 19 +++++++++----------
tests/py/test_schedule.py | 14 +++++++-------
2 files changed, 16 insertions(+), 17 deletions(-)
diff --git a/liberapay/models/participant.py b/liberapay/models/participant.py
index f567889fe2..6e08b684e4 100644
--- a/liberapay/models/participant.py
+++ b/liberapay/models/participant.py
@@ -2844,23 +2844,21 @@ def find_partial_match(new_sp, current_schedule_map):
new_sp.transfers.sort(key=tippee_id_getter)
# Check the charge amount
if renewal_mode == 2:
- adjust = False
+ unadjusted_amount = new_sp.amount
pp = PayinProspect(self, payin_tips, 'stripe')
if new_sp.amount < pp.min_acceptable_amount:
- adjust = True
new_sp.amount = pp.min_acceptable_amount
elif new_sp.amount > pp.max_acceptable_amount:
- adjust = True
new_sp.amount = pp.max_acceptable_amount
if past_payin_amount_maximum:
maximum = past_payin_amount_maximum.convert(payin_currency)
- adjust = (
- new_sp.amount > maximum and
- maximum >= pp.moderate_proposed_amount
- )
- if adjust:
- new_sp.amount = maximum
- if adjust:
+ if new_sp.amount > maximum:
+ new_sp.amount = max(
+ maximum,
+ pp.moderate_fee_amount,
+ pp.one_weeks_worth,
+ )
+ if new_sp.amount != unadjusted_amount:
tr_amounts = resolve_amounts(
new_sp.amount,
{tip.tippee: tip.amount for tip in payin_tips}
@@ -2868,6 +2866,7 @@ def find_partial_match(new_sp, current_schedule_map):
for tr in new_sp.transfers:
tr['amount'] = tr_amounts[tr['tippee_id']]
del tr_amounts
+ del unadjusted_amount
# Try to find this new payment in the current schedule
tippees = get_tippees_tuple(new_sp)
cur_sp = current_schedule_map.pop(tippees, None)
diff --git a/tests/py/test_schedule.py b/tests/py/test_schedule.py
index 2b59ad530f..d3546fa095 100644
--- a/tests/py/test_schedule.py
+++ b/tests/py/test_schedule.py
@@ -676,18 +676,18 @@ def test_no_new_renewal_is_scheduled_when_there_is_a_pending_transfer(self):
assert len(scheduled_payins) == 0
def test_newly_scheduled_automatic_payments_are_at_least_a_week_away(self):
- # Set up an automatic donation funded 4 weeks ago
+ # Set up an automatic donation partially funded 4 weeks ago
alice = self.make_participant('alice', email='alice@liberapay.com')
bob = self.make_participant('bob')
- alice.set_tip_to(bob, EUR('0.23'), renewal_mode=2)
+ alice.set_tip_to(bob, EUR('3.00'), renewal_mode=2)
alice_sdd = self.upsert_route(alice, 'stripe-sdd')
- payin, pt = self.make_payin_and_transfer(alice_sdd, bob, EUR('0.22'), status='pending')
+ payin, pt = self.make_payin_and_transfer(alice_sdd, bob, EUR('2.00'), status='pending')
self.db.run("UPDATE payin_transfers SET ctime = ctime - interval '4 weeks'")
update_payin_transfer(self.db, pt.id, pt.remote_id, 'succeeded', None)
# At this point we should have an automatic renewal scheduled one week from now
scheduled_payins = self.db.all("SELECT * FROM scheduled_payins")
assert len(scheduled_payins) == 1
- assert scheduled_payins[0].amount == EUR('10.12')
+ assert scheduled_payins[0].amount == EUR('10.00')
assert scheduled_payins[0].automatic is True
payment_timedelta = scheduled_payins[0].execution_date - utcnow().date()
assert payment_timedelta.days in (6, 7)
@@ -702,9 +702,9 @@ def test_late_manual_payment_switched_to_automatic_is_scheduled_a_week_away(self
# Set up a manual donation
alice = self.make_participant('alice', email='alice@liberapay.com')
bob = self.make_participant('bob')
- alice.set_tip_to(bob, EUR('0.23'), renewal_mode=1)
+ alice.set_tip_to(bob, EUR('3.00'), renewal_mode=1)
alice_sdd = self.upsert_route(alice, 'stripe-sdd')
- payin, pt = self.make_payin_and_transfer(alice_sdd, bob, EUR('0.22'), status='pending')
+ payin, pt = self.make_payin_and_transfer(alice_sdd, bob, EUR('2.00'), status='pending')
self.db.run("UPDATE payin_transfers SET ctime = ctime - interval '3 weeks'")
update_payin_transfer(self.db, pt.id, pt.remote_id, 'succeeded', None)
# At this point we should have a manual renewal scheduled in the past
@@ -726,7 +726,7 @@ def test_late_manual_payment_switched_to_automatic_is_scheduled_a_week_away(self
assert tip.renewal_mode == 2
scheduled_payins = self.db.all("SELECT * FROM scheduled_payins WHERE payin IS NULL")
assert len(scheduled_payins) == 1
- assert scheduled_payins[0].amount == EUR('10.12')
+ assert scheduled_payins[0].amount == EUR('10.00')
assert scheduled_payins[0].automatic is True
payment_timedelta = scheduled_payins[0].execution_date - utcnow().date()
assert payment_timedelta.days in (6, 7)