Skip to content

Commit 5f86b73

Browse files
committed
Tweaked the email activation migration to not send email when there's no active email address; it's not meaningful as the best we can do then is simply to activate the draft-related address.
- Legacy-Id: 9171
1 parent e4a1340 commit 5f86b73

1 file changed

Lines changed: 39 additions & 25 deletions

File tree

ietf/person/migrations/0004_auto_20150308_0440.py

Lines changed: 39 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
# '%(inacive_email)s' is 18, so just formatting naturally should come out
1616
# pretty nicely in most cases.
1717

18+
1819
email_template = """
1920
Hi,
2021
@@ -23,13 +24,21 @@
2324
in the active draft %(draft_name)s, was set to inactive.
2425
2526
As a consequence of this, it would not be receiving notifications related to
26-
that draft. The notifications would instead have gone to <%(primary_email)s>.
27+
that draft, from the datatracker or through the draft aliases. The
28+
notifications and aliases would instead have used <%(primary_email)s>.
2729
2830
This most likely was not what you intended when you used <%(inactive_email)s>
29-
in the draft, so that address has now been set to active. However, if you
30-
have manually set the status for <%(inactive_email)s> to inactive, we
31-
apologize for interfering and now having to ask you to go and set it to
32-
inactive again, at https://datatracker.ietf.org/accounts/profile/ .
31+
in the draft, so that address has now been set to active. The datatracker and
32+
draft aliases will now use it.
33+
34+
If you have a datatracker account, and had manually set the status for
35+
<%(inactive_email)s> to inactive, we apologize for interfering. Please set it
36+
to inactive again, by using https://datatracker.ietf.org/accounts/profile/. We
37+
don't anticipate changing it automatically again.
38+
39+
If you don't have a datatracker account, then all should be good -- we've
40+
simply set things to be the way they were expected to be.
41+
3342
3443
Best regards,
3544
@@ -39,41 +48,46 @@
3948

4049
def activate_draft_email(apps, schema_editor):
4150
Document = apps.get_model("doc", "Document")
42-
print("Setting email addresses to active ...")
43-
count = 0
44-
for doc in Document.objects.filter(type__slug='draft', states__slug='active'):
51+
print("\nSetting email addresses to active ...")
52+
change_count = 0
53+
notify_user_count = 0
54+
for doc in Document.objects.filter(type__slug='draft', states__slug='active').order_by('-time'):
4555
for email in doc.authors.all():
4656
if email.active == False:
47-
primary = email.person.email_set.filter(active=True).order_by('-time').first()
57+
person = email.person
58+
primary = person.email_set.filter(active=True).order_by('-time').first()
4859
email.active = True
4960
email.save()
50-
count += 1
61+
change_count += 1
5162
# If there isn't a primary address, ther's no active
5263
# addresses, and it can't be other than right to change the
5364
# draft email address to active. Otherwise, notify the owner.
54-
if primary and settings.SERVER_MODE == 'production':
65+
if primary:
66+
notify_user_count +=1
5567
primary_email = primary.address
5668
inactive_email = email.address
57-
context = dict(
58-
primary_email=primary_email,
59-
inactive_email=inactive_email,
60-
draft_name=doc.name,
69+
if settings.SERVER_MODE == 'production':
70+
context = dict(
71+
primary_email=primary_email,
72+
inactive_email=inactive_email,
73+
draft_name=doc.name,
74+
)
75+
send_mail_text(
76+
request=None,
77+
to=[ primary_email, inactive_email ],
78+
frm="Henrik Levkowetz <henrik@levkowetz.com>",
79+
subject="Changed email settings for you in the datatracker",
80+
txt= email_template % context,
81+
extra={"Reply-To": "Secretariat <ietf-action@ietf.org>"},
6182
)
62-
send_mail_text(
63-
request=None,
64-
to=[ primary_email, inactive_email ],
65-
frm="Henrik Levkowetz <henrik@levkowetz.com>",
66-
subject="Changed email settings for you in the datatracker",
67-
txt= email_template % context,
68-
extra={"Reply-To": "Secretariat <ietf-action@ietf.org>"},
69-
)
70-
print("Set %s email addresses to active" % count)
83+
print("Set %s email addresses to active" % change_count)
84+
print("Notified %s users, who had at least one other active email." % notify_user_count)
7185

7286
def deactivate_draft_email(apps, scema_editor):
7387
"""
7488
The backwards migration doesn't touch the active field of any email addresses.
7589
We don't have the information to exactly undo what the forward migration did,
76-
and on 08 Mar 2015, there were 1931 inactive email addresses coupled to active
90+
and on 08 Mar 2015, there were 1178 inactive email addresses coupled to active
7791
drafts, and 4237 active addresses coupled to active drafts. The harm would
7892
be substantial if those active addresses were set to inactive.
7993
"""

0 commit comments

Comments
 (0)