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 #2378

Merged
merged 8 commits into from
May 31, 2024
Merged

Various #2378

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: 2 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ updates:
interval: "weekly"
day: "tuesday"
ignore:
- dependency-name: "aspen"
- dependency-name: "botocore"
update-types: ["version-update:semver-patch"]
- dependency-name: "pando"
- dependency-name: "psycopg2-pool"
27 changes: 8 additions & 19 deletions liberapay/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ def check_bits(bits):
_ = lambda a: a

ACCOUNT_MARK_CLASSES = {
'trusted': 'success',
'okay': 'info',
'unsettling': 'info',
'controversial': 'warning',
'irrelevant': 'warning',
'misleading': 'warning',
'fraud': 'danger',
'spam': 'danger',
'trusted': 'text-success',
'okay': 'text-info',
'unsettling': 'text-info',
'controversial': 'text-muted',
'irrelevant': 'text-muted',
'misleading': 'text-muted',
'fraud': 'text-danger',
'spam': 'text-danger',
}

ASCII_ALLOWED_IN_USERNAME = set("0123456789"
Expand Down Expand Up @@ -159,17 +159,6 @@ def generate_value(self, currency):

LAUNCH_TIME = datetime(2016, 2, 3, 12, 50, 0, 0, utc)

MARK_CLASSES = {
'trusted': 'text-success',
'okay': 'text-info',
'unsettling': 'text-info',
'controversial': 'text-warning',
'irrelevant': 'text-warning',
'misleading': 'text-warning',
'spam': 'text-danger',
'fraud': 'text-danger',
}

PARTICIPANT_KINDS = {
'individual': _("Individual"),
'organization': _("Organization"),
Expand Down
10 changes: 9 additions & 1 deletion liberapay/models/participant.py
Original file line number Diff line number Diff line change
Expand Up @@ -2307,9 +2307,17 @@ def update_goal(self, goal, cursor=None):
if goal.currency != self.main_currency:
raise UnexpectedCurrency(goal, self.main_currency)
with self.db.get_cursor(cursor) as c:
r = c.one("""
UPDATE participants
SET goal = %(new_goal)s
WHERE id = %(p_id)s
AND ( (goal IS NULL) <> (%(new_goal)s IS NULL) OR goal <> %(new_goal)s )
RETURNING id
""", dict(new_goal=goal, p_id=self.id))
if r is None:
return
json = None if goal is None else str(goal)
self.add_event(c, 'set_goal', json)
c.run("UPDATE participants SET goal=%s WHERE id=%s", (goal, self.id))
self.set_attributes(goal=goal)
if not self.accepts_tips:
tippers = c.all("""
Expand Down
16 changes: 14 additions & 2 deletions liberapay/payin/cron.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def reschedule_renewals():
"""This function looks for inconsistencies in scheduled payins.
"""
donors = website.db.all("""
SELECT p
SELECT p, tips.count AS expected
FROM ( SELECT tip.tipper, count(*)
FROM current_tips tip
JOIN participants tippee_p ON tippee_p.id = tip.tippee
Expand Down Expand Up @@ -62,7 +62,19 @@ def reschedule_renewals():
WHERE sp.payer = p.id
AND sp.payin IS NULL
), 0)
UNION
""")
for p, expected in donors:
logger.info(f"Rescheduling the renewals of participant ~{p.id}")
new_schedule = p.schedule_renewals()
actual = sum(len(sp.transfers) for sp in new_schedule)
if actual < expected:
logger.warning(
"Rescheduling the renewals of participant ~%s failed to correct "
"the imbalance: expected %s, found %s",
p.id, expected, actual,
)
sleep(0.1)
donors = website.db.all("""
SELECT ( SELECT p FROM participants p WHERE p.id = tip.tipper )
FROM current_tips tip
JOIN participants tippee_p ON tippee_p.id = tip.tippee
Expand Down
3 changes: 3 additions & 0 deletions www/%username/edit/avatar.spt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from liberapay.exceptions import BadEmailAddress
from liberapay.utils import form_post_success, get_participant

[---]
Expand All @@ -8,6 +9,8 @@ if request.method == 'POST':

if src not in constants.AVATAR_SOURCES:
raise response.invalid_input(src, 'src', 'body')
if '@' not in email:
raise BadEmailAddress(email)

new_avatar_url = participant.update_avatar(src+':', avatar_email=email)
if new_avatar_url:
Expand Down
2 changes: 1 addition & 1 deletion www/%username/index.html.spt
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ show_income = not participant.hide_receiving and participant.accepts_tips
% if user.is_acting_as('admin')
<p><a class="btn btn-default btn-lg" href="{{ participant.path('admin') }}">Admin</a></p>
% if participant.marked_as
<p>Marked as: <span class="{{ constants.MARK_CLASSES[participant.marked_as] }}">{{ participant.marked_as }}</span></p>
<p>Marked as: <span class="{{ constants.ACCOUNT_MARK_CLASSES[participant.marked_as] }}">{{ participant.marked_as }}</span></p>
% else
<p class="text-muted">Not marked</p>
% endif
Expand Down
2 changes: 1 addition & 1 deletion www/admin/admins.spt
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ title = "Admins Oversight"
% elif marked_as == ''
<p>{{ e.recorder_name }} marked the profile <a href="/~{{ e.participant }}/">{{ e.username }}</a> as <code>{{ e.payload }}</code>.</p>
% else
<p>{{ e.recorder_name }} marked the profile <a href="/~{{ e.participant }}/">{{ e.username }}</a> as <span class="{{ constants.MARK_CLASSES.get(marked_as, 'text-muted') }}">{{ marked_as }}</span>.</p>
<p>{{ e.recorder_name }} marked the profile <a href="/~{{ e.participant }}/">{{ e.username }}</a> as <span class="{{ constants.ACCOUNT_MARK_CLASSES.get(marked_as, 'text-muted') }}">{{ marked_as }}</span>.</p>
% endif
% endif
% endfor
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 @@ -307,7 +307,7 @@ title = "Email Domains"
% for p in participants
<tr>
<td><a class="break-word-anywhere" href="/~{{ p.id }}/">{{ p.username }}</a>{% if p.marked_as %}<br>
<span class="text-{{ constants.ACCOUNT_MARK_CLASSES[p.marked_as] }}">[{{ p.marked_as }}]</span>{% endif %}</td>
<span class="{{ constants.ACCOUNT_MARK_CLASSES[p.marked_as] }}">[{{ p.marked_as }}]</span>{% endif %}</td>
<td>
% for ea in p.addresses
<span class="break-word-anywhere">{{ ea.address }}</span>
Expand Down
2 changes: 1 addition & 1 deletion www/admin/payments.spt
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ title = "Payments Admin"
) -}}
</span>
{% endif %}{% if pi.payer_marked_as %}<br>
<span class="text-{{ constants.ACCOUNT_MARK_CLASSES[pi.payer_marked_as] }}">[{{
<span class="{{ constants.ACCOUNT_MARK_CLASSES[pi.payer_marked_as] }}">[{{
pi.payer_marked_as
}}]</span>{% endif %}</td>
<td class="text-center">{{
Expand Down
2 changes: 1 addition & 1 deletion www/admin/users.spt
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ elif mode == 'new_recipients':
ORDER BY min(pt.id) DESC
LIMIT 25
""", (last_showed,))
page_end = participants[-1].incoming_payments[-1]['id'] if participants else None
page_end = participants[-1].incoming_payments[0]['id'] if participants else None
else:
raise response.invalid_input(mode, 'mode', 'querystring')

Expand Down
2 changes: 1 addition & 1 deletion www/payment-providers/%provider/connect.spt
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ elif 'state' in request.qs:
raise ValueError(provider_name)
if token_response.status_code != 200:
website.logger.error(
f"{provider.display_name} responded with {response.code}: {token_response.text}"
f"{provider.display_name} responded with {token_response.code}: {token_response.text}"
)
raise response.error(502, _(
"{0} returned an error, please try again later.", provider.display_name
Expand Down
Loading