Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Various #2337

Merged
merged 5 commits into from
Apr 9, 2024
Merged

Various #2337

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ Make sure you have the following dependencies installed first:

- python ≥ 3.11
- including the C headers of python and libffi, which are packaged separately in many Linux distributions
- postgresql 13 (see [the official download & install docs](https://www.postgresql.org/download/))
- postgresql 16 (see [the official download & install docs](https://www.postgresql.org/download/))
- make

Then run:
Expand Down
49 changes: 31 additions & 18 deletions liberapay/cron.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,30 +172,43 @@ def f():
self.running = False
self.cron.website.tell_sentry(e)
if self.exclusive:
try:
self.cron.website.db.run("""
INSERT INTO cron_jobs
(name, last_error_time, last_error)
VALUES (%s, current_timestamp, %s)
ON CONFLICT (name) DO UPDATE
SET last_error_time = excluded.last_error_time
, last_error = excluded.last_error
""", (func_name, traceback.format_exc()))
except psycopg2.OperationalError:
pass
while True:
try:
self.cron.website.db.run("""
INSERT INTO cron_jobs
(name, last_error_time, last_error)
VALUES (%s, current_timestamp, %s)
ON CONFLICT (name) DO UPDATE
SET last_error_time = excluded.last_error_time
, last_error = excluded.last_error
""", (func_name, traceback.format_exc()))
except psycopg2.OperationalError as e:
self.cron.website.tell_sentry(e)
# retry in a minute
sleep(60)
else:
break
# retry in a minute
sleep(60)
continue
else:
self.running = False
if self.exclusive:
self.cron.website.db.run("""
INSERT INTO cron_jobs
(name, last_success_time)
VALUES (%s, current_timestamp)
ON CONFLICT (name) DO UPDATE
SET last_success_time = excluded.last_success_time
""", (func_name,))
while True:
try:
self.cron.website.db.run("""
INSERT INTO cron_jobs
(name, last_success_time)
VALUES (%s, current_timestamp)
ON CONFLICT (name) DO UPDATE
SET last_success_time = excluded.last_success_time
""", (func_name,))
except psycopg2.OperationalError:
self.cron.website.tell_sentry(e)
# retry in a minute
sleep(60)
else:
break
if period == 'irregular':
if r is None:
return
Expand Down
5 changes: 5 additions & 0 deletions liberapay/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,11 @@ def msg(self, _):
return _("The username '{0}' contains invalid characters.", self.username)


class UsernameIsPurelyNumerical(UsernameError):
def msg(self, _):
return _("The username '{0}' is purely numerical. This isn't allowed.")


class UsernameIsRestricted(UsernameError):
def msg(self, _):
return _("The username '{0}' is restricted.", self.username)
Expand Down
7 changes: 6 additions & 1 deletion liberapay/models/participant.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
UsernameContainsInvalidCharacters,
UsernameEndsWithForbiddenSuffix,
UsernameIsEmpty,
UsernameIsPurelyNumerical,
UsernameIsRestricted,
UsernameTooLong,
ValueTooLong,
Expand Down Expand Up @@ -2048,6 +2049,9 @@ def check_username(suggested):
if set(suggested) - ASCII_ALLOWED_IN_USERNAME:
raise UsernameContainsInvalidCharacters(suggested)

if suggested.isdigit():
raise UsernameIsPurelyNumerical(suggested)

if suggested[0] == '.':
raise UsernameBeginsWithRestrictedCharacter(suggested)

Expand All @@ -2059,7 +2063,8 @@ def check_username(suggested):
raise UsernameIsRestricted(suggested)

def change_username(self, suggested, cursor=None, recorder=None):
self.check_username(suggested)
if suggested != f'~{self.id}':
self.check_username(suggested)
recorder_id = getattr(recorder, 'id', None)

if suggested != self.username:
Expand Down
4 changes: 2 additions & 2 deletions style/base/icons.scss
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@
width: 17px;
}
.icon-32 {
height: 32px;
width: 32px;
height: 34px;
width: 34px;
}
5 changes: 3 additions & 2 deletions templates/macros/icons.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,9 @@
% macro icon(name, sr='', size=16)
% set name = icon_aliases.get(name, name)
% if soft_assert(name in website.icon_names, "unknown icon name %r" % name)
<svg aria-hidden="true" class="icon icon-{{ size }}" {% if sr %} title="{{ sr }}"{% endif %}{#
#}><use xlink:href="{{ website.asset('icons.svg', domain=False) }}#{{ name }}"/></svg>
<span aria-hidden="true" {% if sr %} title="{{ sr }}"{% endif %}{#
#}><svg class="icon icon-{{ size }}"{#
#}><use xlink:href="{{ website.asset('icons.svg', domain=False) }}#{{ name }}"/></svg></span>
% else
<img aria-hidden="true" class="icon icon-{{ size }}" {% if sr %} title="{{ sr }}"{% endif %} src="/assets/nonexistent" />
% endif
Expand Down
26 changes: 26 additions & 0 deletions www/admin/users.spt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ PT_STATUS_MAP = {
}
ACCOUNT_MARKS = set(website.db.one("SELECT array_to_json(enum_range(NULL::account_mark))"))
ACCOUNT_MARKS.add('')
PAYMENT_INSTRUMENT_TYPES = {
'paypal': "PayPal",
'stripe-card': "card",
'stripe-sdd': "SEPA mandate",
}

[---]

Expand Down Expand Up @@ -101,6 +106,14 @@ if mode == 'all':
WHERE tip.tipper = p.id
) tip
) AS outgoing_donations
, ( SELECT json_objectagg(r.network:r.count)
FROM ( SELECT r.network, count(*) AS count
FROM exchange_routes r
WHERE r.participant = p.id
GROUP BY r.network
ORDER BY r.network
) r
) AS payment_instruments
, ( SELECT json_agg(json_build_object(
'provider', a.provider,
'id', a.id,
Expand Down Expand Up @@ -346,6 +359,19 @@ title = "Users Admin"
none.
% endif
</p>

% if row.payment_instruments is defined
<p><strong>Payment instruments:</strong>
% if row.payment_instruments
% for network, count in row.payment_instruments.items()
{{ count }} {{ PAYMENT_INSTRUMENT_TYPES.get(network, network) }}
{{- '' if count == 1 else 's' }}
{{- '.' if loop.last else ',' }}
% endfor
% else
none.
% endif
% endif
% endif

<p><strong>Payment accounts:</strong>
Expand Down
Loading