mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-08-05 01:11:55 +02:00
Temp duplicate fix
Temporary fix for the duplicate issue... Need to find a better solution
This commit is contained in:
parent
3835293b23
commit
917d19d144
3 changed files with 61 additions and 61 deletions
|
@ -149,7 +149,6 @@ class Domain(TimeStampedModel, DomainHelper):
|
|||
"""Called during set. Example: `domain.registrant = 'abc123'`."""
|
||||
super().__set__(obj, value)
|
||||
# always invalidate cache after sending updates to the registry
|
||||
logger.debug("cache was invalidateds")
|
||||
obj._invalidate_cache()
|
||||
|
||||
def __delete__(self, obj):
|
||||
|
@ -538,11 +537,14 @@ class Domain(TimeStampedModel, DomainHelper):
|
|||
self._update_domain_with_contact(contact=contact, rem=False)
|
||||
# if already exists just update
|
||||
elif alreadyExistsInRegistry:
|
||||
logger.debug(f"aaaa12 {contact.__dict__}")
|
||||
|
||||
current_contact = PublicContact.objects.filter(
|
||||
filtered_contacts = PublicContact.objects.filter(
|
||||
registry_id=contact.registry_id
|
||||
).get()
|
||||
)
|
||||
if(filtered_contacts.count() > 1):
|
||||
filtered_contacts.order_by('id').first().delete()
|
||||
|
||||
current_contact = filtered_contacts.get()
|
||||
logger.debug(f"current contact was accessed {current_contact}")
|
||||
|
||||
if current_contact.email != contact.email:
|
||||
self._update_epp_contact(contact=contact)
|
||||
|
@ -716,7 +718,6 @@ class Domain(TimeStampedModel, DomainHelper):
|
|||
fillvalue=None,
|
||||
)
|
||||
)
|
||||
logger.debug(f"WHAT IS CONTACT {contact_id} {len(contact_id)}")
|
||||
desired_contact = PublicContact(
|
||||
domain=self,
|
||||
contact_type=contact_type,
|
||||
|
@ -735,7 +736,10 @@ class Domain(TimeStampedModel, DomainHelper):
|
|||
)
|
||||
# Saves to DB
|
||||
if(create_object):
|
||||
desired_contact.save()
|
||||
create = PublicContact.objects.filter(registry_id=contact_id, contact_type=contact_type, domain=self)
|
||||
if(create.count() == 0):
|
||||
desired_contact.save()
|
||||
|
||||
return desired_contact
|
||||
|
||||
def _request_contact_info(self, contact: PublicContact):
|
||||
|
@ -803,7 +807,6 @@ class Domain(TimeStampedModel, DomainHelper):
|
|||
logger.warning("generic_contact_getter -> Contact does not exist")
|
||||
logger.warning(error)
|
||||
# Should we just raise an error instead?
|
||||
return self.get_contact_default(contact_type_choice)
|
||||
else:
|
||||
print(f"generic_contact_getter -> contacts?? {contacts}")
|
||||
# --> Map to public contact
|
||||
|
@ -1188,11 +1191,22 @@ class Domain(TimeStampedModel, DomainHelper):
|
|||
# no point in removing
|
||||
cleaned["hosts"] = []
|
||||
for name in cleaned["_hosts"]:
|
||||
# For reviewers - slight refactor here
|
||||
# as we may need this for future hosts tickets
|
||||
# (potential host mapper?).
|
||||
# Can remove if unnecessary
|
||||
cleaned["hosts"].append(self._get_host_as_dict(name))
|
||||
# we do not use _get_or_create_* because we expect the object we
|
||||
# just asked the registry for still exists --
|
||||
# if not, that's a problem
|
||||
req = commands.InfoHost(name=name)
|
||||
data = registry.send(req, cleaned=True).res_data[0]
|
||||
# extract properties from response
|
||||
# (Ellipsis is used to mean "null")
|
||||
host = {
|
||||
"name": name,
|
||||
"addrs": getattr(data, "addrs", ...),
|
||||
"cr_date": getattr(data, "cr_date", ...),
|
||||
"statuses": getattr(data, "statuses", ...),
|
||||
"tr_date": getattr(data, "tr_date", ...),
|
||||
"up_date": getattr(data, "up_date", ...),
|
||||
}
|
||||
cleaned["hosts"].append({k: v for k, v in host.items() if v is not ...})
|
||||
# replace the prior cache with new data
|
||||
self._cache = cleaned
|
||||
|
||||
|
@ -1215,36 +1229,6 @@ class Domain(TimeStampedModel, DomainHelper):
|
|||
full_object, contact.registry_id, contact.contact_type
|
||||
)
|
||||
|
||||
def _get_host_as_dict(self, host_name):
|
||||
"""Returns the result of commands.InfoHost as a dictionary
|
||||
|
||||
Returns the following, excluding null fields:
|
||||
{
|
||||
"name": name,
|
||||
"addrs": addr,
|
||||
"cr_date": cr_date,
|
||||
"statuses": statuses,
|
||||
"tr_date": tr_date,
|
||||
"up_date": up_date,
|
||||
}
|
||||
"""
|
||||
# we do not use _get_or_create_* because we expect the object we
|
||||
# just asked the registry for still exists --
|
||||
# if not, that's a problem
|
||||
req = commands.InfoHost(name=host_name)
|
||||
data = registry.send(req, cleaned=True).res_data[0]
|
||||
# extract properties from response
|
||||
# (Ellipsis is used to mean "null")
|
||||
host = {
|
||||
"name": host_name,
|
||||
"addrs": getattr(data, "addrs", ...),
|
||||
"cr_date": getattr(data, "cr_date", ...),
|
||||
"statuses": getattr(data, "statuses", ...),
|
||||
"tr_date": getattr(data, "tr_date", ...),
|
||||
"up_date": getattr(data, "up_date", ...),
|
||||
}
|
||||
return {k: v for k, v in host.items() if v is not ...}
|
||||
|
||||
def _invalidate_cache(self):
|
||||
"""Remove cache data when updates are made."""
|
||||
logger.debug(f"cache was cleared! {self.__dict__}")
|
||||
|
@ -1252,6 +1236,7 @@ class Domain(TimeStampedModel, DomainHelper):
|
|||
|
||||
def _get_property(self, property):
|
||||
"""Get some piece of info about a domain."""
|
||||
logger.info(f"_get_property() -> prop is... {property} prop in cache... {property not in self._cache} cache is {self._cache}")
|
||||
if property not in self._cache:
|
||||
self._fetch_cache(
|
||||
fetch_hosts=(property == "hosts"),
|
||||
|
@ -1259,7 +1244,6 @@ class Domain(TimeStampedModel, DomainHelper):
|
|||
)
|
||||
|
||||
if property in self._cache:
|
||||
logger.debug(f"hit here also!! {property}")
|
||||
logger.debug(self._cache[property])
|
||||
return self._cache[property]
|
||||
else:
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
<button
|
||||
type="submit"
|
||||
class="usa-button"
|
||||
>{% if domain.security_email is None %}Add security email{% else %}Save{% endif %}</button>
|
||||
>{% if domain.security_email is None and domain.security_email.email != 'g'%}Add security email{% else %}Save{% endif %}</button>
|
||||
</form>
|
||||
|
||||
{% endblock %} {# domain_content #}
|
||||
|
|
|
@ -43,16 +43,30 @@ class TestDomainCache(MockEppLib):
|
|||
# using a setter should clear the cache
|
||||
domain.expiration_date = datetime.date.today()
|
||||
self.assertEquals(domain._cache, {})
|
||||
|
||||
expectedCreateContact = self._convertPublicContactToEpp(domain.security_contact, False, createContact=True)
|
||||
# send should have been called only once
|
||||
self.mockedSendFunction.assert_has_calls(
|
||||
[
|
||||
call(
|
||||
commands.InfoDomain(name="igorville.gov", auth_info=None),
|
||||
cleaned=True,
|
||||
call(commands.InfoDomain(name='igorville.gov', auth_info=None), cleaned=True),
|
||||
call(commands.InfoContact(id='123', auth_info=None), cleaned=True),
|
||||
call(expectedCreateContact),
|
||||
call(commands.UpdateDomain(
|
||||
name='igorville.gov',
|
||||
add=[
|
||||
common.DomainContact(
|
||||
contact='123',
|
||||
type=PublicContact.ContactTypeChoices.SECURITY
|
||||
)
|
||||
],
|
||||
rem=[],
|
||||
nsset=None,
|
||||
keyset=None,
|
||||
registrant=None,
|
||||
auth_info=None
|
||||
),
|
||||
cleaned=True
|
||||
),
|
||||
call(commands.InfoContact(id="123", auth_info=None), cleaned=True),
|
||||
call(commands.InfoHost(name="fake.host.com"), cleaned=True),
|
||||
call(commands.InfoHost(name='fake.host.com'), cleaned=True)
|
||||
]
|
||||
)
|
||||
# Clear the cache
|
||||
|
@ -95,9 +109,7 @@ class TestDomainCache(MockEppLib):
|
|||
common.DomainContact(contact="123", type="security"),
|
||||
]
|
||||
expectedContactsList = [
|
||||
domain.map_epp_contact_to_public_contact(
|
||||
self.mockDataInfoContact, "123", "security"
|
||||
)
|
||||
domain.security_contact
|
||||
]
|
||||
expectedHostsDict = {
|
||||
"name": self.mockDataInfoDomain.hosts[0],
|
||||
|
@ -449,9 +461,7 @@ class TestRegistrantContacts(MockEppLib):
|
|||
security_contact = self.domain.get_default_security_contact()
|
||||
security_contact.email = "originalUserEmail@gmail.com"
|
||||
security_contact.registry_id = "fail"
|
||||
security_contact.domain = self.domain
|
||||
self.domain.security_contact = security_contact
|
||||
|
||||
security_contact.save()
|
||||
expectedCreateCommand = self._convertPublicContactToEpp(
|
||||
security_contact, disclose_email=True
|
||||
)
|
||||
|
@ -464,22 +474,28 @@ class TestRegistrantContacts(MockEppLib):
|
|||
)
|
||||
],
|
||||
)
|
||||
self.domain.security_contact.email = "changedEmail@email.com"
|
||||
#self.domain.security_contact.email = "changedEmail@email.com"
|
||||
security_contact.email = "changedEmail@email.com"
|
||||
security_contact.save()
|
||||
expectedSecondCreateCommand = self._convertPublicContactToEpp(
|
||||
security_contact, disclose_email=True
|
||||
)
|
||||
updateContact = self._convertPublicContactToEpp(
|
||||
security_contact, disclose_email=True, createContact=False
|
||||
)
|
||||
self.domain.security_contact.email = "changedEmailAgain@email.com"
|
||||
|
||||
expected_calls = [
|
||||
call(expectedCreateCommand, cleaned=True),
|
||||
call(expectedUpdateDomain, cleaned=True),
|
||||
call(expectedSecondCreateCommand, cleaned=True),
|
||||
call(updateContact, cleaned=True),
|
||||
]
|
||||
self.mockedSendFunction.assert_has_calls(expected_calls, any_order=True)
|
||||
self.assertEqual(PublicContact.objects.filter(domain=self.domain).count(), 1)
|
||||
# Check if security_contact is what we expect...
|
||||
self.assertEqual(self.domain.security_contact.email, "changedEmailAgain@email.com")
|
||||
# If the item in PublicContact is as expected...
|
||||
current_item = PublicContact.objects.filter(domain=self.domain).get()
|
||||
self.assertEqual(current_item.email, "changedEmailAgain@email.com")
|
||||
self.assertEqual(current_item.email, "changedEmail@email.com")
|
||||
|
||||
# Check if cache stored it correctly...
|
||||
self.assertEqual("contacts" in self.domain._cache)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue