diff --git a/ops/manifests/manifest-ab.yaml b/ops/manifests/manifest-ab.yaml index fb8b02b03..f3dd170e6 100644 --- a/ops/manifests/manifest-ab.yaml +++ b/ops/manifests/manifest-ab.yaml @@ -11,6 +11,7 @@ applications: command: ./run.sh health-check-type: http health-check-http-endpoint: /health + health-check-invocation-timeout: 40 env: # Send stdout and stderr straight to the terminal without buffering PYTHONUNBUFFERED: yup diff --git a/ops/manifests/manifest-bl.yaml b/ops/manifests/manifest-bl.yaml index bff347709..3a494aa25 100644 --- a/ops/manifests/manifest-bl.yaml +++ b/ops/manifests/manifest-bl.yaml @@ -11,6 +11,7 @@ applications: command: ./run.sh health-check-type: http health-check-http-endpoint: /health + health-check-invocation-timeout: 40 env: # Send stdout and stderr straight to the terminal without buffering PYTHONUNBUFFERED: yup diff --git a/ops/manifests/manifest-dk.yaml b/ops/manifests/manifest-dk.yaml index 249eab119..61036b739 100644 --- a/ops/manifests/manifest-dk.yaml +++ b/ops/manifests/manifest-dk.yaml @@ -11,6 +11,7 @@ applications: command: ./run.sh health-check-type: http health-check-http-endpoint: /health + health-check-invocation-timeout: 40 env: # Send stdout and stderr straight to the terminal without buffering PYTHONUNBUFFERED: yup diff --git a/ops/manifests/manifest-gd.yaml b/ops/manifests/manifest-gd.yaml index f11758858..bb07e78ec 100644 --- a/ops/manifests/manifest-gd.yaml +++ b/ops/manifests/manifest-gd.yaml @@ -11,6 +11,7 @@ applications: command: ./run.sh health-check-type: http health-check-http-endpoint: /health + health-check-invocation-timeout: 40 env: # Send stdout and stderr straight to the terminal without buffering PYTHONUNBUFFERED: yup diff --git a/ops/manifests/manifest-ko.yaml b/ops/manifests/manifest-ko.yaml index 09e199ca0..7681d9527 100644 --- a/ops/manifests/manifest-ko.yaml +++ b/ops/manifests/manifest-ko.yaml @@ -11,6 +11,7 @@ applications: command: ./run.sh health-check-type: http health-check-http-endpoint: /health + health-check-invocation-timeout: 40 env: # Send stdout and stderr straight to the terminal without buffering PYTHONUNBUFFERED: yup diff --git a/ops/manifests/manifest-nl.yaml b/ops/manifests/manifest-nl.yaml index dcdb02794..6c848db78 100644 --- a/ops/manifests/manifest-nl.yaml +++ b/ops/manifests/manifest-nl.yaml @@ -11,6 +11,7 @@ applications: command: ./run.sh health-check-type: http health-check-http-endpoint: /health + health-check-invocation-timeout: 40 env: # Send stdout and stderr straight to the terminal without buffering PYTHONUNBUFFERED: yup diff --git a/ops/manifests/manifest-rb.yaml b/ops/manifests/manifest-rb.yaml index b228980e0..c51230eb4 100644 --- a/ops/manifests/manifest-rb.yaml +++ b/ops/manifests/manifest-rb.yaml @@ -11,6 +11,7 @@ applications: command: ./run.sh health-check-type: http health-check-http-endpoint: /health + health-check-invocation-timeout: 40 env: # Send stdout and stderr straight to the terminal without buffering PYTHONUNBUFFERED: yup diff --git a/ops/manifests/manifest-rh.yaml b/ops/manifests/manifest-rh.yaml index d8bf4cb77..ac88a8031 100644 --- a/ops/manifests/manifest-rh.yaml +++ b/ops/manifests/manifest-rh.yaml @@ -11,6 +11,7 @@ applications: command: ./run.sh health-check-type: http health-check-http-endpoint: /health + health-check-invocation-timeout: 40 env: # Send stdout and stderr straight to the terminal without buffering PYTHONUNBUFFERED: yup diff --git a/ops/manifests/manifest-rjm.yaml b/ops/manifests/manifest-rjm.yaml index 1942414ef..45a12f363 100644 --- a/ops/manifests/manifest-rjm.yaml +++ b/ops/manifests/manifest-rjm.yaml @@ -11,6 +11,7 @@ applications: command: ./run.sh health-check-type: http health-check-http-endpoint: /health + health-check-invocation-timeout: 40 env: # Send stdout and stderr straight to the terminal without buffering PYTHONUNBUFFERED: yup diff --git a/ops/manifests/manifest-stable.yaml b/ops/manifests/manifest-stable.yaml index 7cfa1417d..bc5e933f6 100644 --- a/ops/manifests/manifest-stable.yaml +++ b/ops/manifests/manifest-stable.yaml @@ -11,6 +11,7 @@ applications: command: ./run.sh health-check-type: http health-check-http-endpoint: /health + health-check-invocation-timeout: 40 env: # Send stdout and stderr straight to the terminal without buffering PYTHONUNBUFFERED: yup diff --git a/ops/manifests/manifest-staging.yaml b/ops/manifests/manifest-staging.yaml index 93c44071c..3e80352ba 100644 --- a/ops/manifests/manifest-staging.yaml +++ b/ops/manifests/manifest-staging.yaml @@ -11,6 +11,7 @@ applications: command: ./run.sh health-check-type: http health-check-http-endpoint: /health + health-check-invocation-timeout: 40 env: # Send stdout and stderr straight to the terminal without buffering PYTHONUNBUFFERED: yup diff --git a/ops/manifests/manifest-za.yaml b/ops/manifests/manifest-za.yaml index fbacb6912..23b6179ec 100644 --- a/ops/manifests/manifest-za.yaml +++ b/ops/manifests/manifest-za.yaml @@ -11,6 +11,7 @@ applications: command: ./run.sh health-check-type: http health-check-http-endpoint: /health + health-check-invocation-timeout: 40 env: # Send stdout and stderr straight to the terminal without buffering PYTHONUNBUFFERED: yup diff --git a/ops/scripts/manifest-sandbox-template-migrate.yaml b/ops/scripts/manifest-sandbox-template-migrate.yaml index 8789effa5..dfebed766 100644 --- a/ops/scripts/manifest-sandbox-template-migrate.yaml +++ b/ops/scripts/manifest-sandbox-template-migrate.yaml @@ -11,6 +11,7 @@ applications: command: ./run.sh health-check-type: http health-check-http-endpoint: /health + health-check-invocation-timeout: 40 env: # Send stdout and stderr straight to the terminal without buffering PYTHONUNBUFFERED: yup diff --git a/ops/scripts/manifest-sandbox-template.yaml b/ops/scripts/manifest-sandbox-template.yaml index 1bf979c9f..3acbb910c 100644 --- a/ops/scripts/manifest-sandbox-template.yaml +++ b/ops/scripts/manifest-sandbox-template.yaml @@ -11,6 +11,7 @@ applications: command: ./run.sh health-check-type: http health-check-http-endpoint: /health + health-check-invocation-timeout: 40 env: # Send stdout and stderr straight to the terminal without buffering PYTHONUNBUFFERED: yup diff --git a/src/epplibwrapper/__init__.py b/src/epplibwrapper/__init__.py index 1997b422e..27c299d1b 100644 --- a/src/epplibwrapper/__init__.py +++ b/src/epplibwrapper/__init__.py @@ -45,6 +45,7 @@ try: from .client import CLIENT, commands from .errors import RegistryError, ErrorCode from epplib.models import common, info + from epplib import responses except ImportError: pass @@ -52,6 +53,7 @@ __all__ = [ "CLIENT", "commands", "common", + "responses", "info", "ErrorCode", "RegistryError", diff --git a/src/epplibwrapper/errors.py b/src/epplibwrapper/errors.py index 7e45633a7..d34ed5e91 100644 --- a/src/epplibwrapper/errors.py +++ b/src/epplibwrapper/errors.py @@ -67,6 +67,13 @@ class RegistryError(Exception): def should_retry(self): return self.code == ErrorCode.COMMAND_FAILED + # connection errors have error code of None and [Errno 99] in the err message + def is_connection_error(self): + return self.code is None + + def is_session_error(self): + return self.code is not None and (self.code >= 2501 and self.code <= 2502) + def is_server_error(self): return self.code is not None and (self.code >= 2400 and self.code <= 2500) diff --git a/src/registrar/admin.py b/src/registrar/admin.py index d78947c85..e99e767bd 100644 --- a/src/registrar/admin.py +++ b/src/registrar/admin.py @@ -639,6 +639,21 @@ class DomainApplicationAdmin(ListHeaderAdmin): return super().change_view(request, object_id, form_url, extra_context) +class TransitionDomainAdmin(ListHeaderAdmin): + """Custom transition domain admin class.""" + + # Columns + list_display = [ + "username", + "domain_name", + "status", + "email_sent", + ] + + search_fields = ["username", "domain_name"] + search_help_text = "Search by user or domain name." + + class DomainInformationInline(admin.StackedInline): """Edit a domain information on the domain page. We had issues inheriting from both StackedInline @@ -730,7 +745,23 @@ class DomainAdmin(ListHeaderAdmin): obj.place_client_hold() obj.save() except Exception as err: - self.message_user(request, err, messages.ERROR) + # if error is an error from the registry, display useful + # and readable error + if err.code: + self.message_user( + request, + f"Error placing the hold with the registry: {err}", + messages.ERROR, + ) + elif err.is_connection_error(): + self.message_user( + request, + "Error connecting to the registry", + messages.ERROR, + ) + else: + # all other type error messages, display the error + self.message_user(request, err, messages.ERROR) else: self.message_user( request, @@ -747,7 +778,23 @@ class DomainAdmin(ListHeaderAdmin): obj.revert_client_hold() obj.save() except Exception as err: - self.message_user(request, err, messages.ERROR) + # if error is an error from the registry, display useful + # and readable error + if err.code: + self.message_user( + request, + f"Error removing the hold in the registry: {err}", + messages.ERROR, + ) + elif err.is_connection_error(): + self.message_user( + request, + "Error connecting to the registry", + messages.ERROR, + ) + else: + # all other type error messages, display the error + self.message_user(request, err, messages.ERROR) else: self.message_user( request, @@ -801,4 +848,4 @@ admin.site.register(models.Nameserver, MyHostAdmin) admin.site.register(models.Website, WebsiteAdmin) admin.site.register(models.PublicContact, AuditedAdmin) admin.site.register(models.DomainApplication, DomainApplicationAdmin) -admin.site.register(models.TransitionDomain, AuditedAdmin) +admin.site.register(models.TransitionDomain, TransitionDomainAdmin) diff --git a/src/registrar/assets/sass/_theme/_uswds-theme-custom-styles.scss b/src/registrar/assets/sass/_theme/_uswds-theme-custom-styles.scss index 4878235a9..e69b36bb8 100644 --- a/src/registrar/assets/sass/_theme/_uswds-theme-custom-styles.scss +++ b/src/registrar/assets/sass/_theme/_uswds-theme-custom-styles.scss @@ -399,6 +399,11 @@ a.usa-button--unstyled:visited { border-color: color('accent-cool-lighter'); } +.dotgov-status-box--action-need { + background-color: color('warning-lighter'); + border-color: color('warning'); +} + #wrapper { padding-top: units(3); padding-bottom: units(6) * 2 ; //Workaround because USWDS units jump from 10 to 15 diff --git a/src/registrar/management/commands/generate_test_transition_domains.py b/src/registrar/management/commands/generate_test_transition_domains.py new file mode 100644 index 000000000..20aba2c58 --- /dev/null +++ b/src/registrar/management/commands/generate_test_transition_domains.py @@ -0,0 +1,65 @@ +"""Data migration: Generate fake transition domains, replacing existing ones.""" + +import logging + +from django.core.management import BaseCommand +from registrar.models import TransitionDomain, Domain + +logger = logging.getLogger(__name__) + + +class Command(BaseCommand): + help = "Generate test transition domains from existing domains" + + # Generates test transition domains for testing send_domain_invitations script. + # Running this script removes all existing transition domains, so use with caution. + # Transition domains are created with email addresses provided as command line + # argument. Email addresses for testing are passed as comma delimited list of + # email addresses, and are required to be provided. Email addresses from the list + # are assigned to transition domains at time of creation. + + def add_arguments(self, parser): + """Add command line arguments.""" + parser.add_argument( + "-e", + "--emails", + required=True, + dest="emails", + help="Comma-delimited list of email addresses to be used for testing", + ) + + def handle(self, **options): + """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(",") + + 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: list): + """Load test transition domains""" + + # counter for test_emails index + test_emails_counter = 0 + # Need to get actual domain names from the database for this test + real_domains = Domain.objects.all() + for real_domain in real_domains: + TransitionDomain.objects.create( + username=test_emails[test_emails_counter % len(test_emails)], + domain_name=real_domain.name, + status="created", + email_sent=False, + ) + test_emails_counter += 1 + + def delete_test_transition_domains(self): + self.transition_domains = TransitionDomain.objects.all() + for transition_domain in self.transition_domains: + transition_domain.delete() diff --git a/src/registrar/management/commands/send_domain_invitations.py b/src/registrar/management/commands/send_domain_invitations.py new file mode 100644 index 000000000..994013254 --- /dev/null +++ b/src/registrar/management/commands/send_domain_invitations.py @@ -0,0 +1,142 @@ +"""Data migration: Send domain invitations once to existing customers.""" + +import logging +import copy + +from django.core.management import BaseCommand +from registrar.models import TransitionDomain +from ...utility.email import send_templated_email, EmailSendingError +from typing import List + +logger = logging.getLogger(__name__) + + +class Command(BaseCommand): + help = "Send domain invitations once to existing customers." + + # this array is used to store and process the transition_domains + transition_domains: List[str] = [] + # this array is used to store domains with errors, which are not + # sent emails; this array is used to update the succesful + # transition_domains to email_sent=True, and also to report + # out errors + domains_with_errors: List[str] = [] + # this array is used to store email_context; each item in the array + # contains the context for a single email; single emails may be 1 + # or more transition_domains, as they are grouped by username + emails_to_send: List[str] = [] + + def add_arguments(self, parser): + """Add command line arguments.""" + parser.add_argument( + "-s", + "--send_emails", + action="store_true", + default=False, + dest="send_emails", + help="Send emails ", + ) + + def handle(self, **options): + """Process the objects in TransitionDomain.""" + + logger.info("checking domains and preparing emails") + # Get all TransitionDomain objects + self.transition_domains = TransitionDomain.objects.filter( + email_sent=False, + ).order_by("username") + + self.build_emails_to_send_array() + + if options["send_emails"]: + logger.info("about to send emails") + self.send_emails() + logger.info("done sending emails") + + self.update_domains_as_sent() + + logger.info("done sending emails and updating transition_domains") + else: + logger.info("not sending emails") + + def build_emails_to_send_array(self): + """this method sends emails to distinct usernames""" + + # data structure to hold email context for a single email; + # transition_domains ordered by username, a single email_context + # may include information from more than one transition_domain + email_context = {"email": ""} + + # loop through all transition_domains; group them by username + # into emails_to_send_array + for transition_domain in self.transition_domains: + # attempt to get the domain from domain objects; if there is + # an error getting the domain, skip this domain and add it to + # domains_with_errors + try: + # if prior username does not match current username + if ( + not email_context["email"] + or email_context["email"] != transition_domain.username + ): + # if not first in list of transition_domains + if email_context["email"]: + # append the email context to the emails_to_send array + self.emails_to_send.append(copy.deepcopy(email_context)) + email_context["domains"] = [] + email_context["email"] = transition_domain.username + email_context["domains"].append(transition_domain.domain_name) + except Exception as err: + # error condition if domain not in database + self.domains_with_errors.append( + copy.deepcopy(transition_domain.domain_name) + ) + logger.error( + f"error retrieving domain {transition_domain.domain_name}: {err}" + ) + # if there are at least one more transition domains than errors, + # 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: + send_templated_email( + "emails/transition_domain_invitation.txt", + "emails/transition_domain_invitation_subject.txt", + to_address=email_data["email"], + context={ + "domains": email_data["domains"], + }, + ) + # success message is logged + logger.info( + f"email sent successfully to {email_data['email']} for " + f"{[domain for domain in email_data['domains']]}" + ) + except EmailSendingError as err: + logger.error( + f"email did not send successfully to {email_data['email']} " + f"for {[domain for domain in email_data['domains']]}" + f": {err}" + ) + # if email failed to send, set error in domains_with_errors for each + # domain in the email so that transition domain email_sent is not set + # to True + for domain in email_data["domains"]: + self.domains_with_errors.append(domain) + + def update_domains_as_sent(self): + """set email_sent to True in all transition_domains which have + been processed successfully""" + for transition_domain in self.transition_domains: + if transition_domain.domain_name not in self.domains_with_errors: + transition_domain.email_sent = True + transition_domain.save() diff --git a/src/registrar/migrations/0032_alter_transitiondomain_status.py b/src/registrar/migrations/0032_alter_transitiondomain_status.py new file mode 100644 index 000000000..4f3a06712 --- /dev/null +++ b/src/registrar/migrations/0032_alter_transitiondomain_status.py @@ -0,0 +1,24 @@ +# Generated by Django 4.2.1 on 2023-09-27 00:18 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + dependencies = [ + ("registrar", "0031_transitiondomain_and_more"), + ] + + operations = [ + migrations.AlterField( + model_name="transitiondomain", + name="status", + field=models.CharField( + blank=True, + choices=[("ready", "Ready"), ("hold", "Hold")], + default="ready", + help_text="domain status during the transfer", + max_length=255, + verbose_name="Status", + ), + ), + ] diff --git a/src/registrar/models/domain.py b/src/registrar/models/domain.py index bf255aca5..0295b794f 100644 --- a/src/registrar/models/domain.py +++ b/src/registrar/models/domain.py @@ -617,13 +617,25 @@ class Domain(TimeStampedModel, DomainHelper): """This domain should not be active. may raises RegistryError, should be caught or handled correctly by caller""" request = commands.UpdateDomain(name=self.name, add=[self.clientHoldStatus()]) - registry.send(request, cleaned=True) + try: + registry.send(request, cleaned=True) + self._invalidate_cache() + except RegistryError as err: + # if registry error occurs, log the error, and raise it as well + logger.error(f"registry error placing client hold: {err}") + raise (err) def _remove_client_hold(self): """This domain is okay to be active. may raises RegistryError, should be caught or handled correctly by caller""" request = commands.UpdateDomain(name=self.name, rem=[self.clientHoldStatus()]) - registry.send(request, cleaned=True) + try: + registry.send(request, cleaned=True) + self._invalidate_cache() + except RegistryError as err: + # if registry error occurs, log the error, and raise it as well + logger.error(f"registry error removing client hold: {err}") + raise (err) def _delete_domain(self): """This domain should be deleted from the registry @@ -964,7 +976,9 @@ class Domain(TimeStampedModel, DomainHelper): administrative_contact = self.get_default_administrative_contact() administrative_contact.save() - @transition(field="state", source=State.READY, target=State.ON_HOLD) + @transition( + field="state", source=[State.READY, State.ON_HOLD], target=State.ON_HOLD + ) def place_client_hold(self): """place a clienthold on a domain (no longer should resolve)""" # TODO - ensure all requirements for client hold are made here @@ -973,7 +987,7 @@ class Domain(TimeStampedModel, DomainHelper): self._place_client_hold() # TODO -on the client hold ticket any additional error handling here - @transition(field="state", source=State.ON_HOLD, target=State.READY) + @transition(field="state", source=[State.READY, State.ON_HOLD], target=State.READY) def revert_client_hold(self): """undo a clienthold placed on a domain""" @@ -1145,9 +1159,14 @@ class Domain(TimeStampedModel, DomainHelper): if "statuses" in cleaned: cleaned["statuses"] = [status.state for status in cleaned["statuses"]] + # Capture and store old hosts and contacts from cache if they exist + old_cache_hosts = self._cache.get("hosts") + old_cache_contacts = self._cache.get("contacts") + + # get contact info, if there are any if ( - # fetch_contacts and - "_contacts" in cleaned + fetch_contacts + and "_contacts" in cleaned and isinstance(cleaned["_contacts"], list) and len(cleaned["_contacts"]) > 0 ): diff --git a/src/registrar/models/transition_domain.py b/src/registrar/models/transition_domain.py index 31da70704..203795925 100644 --- a/src/registrar/models/transition_domain.py +++ b/src/registrar/models/transition_domain.py @@ -3,15 +3,16 @@ from django.db import models from .utility.time_stamped_model import TimeStampedModel +class StatusChoices(models.TextChoices): + READY = "ready", "Ready" + HOLD = "hold", "Hold" + + class TransitionDomain(TimeStampedModel): """Transition Domain model stores information about the state of a domain upon transition between registry providers""" - class StatusChoices(models.TextChoices): - CREATED = "created", "Created" - HOLD = "hold", "Hold" - username = models.TextField( null=False, blank=False, @@ -27,6 +28,7 @@ class TransitionDomain(TimeStampedModel): max_length=255, null=False, blank=True, + default=StatusChoices.READY, choices=StatusChoices.choices, verbose_name="Status", help_text="domain status during the transfer", @@ -39,4 +41,9 @@ class TransitionDomain(TimeStampedModel): ) def __str__(self): - return self.username + return ( + f"username: {self.username} " + f"domainName: {self.domain_name} " + f"status: {self.status} " + f"email sent: {self.email_sent} " + ) diff --git a/src/registrar/templates/domain_detail.html b/src/registrar/templates/domain_detail.html index 074f7fec3..6a700b393 100644 --- a/src/registrar/templates/domain_detail.html +++ b/src/registrar/templates/domain_detail.html @@ -5,6 +5,28 @@ {{ block.super }}
+ + Status: + + {% if domain.state == domain.State.UNKNOWN or domain.state == domain.State.DNS_NEEDED%} + DNS Needed + {% else %} + {{ domain.state|title }} + {% endif %} +
+