bug found for registrant, needs to be rewritten

This commit is contained in:
Alysia Broddrick 2023-08-17 13:37:30 -07:00
parent 2963fd05d1
commit 099adb3dc2
No known key found for this signature in database
GPG key ID: 03917052CD0F06B7

View file

@ -2,7 +2,7 @@ import logging
from datetime import date from datetime import date
from string import digits from string import digits
from django_fsm import FSMField # type: ignore from django_fsm import FSMField, transition # type: ignore
from django.db import models from django.db import models
@ -112,6 +112,11 @@ class Domain(TimeStampedModel, DomainHelper):
# Domain has had nameservers set, may or may not be active # Domain has had nameservers set, may or may not be active
CREATED = "created" CREATED = "created"
#Registrar manually changed state to client hold
CLIENT_HOLD ="client hold"
#Registry
SERVER_HOLD = "server hold"
# previously existed but has been deleted from the registry # previously existed but has been deleted from the registry
DELETED = "deleted" DELETED = "deleted"
@ -264,10 +269,16 @@ class Domain(TimeStampedModel, DomainHelper):
@registrant_contact.setter # type: ignore @registrant_contact.setter # type: ignore
def registrant_contact(self, contact: PublicContact): def registrant_contact(self, contact: PublicContact):
# get id from PublicContact->.registry_id """Registrant is set when a domain is created, so follow on additions will update the current registrant"""
# call UpdateDomain() command with registrant as parameter ###incorrect should update an existing registrant
raise NotImplementedError() logger.info("making registrant contact")
# if contact.contact_type!=contact.ContactTypeChoices.REGISTRANT:
# raise ValueError("Cannot set a registrant contact with a different contact type")
# logger.info("registrant_contact()-> update domain with registrant contact")
# self._update_domain_with_contact(contact, rem=False)
#req= updated contact
#send req
#handle error poorly
@Cache @Cache
def administrative_contact(self) -> PublicContact: def administrative_contact(self) -> PublicContact:
"""Get or set the admin contact for this domain.""" """Get or set the admin contact for this domain."""
@ -279,7 +290,12 @@ class Domain(TimeStampedModel, DomainHelper):
# call UpdateDomain with contact, # call UpdateDomain with contact,
# type options are[admin, billing, tech, security] # type options are[admin, billing, tech, security]
# use admin as type parameter for this contact # use admin as type parameter for this contact
raise NotImplementedError() logger.info("making admin contact")
if contact.contact_type!=contact.ContactTypeChoices.ADMINISTRATIVE:
raise ValueError("Cannot set a registrant contact with a different contact type")
logger.info("administrative_contact()-> update domain with admin contact")
self._update_domain_with_contact(contact, rem=False)
def get_default_security_contact(self): def get_default_security_contact(self):
logger.info("getting default sec contact") logger.info("getting default sec contact")
@ -299,6 +315,8 @@ class Domain(TimeStampedModel, DomainHelper):
registry.send(updateDomain, cleaned=True) registry.send(updateDomain, cleaned=True)
except RegistryError as e: except RegistryError as e:
logger.error("Error removing old security 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 @Cache
def security_contact(self) -> PublicContact: def security_contact(self) -> PublicContact:
"""Get or set the security contact for this domain.""" """Get or set the security contact for this domain."""
@ -345,28 +363,14 @@ class Domain(TimeStampedModel, DomainHelper):
for security the public contact should have the org or registrant information for security the public contact should have the org or registrant information
from domain information (not domain application) from domain information (not domain application)
and should have the security email from DomainApplication""" and should have the security email from DomainApplication"""
print("making contact in registry") logger.info("making security contact in registry")
self._make_contact_in_registry(contact=contact) if contact.contact_type!=contact.ContactTypeChoices.SECURITY:
raise ValueError("Cannot set a security contact with a different contact type")
logger.info("security_contact()-> update domain with secutity contact")
self._update_domain_with_contact(contact, rem=False)
#create update domain command with security contact ##TODO- delete old security contact if one exists??
# 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)
updateDomainAddContact=commands.UpdateDomain(name=self.name, rem=[addDomainContact] )
try:
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))
@Cache @Cache
@ -376,7 +380,11 @@ class Domain(TimeStampedModel, DomainHelper):
@technical_contact.setter # type: ignore @technical_contact.setter # type: ignore
def technical_contact(self, contact: PublicContact): def technical_contact(self, contact: PublicContact):
raise NotImplementedError() logger.info("making technical contact")
if contact.contact_type!=contact.ContactTypeChoices.TECHNICAL:
raise ValueError("Cannot set a technical contact with a different contact type")
logger.info("technical_contact()-> update domain with technical contact")
self._update_domain_with_contact(contact, rem=False)
def is_active(self) -> bool: def is_active(self) -> bool:
"""Is the domain live on the inter webs?""" """Is the domain live on the inter webs?"""
@ -465,13 +473,18 @@ class Domain(TimeStampedModel, DomainHelper):
def _get_or_create_domain(self): def _get_or_create_domain(self):
"""Try to fetch info about this domain. Create it if it does not exist.""" """Try to fetch info about this domain. Create it if it does not exist."""
already_tried_to_create = False already_tried_to_create = False
while True: count=0
while not already_tried_to_create and count<3:
try: try:
logger.info("_get_or_create_domain()-> getting info on the domain, should hit an error") logger.info("_get_or_create_domain()-> getting info on the domain, should hit an error")
req = commands.InfoDomain(name=self.name) req = commands.InfoDomain(name=self.name)
return registry.send(req, cleaned=True).res_data[0] domainInfo= registry.send(req, cleaned=True).res_data[0]
already_tried_to_create = True
return domainInfo
except RegistryError as e: except RegistryError as e:
count+=1
if already_tried_to_create: if already_tried_to_create:
logger.error("Already tried to create") logger.error("Already tried to create")
logger.error(e) logger.error(e)
@ -485,14 +498,17 @@ class Domain(TimeStampedModel, DomainHelper):
logger.error(e) logger.error(e)
logger.error(e.code) logger.error(e.code)
raise e raise e
def _make_domain_in_registry(self):
@transition(field="state", source=State.UNKNOWN, target=State.PENDING_CREATE)
def pendingCreate(self):
logger.info("In make domain in registry ") logger.info("In make domain in registry ")
registrant = PublicContact.get_default_registrant() registrant = PublicContact.get_default_registrant()
self._make_contact_in_registry(registrant) self._make_contact_in_registry(registrant)
logger.info("registrant is %s" % registrant) logger.info("registrant is %s" % registrant)
#TODO-notes no chg item for registrant in the epplib should #TODO-notes no chg item for registrant in the epplib should
security_contact = self._get_or_create_contact( PublicContact.get_default_security()) security_contact=PublicContact.get_default_security()
req = commands.CreateDomain( req = commands.CreateDomain(
name=self.name, name=self.name,
registrant=registrant.registry_id, registrant=registrant.registry_id,
@ -510,13 +526,43 @@ class Domain(TimeStampedModel, DomainHelper):
raise err raise err
logger.info("_get_or_create_domain()-> registry received create for "+self.name) logger.info("_get_or_create_domain()-> registry received create for "+self.name)
logger.info(response) logger.info(response)
# no error, so go ahead and update state # no error, so go ahead and add a security contact
## self.security_contact=security_contact
#make this a trainsition function
self.state = Domain.State.PENDING_CREATE def testSettingAllContacts(self):
self.save() ##delete this funciton
logger.info("update domain with secutity contact") logger.info("testSettingAllContacts")
self._update_domain_with_contact(security_contact, rem=False) security_contact=PublicContact.get_default_security()
security_contact.domain=self
technical_contact=PublicContact.get_default_technical()
technical_contact.domain=self
administrative_contact=PublicContact.get_default_administrative()
administrative_contact.domain=self
# security_contact.save()
technical_contact.save()
administrative_contact.save()
try:
logger.info("setting registrant")
self.registrant_contact=PublicContact.get_default_registrant()
except Exception as err:
logger.info(err.code)
logger.info(err)
@transition(field="state", source=State.PENDING_CREATE, target=State.CLIENT_HOLD)
def clientHold(self):
##TODO - check to see if client hold is allowed should happen outside of this function
#(check prohibited statuses)
logger.info("clientHold()-> inside clientHold")
pass
#TODO -send clientHold here
@transition(field="state", source=State.CLIENT_HOLD, target=State.DELETED)
def deleted(self):
logger.info("pendingCreate()-> inside pending create")
pass
#TODO - send delete here
def _make_contact_in_registry(self, contact: PublicContact): def _make_contact_in_registry(self, contact: PublicContact):
"""Create the contact in the registry, ignore duplicate contact errors""" """Create the contact in the registry, ignore duplicate contact errors"""
@ -559,6 +605,7 @@ class Domain(TimeStampedModel, DomainHelper):
try: try:
logger.info("sending contact") logger.info("sending contact")
registry.send(create, cleaned=True) registry.send(create, cleaned=True)
return contact return contact
except RegistryError as err: except RegistryError as err:
#don't throw an error if it is just saying this is a duplicate contact #don't throw an error if it is just saying this is a duplicate contact
@ -568,14 +615,15 @@ class Domain(TimeStampedModel, DomainHelper):
else: else:
logger.warning("Registrar tried to create duplicate contact for id %s",contact.registry_id) logger.warning("Registrar tried to create duplicate contact for id %s",contact.registry_id)
def _request_contact_info(self, contact: PublicContact):
req = commands.InfoContact(id=contact.registry_id)
return registry.send(req, cleaned=True).res_data[0]
def _get_or_create_contact(self, contact: PublicContact): def _get_or_create_contact(self, contact: PublicContact):
"""Try to fetch info about a contact. Create it if it does not exist.""" """Try to fetch info about a contact. Create it if it does not exist."""
try: try:
req = commands.InfoContact(id=contact.registry_id) return self._request_contact_info(contact)
return registry.send(req, cleaned=True).res_data[0]
except RegistryError as e: except RegistryError as e: