Change logic flow in grab_contact_keys

This commit is contained in:
zandercymatics 2023-09-13 14:59:33 -06:00
parent 7643a63d97
commit e5037cd953
No known key found for this signature in database
GPG key ID: FF4636ABEC9682B7

View file

@ -803,14 +803,14 @@ class Domain(TimeStampedModel, DomainHelper):
contact.domain = self contact.domain = self
return contact return contact
def grab_contact_in_keys(self, contacts, check_type, get_from_registry=True): def grab_contact_in_keys(self, contacts, check_type, get_latest_from_registry=True):
""" Grabs a contact object. """ Grabs a contact object.
Returns None if nothing is found. Returns None if nothing is found.
check_type compares contact["type"] == check_type. check_type compares contact["type"] == check_type.
For example, check_type = 'security' For example, check_type = 'security'
get_from_registry --> bool which specifies if get_latest_from_registry --> bool which specifies if
a InfoContact command should be send to the a InfoContact command should be send to the
registry when grabbing the object. registry when grabbing the object.
If it is set to false, we just grab from cache. If it is set to false, we just grab from cache.
@ -823,18 +823,24 @@ class Domain(TimeStampedModel, DomainHelper):
and "contact" in contact.keys() and "contact" in contact.keys()
and contact["type"] == check_type and contact["type"] == check_type
): ):
if(get_from_registry): #
if(get_latest_from_registry):
request = commands.InfoContact(id=contact.get("contact")) request = commands.InfoContact(id=contact.get("contact"))
# TODO - Additional error checking # TODO - Maybe have this return contact instead,
# Does this have performance implications? # Then create a global timer which eventually returns
# Expecting/sending a response for every object # the requested content.... And updates it!
# seems potentially taxing
contact_info = registry.send(request, cleaned=True) contact_info = registry.send(request, cleaned=True)
logger.debug(f"grab_contact_in_keys -> rest data is {contact_info.res_data[0]}") logger.debug(f"grab_contact_in_keys -> rest data is {contact_info.res_data[0]}")
return self.map_to_public_contact(contact_info.res_data[0]) return self.map_to_public_contact(contact_info.res_data[0])
return contact["contact"] return contact["contact"]
# If nothing is found in cache, then grab from registry
request = commands.InfoContact(id=contact.get("contact"))
contact_info = registry.send(request, cleaned=True)
logger.debug(f"grab_contact_in_keys -> rest data is {contact_info.res_data[0]}")
return self.map_to_public_contact(contact_info.res_data[0])
# ForeignKey on UserDomainRole creates a "permissions" member for # ForeignKey on UserDomainRole creates a "permissions" member for
# all of the user-roles that are in place for this domain # all of the user-roles that are in place for this domain