Skip to content

Commit

Permalink
Merge pull request #2461 from liberapay/various
Browse files Browse the repository at this point in the history
  • Loading branch information
Changaco authored Sep 30, 2024
2 parents 42b043a + 03e105f commit 8348a2d
Show file tree
Hide file tree
Showing 10 changed files with 50 additions and 24 deletions.
11 changes: 7 additions & 4 deletions liberapay/cron.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,23 @@ def __call__(self, period, func, exclusive=False):
job.start()

def _wait_for_lock(self):
if self.conn:
if self._lock_thread:
return # Already waiting
self.conn = self.website.db.get_connection().__enter__()
def f():
while True:
try:
g()
except psycopg2.errors.IdleInTransactionSessionTimeout:
except Exception as e:
if not isinstance(e, psycopg2.errors.IdleInTransactionSessionTimeout):
self.website.tell_sentry(e)
if self.has_lock:
self.has_lock = False
self.conn = None
sleep(10)
self.conn = self.website.db.get_connection().__enter__()

def g():
if not self.conn:
self.conn = self.website.db.get_connection().__enter__()
cursor = self.conn.cursor()
while True:
if cursor.one("SELECT pg_try_advisory_lock(0)"):
Expand Down
8 changes: 7 additions & 1 deletion liberapay/models/exchange_route.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,13 @@ def attach_stripe_source(cls, participant, source, one_off):
def invalidate(self, obj=None):
if self.network.startswith('stripe-'):
if self.address.startswith('pm_'):
stripe.PaymentMethod.detach(self.address)
try:
stripe.PaymentMethod.detach(self.address)
except stripe.error.InvalidRequestError as e:
if "The payment method you provided is not attached " in str(e):
pass
else:
raise
else:
try:
source = stripe.Source.retrieve(self.address).detach()
Expand Down
34 changes: 20 additions & 14 deletions liberapay/utils/emails.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,11 +222,11 @@ def test_email_address(email: NormalizedEmailAddress, timeout: float = 30.0):
website.tell_sentry(e)
exceptions.append(e)
n_attempts += 1
if n_attempts >= 3:
if n_attempts >= 10:
break
time_elapsed = time.monotonic() - start_time
timeout = website.app_conf.socket_timeout - time_elapsed
if timeout <= 3:
timeout -= time_elapsed
if timeout < 2:
break
if not success:
if n_ip_addresses == 0:
Expand Down Expand Up @@ -372,20 +372,26 @@ def test_email_server(ip_address: str, email=None, timeout=None) -> None:
enhanced_code, msg = parse_SMTP_reply(msg)
if enhanced_code:
cls, subject, detail = enhanced_code.split('.')
recipient_rejected = cls in '45' and (
else:
cls = subject = detail = None
recipient_rejected = (
cls and cls in '45' and (
# Address errors
subject == '1' and detail in '12346' or
# Mailbox errors
subject == '2' and detail in '124' or
# gamil.com SMTP server
msg.startswith("sorry, no mailbox here by that name") or
# Microsoft's SMTP server
msg.startswith("Requested action not taken: mailbox unavailable") or
# Tutanota's SMTP server
msg.endswith("Recipient address rejected: Recipient not found")
)
if recipient_rejected:
raise EmailAddressRejected(email, msg, ip_address)
subject == '2' and detail in '124'
) or
# gamil.com SMTP server
msg.startswith("sorry, no mailbox here by that name") or
# Microsoft's SMTP server
msg.startswith("Requested action not taken: mailbox unavailable") or
# OpenSMTPD
msg.startswith("Invalid recipient: ") or
# Tutanota's SMTP server
msg.endswith("Recipient address rejected: Recipient not found")
)
if recipient_rejected:
raise EmailAddressRejected(email, msg, ip_address)
finally:
try:
smtp.close()
Expand Down
1 change: 1 addition & 0 deletions liberapay/utils/state_chain.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ def attach_environ_to_request(environ, request):
except UnicodeDecodeError:
request.hostname = ''
request.subdomain = None
request.save_data = request.headers.get(b'Save-Data') == b'on'


def create_response_object(request, website):
Expand Down
File renamed without changes.
3 changes: 3 additions & 0 deletions templates/layouts/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
<link rel="icon" href="{{ website.asset('liberapay/icon-v2_black.16.png') }}" type="image/png">
<link rel="apple-touch-icon" href="{{ website.asset('liberapay/icon-v2_black-on-yellow.200.png') }}">
<link rel="stylesheet" href="{{ website.asset('bootstrap/css/bootstrap.css') }}">
% if not request.save_data
<link rel="stylesheet" href="{{ website.asset('fonts.css') }}" type="text/css">
% endif
<link rel="stylesheet" href="{{ website.asset('base.css') }}" type="text/css">
% block head_alternates
% if request.method in constants.SAFE_METHODS and response.code == 200
Expand Down
2 changes: 1 addition & 1 deletion www/admin/email-domains.spt
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ title = "Email Domains"
<tbody>
% for d in email_domains
<tr>
<td><a href="?domain={{ d.domain }}">{{ d.domain }}</a></td>
<td><a class="break-word-anywhere" href="?domain={{ d.domain }}">{{ d.domain }}</a></td>
<td class="text-center">{{ d.n_addresses }}</td>
% set percent_verified = d.n_verified / d.n_addresses if d.n_addresses else 1
<td class="text-center {{ 'danger' if percent_verified <= 0.2 else 'warning' if percent_verified <= 0.5 else '' }}">{{ d.n_verified }}</td>
Expand Down
6 changes: 3 additions & 3 deletions www/admin/emails.spt
Original file line number Diff line number Diff line change
Expand Up @@ -127,15 +127,15 @@ title = "Email Addresses"
</form>

% if request.method != 'POST'
<h3>Bounces and complaints</h3>
<h3>Blocked addresses</h3>
% if blacklist_entries
<form action="" method="POST">
<input type="hidden" name="csrf_token" value="{{ csrf_token }}" />
% for e in blacklist_entries
<p>
<button class="link" name="email" value="{{ e.address }}">{{ e.address }}</button> :
{{ "a complaint was received" if e.reason == 'complaint' else "a message bounced" }}
at {{ locale.format_time(e.ts.time()) }} on {{ locale.format_date(e.ts.date(), format='long') }}.
blocked since {{ locale.format_time(e.ts.time()) }} on {{ locale.format_date(e.ts.date(), format='long') }},
reason = {{ repr(e.reason) }}
</p>
% endfor
</form>
Expand Down
6 changes: 5 additions & 1 deletion www/admin/users.spt
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ if request.method == 'POST':
last_showed = request.qs.get_int('last_showed', default=None)
mode = request.qs.get('mode', 'all')
if mode == 'all':
marked_as = request.qs.get('marked_as')
participants = website.db.all("""
SELECT p
, c.name AS c_name
Expand Down Expand Up @@ -144,6 +145,8 @@ if mode == 'all':
FROM events e
WHERE e.participant = p.id
AND e.type = 'sign_up_request'
ORDER BY e.ts
LIMIT 1
) AS sign_up_request
, ( SELECT row_to_json(e)
FROM ( SELECT e.*, p2.username AS recorder_name
Expand All @@ -159,10 +162,11 @@ if mode == 'all':
LEFT JOIN communities c ON c.participant = p.id
LEFT JOIN feedback f ON f.participant = p.id
WHERE coalesce(p.id < %s, true)
AND coalesce(p.marked_as = %s, true)
AND (p.status <> 'stub' OR p.receiving > 0)
ORDER BY p.id DESC
LIMIT 25
""", (last_showed,))
""", (last_showed, marked_as))
page_end = participants[-1][0].id if participants else None
elif mode == 'new_recipients':
participants = website.db.all("""
Expand Down
3 changes: 3 additions & 0 deletions www/assets/fonts.css.spt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[---]
[---] text/css via scss
@import "style/fonts";

0 comments on commit 8348a2d

Please sign in to comment.