mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-06-30 08:13:27 +02:00
updated some error handling, logging, and text of emails
This commit is contained in:
parent
82b097d2f6
commit
91aaa0ff3e
4 changed files with 52 additions and 26 deletions
|
@ -29,16 +29,21 @@ class Command(BaseCommand):
|
|||
)
|
||||
|
||||
def handle(self, **options):
|
||||
"""Delete existing TransitionDomains. Generate test ones."""
|
||||
"""Delete existing TransitionDomains. Generate test ones.
|
||||
expects options[emails]; emails will be assigned to transition
|
||||
domains at the time of creation"""
|
||||
|
||||
# split options[emails] into an array of test emails
|
||||
test_emails = options["emails"].split(",")
|
||||
|
||||
# setting up test data
|
||||
if len(test_emails) > 0:
|
||||
# set up test data
|
||||
self.delete_test_transition_domains()
|
||||
self.load_test_transition_domains(test_emails)
|
||||
else:
|
||||
logger.error("list of emails for testing is required")
|
||||
|
||||
def load_test_transition_domains(self, test_emails):
|
||||
def load_test_transition_domains(self, test_emails: list):
|
||||
"""Load test transition domains"""
|
||||
|
||||
# counter for test_emails index
|
||||
|
|
|
@ -42,7 +42,7 @@ class Command(BaseCommand):
|
|||
def handle(self, **options):
|
||||
"""Process the objects in TransitionDomain."""
|
||||
|
||||
logger.debug("checking domains and preparing emails")
|
||||
logger.info("checking domains and preparing emails")
|
||||
# Get all TransitionDomain objects
|
||||
self.transition_domains = TransitionDomain.objects.filter(
|
||||
email_sent=False,
|
||||
|
@ -51,15 +51,15 @@ class Command(BaseCommand):
|
|||
self.build_emails_to_send_array()
|
||||
|
||||
if options["send_emails"]:
|
||||
logger.debug("about to send emails")
|
||||
logger.info("about to send emails")
|
||||
self.send_emails()
|
||||
logger.debug("done sending emails")
|
||||
logger.info("done sending emails")
|
||||
|
||||
self.update_domains_as_sent()
|
||||
|
||||
logger.debug("done sending emails and updating transition_domains")
|
||||
logger.info("done sending emails and updating transition_domains")
|
||||
else:
|
||||
logger.debug("not sending emails")
|
||||
logger.info("not sending emails")
|
||||
|
||||
def build_emails_to_send_array(self):
|
||||
"""this method sends emails to distinct usernames"""
|
||||
|
@ -104,13 +104,16 @@ class Command(BaseCommand):
|
|||
f"error retrieving domain {transition_domain.domain_name}: {err}"
|
||||
)
|
||||
# if there are at least one more transition domains than errors,
|
||||
# then send one more
|
||||
# then append one more item
|
||||
if len(self.transition_domains) > len(self.domains_with_errors):
|
||||
self.emails_to_send.append(email_context)
|
||||
|
||||
def send_emails(self):
|
||||
if len(self.emails_to_send) > 0:
|
||||
for email_data in self.emails_to_send:
|
||||
self.send_email(email_data)
|
||||
else:
|
||||
logger.info("no emails to send")
|
||||
|
||||
def send_email(self, email_data):
|
||||
try:
|
||||
|
@ -122,8 +125,8 @@ class Command(BaseCommand):
|
|||
"domains": email_data["domains"],
|
||||
},
|
||||
)
|
||||
# if log level set to debug, success message is logged
|
||||
logger.debug(
|
||||
# success message is logged
|
||||
logger.info(
|
||||
f"email sent successfully to {email_data['email']} for "
|
||||
f"{[domain['name'] for domain in email_data['domains']]}"
|
||||
)
|
||||
|
|
|
@ -1,11 +1,29 @@
|
|||
You have been invited to manage {% if domains|length > 1 %}multiple domains{% else %}the domain {{ domains.0.name }}{% endif %} on get.gov,
|
||||
the registrar for .gov domain names.
|
||||
{% autoescape off %}{# In a text file, we don't want to have HTML entities escaped #}
|
||||
Hi.
|
||||
|
||||
You have been added as a manager on {% if domains|length > 1 %}multiple domains (listed below){% else %}{{ domains.0.name }}{% endif %}.
|
||||
|
||||
YOU NEED A LOGIN.GOV ACCOUNT
|
||||
You’ll need a Login.gov account to manage your .gov domain{% if domains|length > 1 %}s{% endif %}. Login.gov provides a simple and secure process for signing into many government services with one account. If you don’t already have one, follow these steps to create your Login.gov account <https://login.gov/help/get-started/create-your-account/>.
|
||||
|
||||
DOMAIN MANAGEMENT
|
||||
As a .gov domain manager you can add or update information about your domain{% if domains|length > 1 %}s{% endif %}. You’ll also serve as a contact for your .gov domain{% if domains|length > 1 %}s{% endif %}. Please keep your contact information updated. Learn more about domain management <https://get.gov/help/>.
|
||||
{% if domains|length > 1 %}
|
||||
To accept your invitation, go to each of the following urls:
|
||||
{% for domain in domains %}
|
||||
{{ domain.url }} (to manage {{ domain.name }})
|
||||
{% endfor %}
|
||||
{% else %}
|
||||
To accept your invitation, go to <{{ domains.0.url }}>.
|
||||
DOMAINS
|
||||
{% for domain in domains %} {{ domain.name }}
|
||||
{% endfor %}{% else %}
|
||||
{% endif %}
|
||||
You will need to log in with a Login.gov account using this email address.
|
||||
SOMETHING WRONG?
|
||||
If you’re not affiliated with {{ domain.name }} or think you received this message in error, contact the .gov team <https://get.gov/help/#contact-us>.
|
||||
|
||||
|
||||
THANK YOU
|
||||
|
||||
.Gov helps the public identify official, trusted information. Thank you for using a .gov domain.
|
||||
|
||||
----------------------------------------------------------------
|
||||
|
||||
The .gov team
|
||||
Contact us: <https://get.gov/contact/>
|
||||
Visit <https://get.gov>
|
||||
{% endautoescape %}
|
||||
|
|
|
@ -1 +1 @@
|
|||
You are invited to manage {% if domains|length > 1 %}multiple domains{% else %}{{ domains.0 }}{% endif %} on get.gov
|
||||
You've been added to a .gov domain
|
Loading…
Add table
Add a link
Reference in a new issue