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
This commit is contained in:
Henrik Levkowetz 2015-03-10 20:13:49 +00:00
parent e4a1340974
commit 5f86b73d0e

View file

@ -15,6 +15,7 @@ from ietf.utils.mail import send_mail_text
# '%(inacive_email)s' is 18, so just formatting naturally should come out
# pretty nicely in most cases.
email_template = """
Hi,
@ -23,13 +24,21 @@ it has been found that your address <%(inactive_email)s>, which is mentioned
in the active draft %(draft_name)s, was set to inactive.
As a consequence of this, it would not be receiving notifications related to
that draft. The notifications would instead have gone to <%(primary_email)s>.
that draft, from the datatracker or through the draft aliases. The
notifications and aliases would instead have used <%(primary_email)s>.
This most likely was not what you intended when you used <%(inactive_email)s>
in the draft, so that address has now been set to active. However, if you
have manually set the status for <%(inactive_email)s> to inactive, we
apologize for interfering and now having to ask you to go and set it to
inactive again, at https://datatracker.ietf.org/accounts/profile/ .
in the draft, so that address has now been set to active. The datatracker and
draft aliases will now use it.
If you have a datatracker account, and had manually set the status for
<%(inactive_email)s> to inactive, we apologize for interfering. Please set it
to inactive again, by using https://datatracker.ietf.org/accounts/profile/. We
don't anticipate changing it automatically again.
If you don't have a datatracker account, then all should be good -- we've
simply set things to be the way they were expected to be.
Best regards,
@ -39,41 +48,46 @@ Best regards,
def activate_draft_email(apps, schema_editor):
Document = apps.get_model("doc", "Document")
print("Setting email addresses to active ...")
count = 0
for doc in Document.objects.filter(type__slug='draft', states__slug='active'):
print("\nSetting email addresses to active ...")
change_count = 0
notify_user_count = 0
for doc in Document.objects.filter(type__slug='draft', states__slug='active').order_by('-time'):
for email in doc.authors.all():
if email.active == False:
primary = email.person.email_set.filter(active=True).order_by('-time').first()
person = email.person
primary = person.email_set.filter(active=True).order_by('-time').first()
email.active = True
email.save()
count += 1
change_count += 1
# If there isn't a primary address, ther's no active
# addresses, and it can't be other than right to change the
# draft email address to active. Otherwise, notify the owner.
if primary and settings.SERVER_MODE == 'production':
if primary:
notify_user_count +=1
primary_email = primary.address
inactive_email = email.address
context = dict(
primary_email=primary_email,
inactive_email=inactive_email,
draft_name=doc.name,
if settings.SERVER_MODE == 'production':
context = dict(
primary_email=primary_email,
inactive_email=inactive_email,
draft_name=doc.name,
)
send_mail_text(
request=None,
to=[ primary_email, inactive_email ],
frm="Henrik Levkowetz <henrik@levkowetz.com>",
subject="Changed email settings for you in the datatracker",
txt= email_template % context,
extra={"Reply-To": "Secretariat <ietf-action@ietf.org>"},
)
send_mail_text(
request=None,
to=[ primary_email, inactive_email ],
frm="Henrik Levkowetz <henrik@levkowetz.com>",
subject="Changed email settings for you in the datatracker",
txt= email_template % context,
extra={"Reply-To": "Secretariat <ietf-action@ietf.org>"},
)
print("Set %s email addresses to active" % count)
print("Set %s email addresses to active" % change_count)
print("Notified %s users, who had at least one other active email." % notify_user_count)
def deactivate_draft_email(apps, scema_editor):
"""
The backwards migration doesn't touch the active field of any email addresses.
We don't have the information to exactly undo what the forward migration did,
and on 08 Mar 2015, there were 1931 inactive email addresses coupled to active
and on 08 Mar 2015, there were 1178 inactive email addresses coupled to active
drafts, and 4237 active addresses coupled to active drafts. The harm would
be substantial if those active addresses were set to inactive.
"""