Refactored storage of CISA rep info to NOT use Contacts model

This commit is contained in:
CocoByte 2024-05-31 15:39:40 -06:00
parent 9fecf11558
commit 8af8a8c670
No known key found for this signature in database
GPG key ID: BBFAA2526384C97F
12 changed files with 164 additions and 132 deletions

View file

@ -647,47 +647,20 @@ class NoOtherContactsForm(BaseDeletableRegistrarForm):
class CisaRepresentativeForm(BaseDeletableRegistrarForm):
JOIN = "cisa_representative"
def to_database(self, obj):
if not self.is_valid():
return
contact = getattr(obj, "cisa_representative", None)
if contact is not None and not contact.has_more_than_one_join("cisa_representative_domain_requests"):
if self.form_data_marked_for_deletion:
# remove the CISA contact from this domain request
obj.cisa_representative = None
# QUESTION - should we also delete the contact object if it is not joined to other entities?
else:
# update existing contact if it is not joined to other enttities
super().to_database(contact)
else:
# no contact exists OR contact exists which is joined also to other entities;
# in either case, create a new contact and update it
contact = Contact()
super().to_database(contact)
obj.cisa_representative = contact
obj.save()
@classmethod
def from_database(cls, obj):
contact = getattr(obj, "cisa_representative", None)
return super().from_database(contact)
first_name = forms.CharField(
cisa_representative_first_name = forms.CharField(
label="First name / given name",
error_messages={"required": "Enter your first name / given name."},
)
last_name = forms.CharField(
cisa_representative_last_name = forms.CharField(
label="Last name / family name",
error_messages={"required": "Enter your last name / family name."},
)
email = forms.EmailField(
label="Email",
cisa_representative_email = forms.EmailField(
label="Your representatives email (optional)",
max_length=None,
required=False,
error_messages={
"invalid": ("Enter your email address in the required format, like name@example.com."),
"invalid": ("Enter your representatives email address in the required format, like name@example.com."),
},
validators=[
MaxLengthValidator(
@ -698,6 +671,7 @@ class CisaRepresentativeForm(BaseDeletableRegistrarForm):
)
class CisaRepresentativeYesNoForm(BaseYesNoForm):
"""Yes/no toggle for the CISA regions question on additional details"""