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

Merged
merged 4 commits into from
Apr 17, 2024
Merged

Various #2342

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
32 changes: 23 additions & 9 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,27 @@ jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Install PostgreSQL 16
run: |
sudo sh -c 'echo "deb https://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
sudo apt-get update
sudo apt-get install -y postgresql-16
- name: Start PostgreSQL
run: |
sudo systemctl cat [email protected]
sudo systemctl start [email protected]
sudo systemctl status [email protected]
ls -la /var/run/postgresql/
- name: Set libpq environment variables
run: echo PGPORT=5433 >>$GITHUB_ENV
- name: Create the database user
run: sudo -E -u postgres createuser --superuser $(whoami)
- name: Create the test database
run: createdb liberapay_tests
- name: Create the test database schema
run: DATABASE_URL=liberapay_tests ./recreate-schema.sh test
- name: Install Python 3.11
uses: actions/setup-python@v4
with:
Expand All @@ -25,21 +45,15 @@ jobs:
with:
path: .tox
key: test-${{ runner.os }}-${{ hashFiles('requirements_*.txt') }}
- name: Start PostgreSQL
run: sudo systemctl start postgresql.service
- name: Create the database user
run: sudo -u postgres createuser --superuser $(whoami)
- name: Create the test database
run: createdb liberapay_tests
- name: Create the test database schema
run: DATABASE_URL=liberapay_tests ./recreate-schema.sh test
- name: Enable expensive tests, on the master branch only
if: ${{ env.GITHUB_HEAD_REF == 'master' }}
run: |
rm -rfv tests/py/fixtures
echo LIBERAPAY_I18N_TEST=yes >> $GITHUB_ENV
- name: Install tox
run: pip install tox
- name: Write liberapay environment file for tests
run: echo 'DATABASE_URL="port=5433 dbname=liberapay_tests"' >tests/local.env
- name: Run the tests
run: tox
- name: Upload coverage reports to Codecov
Expand Down
2 changes: 1 addition & 1 deletion liberapay/cron.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ def f():
ON CONFLICT (name) DO UPDATE
SET last_success_time = excluded.last_success_time
""", (func_name,))
except psycopg2.OperationalError:
except psycopg2.OperationalError as e:
self.cron.website.tell_sentry(e)
# retry in a minute
sleep(60)
Expand Down
6 changes: 3 additions & 3 deletions liberapay/elsewhere/twitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ class Twitter(PlatformOAuth1):
prev='previous_cursor',
next='next_cursor')
api_url = 'https://api.twitter.com/1.1'
api_user_info_path = '/users/show.json?user_id={user_id}&include_entities=false'
api_user_name_info_path = '/users/show.json?screen_name={user_name}&include_entities=false'
# api_user_info_path = '/users/show.json?user_id={user_id}&include_entities=false'
# api_user_name_info_path = '/users/show.json?screen_name={user_name}&include_entities=false'
api_user_self_info_path = '/account/verify_credentials.json?include_entities=false&skip_status=true'
api_follows_path = '/friends/list.json?user_id={user_id}&include_user_entities=false&skip_status=true'
# api_follows_path = '/friends/list.json?user_id={user_id}&include_user_entities=false&skip_status=true'
ratelimit_headers_prefix = 'x-rate-limit-'

# User info extractors
Expand Down
13 changes: 13 additions & 0 deletions liberapay/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,19 @@ def msg(self, _, locale):
)


class UnacceptedDonationVisibility(LazyResponseXXX):
code = 403
def msg(self, _):
tippee, visibility = self.args
return _(
"{username} no longer accepts secret donations.", username=tippee.username,
) if visibility == 1 else _(
"{username} no longer accepts private donations.", username=tippee.username,
) if visibility == 2 else _(
"{username} no longer accepts public donations.", username=tippee.username,
)


class UnexpectedCurrency(LazyResponse400):

def __init__(self, unexpected_amount, expected_currency):
Expand Down
8 changes: 8 additions & 0 deletions liberapay/models/participant.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
TooManyRequests,
TooManyUsernameChanges,
UnableToSendEmail,
UnacceptedDonationVisibility,
UnexpectedCurrency,
UsernameAlreadyTaken,
UsernameBeginsWithRestrictedCharacter,
Expand Down Expand Up @@ -2507,6 +2508,8 @@ def set_tip_to(self, tippee, periodic_amount, period='weekly', renewal_mode=None
raise BadAmount(periodic_amount, period, limits)
if amount.currency not in tippee.accepted_currencies_set:
raise BadDonationCurrency(tippee, amount.currency)
if visibility and not tippee.accepts_tip_visibility(visibility):
raise UnacceptedDonationVisibility(tippee, visibility)

# Insert tip
t = self.db.one("""\
Expand Down Expand Up @@ -2616,6 +2619,11 @@ def hide_tip_to(self, tippee_id, hide=True):
""", dict(tipper=self.id, tippee=tippee_id, hide=hide))


def accepts_tip_visibility(self, visibility):
bit = 2 ** (visibility - 1)
return self.recipient_settings.patron_visibilities & bit > 0


@cached_property
def donor_category(self):
if self.is_suspended is False:
Expand Down
34 changes: 34 additions & 0 deletions sql/branch.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
SELECT 'after deployment';
BEGIN;
CREATE TEMPORARY TABLE _tippees ON COMMIT DROP AS (
SELECT e.participant AS id
, (CASE WHEN e.payload->>'patron_visibilities' = '2' THEN 2 ELSE 3 END) AS only_accepted_visibility
, e.ts AS start_time
, coalesce((
SELECT e2.ts
FROM events e2
WHERE e2.participant = e.participant
AND e2.type = 'recipient_settings'
AND e2.ts > e.ts
ORDER BY e2.ts
LIMIT 1
), current_timestamp) AS end_time
FROM events e
WHERE e.type = 'recipient_settings'
AND e.payload->>'patron_visibilities' IN ('2', '4')
);
UPDATE tips AS tip
SET visibility = tippee.only_accepted_visibility
FROM _tippees AS tippee
WHERE tip.tippee = tippee.id
AND tip.mtime > tippee.start_time
AND tip.mtime < tippee.end_time
AND tip.visibility <> tippee.only_accepted_visibility;
UPDATE payin_transfers AS pt
SET visibility = tippee.only_accepted_visibility
FROM _tippees AS tippee
WHERE pt.recipient = tippee.id
AND pt.ctime > tippee.start_time
AND pt.ctime < tippee.end_time
AND pt.visibility <> tippee.only_accepted_visibility;
ROLLBACK;
4 changes: 4 additions & 0 deletions templates/macros/your-tip.html
Original file line number Diff line number Diff line change
Expand Up @@ -235,16 +235,19 @@ <h5 class="list-group-item-heading">{{ _("Manual renewal") }}</h5>
% endif
% endif
% if patron_visibilities == 1
<input type="hidden" name="visibility" value="1" />
<p class="text-info">{{ icon('info-sign') }} {{ _(
"{username} has chosen not to see who their patrons are, so your donation will be secret.",
username=tippee_name
) }}</p>
% elif patron_visibilities == 2 or paypal_only and not patron_visibilities
<input type="hidden" name="visibility" value="2" />
<p class="text-info">{{ icon('info-sign') }} {{ _(
"This donation won't be secret, you will appear in {username}'s private list of patrons.",
username=tippee_name
) }}</p>
% elif patron_visibilities == 4
<input type="hidden" name="visibility" value="3" />
<p class="text-warning">{{ icon('info-sign') }} {{ _(
"{username} discloses who their patrons are, your donation will be public.",
username=tippee_name
Expand Down Expand Up @@ -299,6 +302,7 @@ <h5 class="list-group-item-heading">{{ _("Public donation") }}</h5>
% endif
</ul>
% else
<input type="hidden" name="visibility" value="1" />
<p class="text-muted">{{ icon('info-sign') }} {{ _(
"{username} hasn't yet specified whether they want to see who their patrons are, "
"so your donation will be secret.",
Expand Down
2 changes: 2 additions & 0 deletions tests/py/test_donating.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ def test_donation_form_v2(self):
creator = self.make_participant(
'creator', accepted_currencies=None, email='[email protected]',
)
creator.update_recipient_settings(patron_visibilities=7)
r = self.client.GET('/creator/donate?currency=KRW')
assert r.code == 200
assert ">Pledge<" in r.text
Expand Down Expand Up @@ -54,6 +55,7 @@ def test_donation_form_v2_does_not_overwrite_visibility(self):
creator = self.make_participant(
'creator', accepted_currencies=None, email='[email protected]',
)
creator.update_recipient_settings(patron_visibilities=7)
self.add_payment_account(creator, 'stripe')
donor = self.make_participant('donor')
donor.set_tip_to(creator, USD('10.00'), renewal_mode=1, visibility=3)
Expand Down
4 changes: 2 additions & 2 deletions tests/py/test_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ def test_enabling_and_disabling_non_secret_donations(self):
# Check that the donation form isn't proposing the visibility options
r = self.client.GET('/alice/donate')
assert r.code == 200
assert 'name="visibility"' not in r.text
assert 'name="visibility"' in r.text
assert 'Secret donation' not in r.text
assert 'Private donation' not in r.text
assert 'Public donation' not in r.text
Expand All @@ -221,7 +221,7 @@ def test_enabling_and_disabling_non_secret_donations(self):
assert alice.recipient_settings.patron_visibilities == 1
r = self.client.GET('/alice/donate')
assert r.code == 200
assert 'name="visibility"' not in r.text
assert 'name="visibility"' in r.text
assert 'Secret donation' not in r.text
assert 'Private donation' not in r.text
assert 'Public donation' not in r.text
Loading