-
-
Notifications
You must be signed in to change notification settings - Fork 215
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
Pause donations option for Goal #1999
Closed
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{{ _("Liberapay donation paused") }} | ||
|
||
[---] text/html | ||
<p>{{ _("{0} has temporarily paused your donations to them.", recipient) }}</p> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{{ _("Liberapay donation resumed") }} | ||
|
||
[---] text/html | ||
<p>{{ _("{0} has resumed your donations to them.", recipient) }}</p> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
from liberapay.testing import EUR, Harness | ||
|
||
from liberapay.testing.emails import EmailHarness | ||
|
||
class Tests(Harness): | ||
|
||
|
@@ -62,3 +62,35 @@ def test_team_member_can_change_team_goal(self): | |
) | ||
assert r.code == 302 | ||
assert team.refetch().goal == EUR('99.99') | ||
|
||
class TestPauseDonations(EmailHarness): | ||
def setUp(self): | ||
EmailHarness.setUp(self) | ||
self.alice = self.make_participant('alice', email='[email protected]') | ||
|
||
def change_goal(self, goal, goal_custom="", auth_as="alice", expect_success=False): | ||
r = self.client.PxST( | ||
"/alice/edit/goal", | ||
{'goal': goal, 'goal_custom': goal_custom}, | ||
auth_as=self.alice if auth_as == 'alice' else auth_as | ||
) | ||
if expect_success and r.code >= 400: | ||
raise r | ||
return r | ||
|
||
def test_pause(self): | ||
bob = self.make_participant('bob', email='[email protected]') | ||
bob.set_tip_to(self.alice, EUR('0.99'), renewal_mode=2) | ||
self.change_goal("-2", expect_success=True) | ||
|
||
assert self.mailer.call_count == 1 | ||
last_email = self.get_last_email() | ||
assert last_email['to'][0] == 'bob <[email protected]>' | ||
assert "paused" in last_email['text'] | ||
|
||
self.change_goal("null", "", expect_success=True) | ||
|
||
assert self.mailer.call_count == 2 | ||
last_email = self.get_last_email() | ||
assert last_email['to'][0] == 'bob <[email protected]>' | ||
assert "resume" in last_email['text'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can't send a potentially large number of emails while processing a user request. Firstly because the request will time out, secondly because it can allow an attacker to flood users with duplicate emails, and thirdly because the user should be able to reverse their decision before the emails are sent.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this be accomplished by using Participant's notify() method? Also when I switched to using notify(), the request seemed to get stuck. Do you know why this might be happening?
also for the last point
If a decision is reversed, what should occur? Do the emails that were queued to send get dequeued?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
notify
method should be used, but in a separate function which would be either a payday method or a cron job, likesend_donation_reminder_notifications
orsend_account_disabled_notifications
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
update_goal
runs in a database transaction (which is confusingly called a "cursor" for legacy reasons), butnotify
doesn't, so if you tried to callnotify
from inside thewith
block you could have created a "deadlock" (two database workers trying to modify the same row, each one waiting for the other to complete its transaction before continuing).No. Once the email is queued for sending we don't cancel it. What we do instead is delay the creation of the notification which results in the email being queued for sending. Donors don't need to be notified immediately that donations have been paused, this kind of information can be delayed for an hour or even a week.