Skip to content

Commit fbd6aa7

Browse files
committed
Default to sending emails for patches where you are the author
This only applies to new users or users that never clicked the profile button.
1 parent 8f8b416 commit fbd6aa7

File tree

6 files changed

+45
-19
lines changed

6 files changed

+45
-19
lines changed

pgcommitfest/commitfest/models.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -202,11 +202,13 @@ def send_closure_notifications(self):
202202
# Send email to each author who has notifications enabled
203203
for author, patches in authors_patches.items():
204204
try:
205-
if not author.userprofile.notify_all_author:
205+
profile = author.userprofile
206+
if not profile.notify_all_author:
206207
continue
207-
notifyemail = author.userprofile.notifyemail
208+
notifyemail = profile.notifyemail
208209
except UserProfile.DoesNotExist:
209-
continue
210+
# No profile means use default (notify=True), so continue
211+
notifyemail = None
210212

211213
email = notifyemail.email if notifyemail else author.email
212214

@@ -813,9 +815,12 @@ def save_and_notify(
813815
)
814816
)
815817

816-
# Current or previous authors wants all notifications
818+
# Current or previous authors wants all notifications (default is True,
819+
# so include users without a profile)
817820
recipients.extend(
818-
self.patch.authors.filter(userprofile__notify_all_author=True)
821+
self.patch.authors.filter(
822+
Q(userprofile__isnull=True) | Q(userprofile__notify_all_author=True)
823+
)
819824
)
820825

821826
for u in set(recipients):

pgcommitfest/commitfest/templates/mail/commitfest_closure.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,8 @@ Please take action on {{patches|length|pluralize:"these patches,this patch"}} by
1212
1. If you want to continue working on {{patches|length|pluralize:"them,it"}}, move {{patches|length|pluralize:"them,it"}} to the next commitfest.
1313

1414
2. If you no longer wish to pursue {{patches|length|pluralize:"these patches,this patch"}}, please close {{patches|length|pluralize:"them,it"}} with an appropriate status (Withdrawn, Returned with feedback, etc.)
15+
16+
--
17+
This is an automated message from the PostgreSQL Commitfest app.
18+
To manage your notification preferences, visit:
19+
https://commitfest.postgresql.org/userprofile/

pgcommitfest/commitfest/templates/mail/patch_notify.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,7 @@ https://commitfest.postgresql.org/patch/{{p.patch.id}}/
99

1010

1111
{%endfor%}
12+
--
13+
This is an automated message from the PostgreSQL Commitfest app.
14+
To manage your notification preferences, visit:
15+
https://commitfest.postgresql.org/userprofile/

pgcommitfest/commitfest/tests/conftest.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@
1212

1313
@pytest.fixture
1414
def alice():
15-
"""Create test user Alice with notify_all_author enabled."""
15+
"""Create test user Alice with a profile (uses default notify_all_author=True)."""
1616
user = User.objects.create_user(
1717
username="alice",
1818
first_name="Alice",
1919
last_name="Anderson",
2020
email="alice@example.com",
2121
)
22-
UserProfile.objects.create(user=user, notify_all_author=True)
22+
UserProfile.objects.create(user=user)
2323
return user
2424

2525

pgcommitfest/commitfest/tests/test_closure_notifications.py

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,7 @@ def test_one_email_per_author_with_multiple_patches(alice, in_progress_cf):
119119

120120

121121
def test_multiple_authors_receive_separate_emails(alice, bob, in_progress_cf):
122-
"""Each author of open patches should receive their own notification (if opted in)."""
123-
# Bob also needs notify_all_author enabled to receive closure emails
124-
UserProfile.objects.create(user=bob, notify_all_author=True)
125-
122+
"""Each author of open patches should receive their own notification."""
126123
patch1 = Patch.objects.create(name="Alice Patch")
127124
patch1.authors.add(alice)
128125
PatchOnCommitFest.objects.create(
@@ -149,10 +146,7 @@ def test_multiple_authors_receive_separate_emails(alice, bob, in_progress_cf):
149146

150147

151148
def test_coauthors_both_receive_notification(alice, bob, in_progress_cf):
152-
"""Both co-authors of a patch should receive notifications (if opted in)."""
153-
# Bob also needs notify_all_author enabled to receive closure emails
154-
UserProfile.objects.create(user=bob, notify_all_author=True)
155-
149+
"""Both co-authors of a patch should receive notifications."""
156150
patch = Patch.objects.create(name="Coauthored Patch")
157151
patch.authors.add(alice)
158152
patch.authors.add(bob)
@@ -170,9 +164,9 @@ def test_coauthors_both_receive_notification(alice, bob, in_progress_cf):
170164
assert receivers == {alice.email, bob.email}
171165

172166

173-
def test_no_notification_for_author_without_notify_all_author(bob, in_progress_cf):
174-
"""Authors without notify_all_author enabled should not receive closure notifications."""
175-
# bob has no UserProfile, so notify_all_author is not enabled
167+
def test_no_notification_for_author_who_opted_out(bob, in_progress_cf):
168+
"""Authors who explicitly opted out should not receive closure notifications."""
169+
UserProfile.objects.create(user=bob, notify_all_author=False)
176170
patch = Patch.objects.create(name="Test Patch")
177171
patch.authors.add(bob)
178172
PatchOnCommitFest.objects.create(
@@ -187,6 +181,24 @@ def test_no_notification_for_author_without_notify_all_author(bob, in_progress_c
187181
assert QueuedMail.objects.count() == 0
188182

189183

184+
def test_notification_for_author_without_profile(bob, in_progress_cf):
185+
"""Authors without a UserProfile should receive notifications (opt-out default)."""
186+
patch = Patch.objects.create(name="Test Patch")
187+
patch.authors.add(bob)
188+
PatchOnCommitFest.objects.create(
189+
patch=patch,
190+
commitfest=in_progress_cf,
191+
enterdate=datetime.now(),
192+
status=PatchOnCommitFest.STATUS_REVIEW,
193+
)
194+
195+
in_progress_cf.send_closure_notifications()
196+
197+
assert QueuedMail.objects.count() == 1
198+
mail = QueuedMail.objects.first()
199+
assert mail.receiver == bob.email
200+
201+
190202
# Auto-move tests
191203

192204

pgcommitfest/userprofile/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class UserProfile(models.Model):
3636
notify_all_author = models.BooleanField(
3737
null=False,
3838
blank=False,
39-
default=False,
39+
default=True,
4040
verbose_name="Notify on all where author",
4141
)
4242
notify_all_reviewer = models.BooleanField(

0 commit comments

Comments
 (0)