diff --git a/docs/developer/registry-access.md b/docs/developer/registry-access.md index a59c8b8b7..c7737d5bc 100644 --- a/docs/developer/registry-access.md +++ b/docs/developer/registry-access.md @@ -31,7 +31,7 @@ Finally, you'll need to craft a request and send it. ``` request = ... -response = registry.send(request) +response = registry.send(request, cleaned=True) ``` Note that you'll need to attest that the data you are sending has been sanitized to remove malicious or invalid strings. Use `send(..., cleaned=True)` to do that. diff --git a/src/epplibwrapper/client.py b/src/epplibwrapper/client.py index 156ee7608..11b7e8dc1 100644 --- a/src/epplibwrapper/client.py +++ b/src/epplibwrapper/client.py @@ -83,7 +83,7 @@ class EPPLibWrapper: logger.warning(message, cmd_type, exc_info=True) raise RegistryError(message) from err except Exception as err: - message = "%s failed to execute due to an unknown error." + message = '%s failed to execute due to an unknown error.' % err logger.warning(message, cmd_type, exc_info=True) raise RegistryError(message) from err else: diff --git a/src/registrar/admin.py b/src/registrar/admin.py index a6c4ffd8e..1875cd340 100644 --- a/src/registrar/admin.py +++ b/src/registrar/admin.py @@ -124,10 +124,15 @@ class DomainAdmin(ListHeaderAdmin): readonly_fields = ["state"] def response_change(self, request, obj): + print(request.POST) ACTION_BUTTON = "_place_client_hold" - GET_SECURITY_EMAIL="_get_security_contact" - SET_SECURITY_EMAIL="_set_security_contact" + GET_SECURITY_EMAIL="_get_security_email" + SET_SECURITY_CONTACT="_set_security_contact" + MAKE_DOMAIN="_make_domain_in_registry" + logger.info("in response") if ACTION_BUTTON in request.POST: + logger.info("in action button") + print("in action button") try: obj.place_client_hold() except Exception as err: @@ -160,27 +165,62 @@ class DomainAdmin(ListHeaderAdmin): ) return HttpResponseRedirect(".") - return super().response_change(request, obj) - def response_change(self, request, obj): - ACTION_BUTTON = "_get_security_email" - - if ACTION_BUTTON in request.POST: + + if SET_SECURITY_CONTACT in request.POST: try: - obj.security + security_contact = obj.get_default_security_contact() + security_contact.email="ab@test.gov" + + obj.security_contact=security_contact except Exception as err: self.message_user(request, err, messages.ERROR) else: - self.message_user( - request, + self.message_user(request, ( - "%s is in client hold. This domain is no longer accessible on" - " the public internet." + "The security email is %" + ". Thanks!" + ) + % security_email, + ) + print("above make domain") + + if MAKE_DOMAIN in request.POST: + print("in make domain") + + try: + obj._get_or_create_domain() + except Exception as err: + self.message_user(request, err, messages.ERROR) + else: + self.message_user(request, + ( + "Domain created with %" + ". Thanks!" ) % obj.name, ) return HttpResponseRedirect(".") - return super().response_change(request, obj) + # def response_change(self, request, obj): + # ACTION_BUTTON = "_get_security_email" + + # if ACTION_BUTTON in request.POST: + # try: + # obj.security + # except Exception as err: + # self.message_user(request, err, messages.ERROR) + # else: + # self.message_user( + # request, + # ( + # "%s is in client hold. This domain is no longer accessible on" + # " the public internet." + # ) + # % obj.name, + # ) + # return HttpResponseRedirect(".") + + # return super().response_change(request, obj) class ContactAdmin(ListHeaderAdmin): diff --git a/src/registrar/models/domain.py b/src/registrar/models/domain.py index 0edfe9e7e..7bbd0767d 100644 --- a/src/registrar/models/domain.py +++ b/src/registrar/models/domain.py @@ -103,15 +103,19 @@ class Domain(TimeStampedModel, DomainHelper): class State(models.TextChoices): """These capture (some of) the states a domain object can be in.""" + # the state is indeterminate + UNKNOWN = "unknown" - # the normal state of a domain object -- may or may not be active! + #The domain object exists in the registry but nameservers don't exist for it yet + PENDING_CREATE="pending create" + + # Domain has had nameservers set, may or may not be active CREATED = "created" # previously existed but has been deleted from the registry DELETED = "deleted" - # the state is indeterminate - UNKNOWN = "unknown" + class Cache(property): """ @@ -284,11 +288,12 @@ class Domain(TimeStampedModel, DomainHelper): updateDomain=commands.UpdateDomain(name=self.name, add=[domainContact] ) if rem: updateDomain=commands.UpdateDomain(name=self.name, rem=[domainContact] ) + logger.info("Send updated") try: registry.send(updateDomain, cleaned=True) except RegistryError as e: - logger.error("Error removing old secuity contact code was %s error was %s" % (e.code, e)) + logger.error("Error removing old security contact code was %s error was %s" % (e.code, e)) @Cache def security_contact(self) -> PublicContact: """Get or set the security contact for this domain.""" @@ -340,20 +345,20 @@ class Domain(TimeStampedModel, DomainHelper): #create update domain command with security contact - current_security_contact=self.security_contact - if self.security_contact.email is not None: - #if there is already a security contact - domainContact=epp.DomainContact(contact=current_security_contact.registry_id,type=current_security_contact.contact_type) - updateDomain=commands.UpdateDomain(name=self.name, rem=[domainContact] ) - try: - registry.send(updateDomain, cleaned=True) - except RegistryError as e: - logger.error("Error removing old secuity contact code was %s error was %s" % (e.code, e)) + # current_security_contact=self.security_contact + # if current_security_contact.email is not None: + # #if there is already a security contact + # domainContact=epp.DomainContact(contact=current_security_contact.registry_id,type=current_security_contact.contact_type) + # updateDomain=commands.UpdateDomain(name=self.name, rem=[domainContact] ) + # try: + # registry.send(updateDomain, cleaned=True) + # except RegistryError as e: + # logger.error("Error removing old secuity contact code was %s error was %s" % (e.code, e)) addDomainContact=epp.DomainContact(contact=contact.registry_id,type=contact.contact_type) - updateDomainAdd=commands.UpdateDomain(name=self.name, rem=[addDomainContact] ) + updateDomainAddContact=commands.UpdateDomain(name=self.name, rem=[addDomainContact] ) try: - registry.send(updateDomainAdd, cleaned=True) + registry.send(updateDomainAddContact, cleaned=True) except RegistryError as e: logger.error("Error removing old security contact code was %s error was %s" % (e.code, e)) @@ -478,26 +483,27 @@ class Domain(TimeStampedModel, DomainHelper): PublicContact.get_default_registrant() ) - #TODO-notes no chg item for registrant in the epplib should - already_tried_to_create = True - security_contact = self._get_or_create_contact(self.get_default_security_contact()) + #TODO-notes no chg item for registrant in the epplib should + + security_contact = self._get_or_create_contact(self.get_default_security_contact()) - req = commands.CreateDomain( - name=self.name, - registrant=registrant.id, - auth_info=epp.DomainAuthInfo( - pw="2fooBAR123fooBaz" - ), # not a password - ) - logger.info("_get_or_create_domain()-> about to send domain request") + req = commands.CreateDomain( + name=self.name, + registrant=registrant.id, + auth_info=epp.DomainAuthInfo( + pw="2fooBAR123fooBaz" + ), # not a password + ) + logger.info("_get_or_create_domain()-> about to send domain request") - response=registry.send(req, cleaned=True) - logger.info("_get_or_create_domain()-> registry received create for "+self.name) - logger.info(response) - # no error, so go ahead and update state - self.state = Domain.State.CREATED - self.save() - self._update_domain_with_contact(security_contact) + response=registry.send(req, cleaned=True) + logger.info("_get_or_create_domain()-> registry received create for "+self.name) + logger.info(response) + # no error, so go ahead and update state + self.state = Domain.State.PENDING_CREATE + self.save() + self._update_domain_with_contact(security_contact, rem=False) + def _make_contact_in_registry(self, contact: PublicContact): """Create the contact in the registry, ignore duplicate contact errors""" create = commands.CreateContact( @@ -535,7 +541,7 @@ class Domain(TimeStampedModel, DomainHelper): types={DF.ADDR: "loc"}, ) try: - registry.send(create) + registry.send(create, cleaned=True) return contact except RegistryError as err: #don't throw an error if it is just saying this is a duplicate contact diff --git a/src/registrar/templates/django/admin/domain_change_form.html b/src/registrar/templates/django/admin/domain_change_form.html index b1a947adc..b06859b69 100644 --- a/src/registrar/templates/django/admin/domain_change_form.html +++ b/src/registrar/templates/django/admin/domain_change_form.html @@ -3,8 +3,10 @@ {% block field_sets %}