merge main

This commit is contained in:
Rachid Mrad 2024-09-16 18:54:59 -04:00
commit 6250ab99ac
No known key found for this signature in database
72 changed files with 2250 additions and 1064 deletions

View file

@ -22,8 +22,6 @@ from .utility import (
DomainRequestWizardPermissionView,
)
from waffle.decorators import flag_is_active, waffle_flag
logger = logging.getLogger(__name__)
@ -45,7 +43,6 @@ class Step(StrEnum):
CURRENT_SITES = "current_sites"
DOTGOV_DOMAIN = "dotgov_domain"
PURPOSE = "purpose"
YOUR_CONTACT = "your_contact"
OTHER_CONTACTS = "other_contacts"
ADDITIONAL_DETAILS = "additional_details"
REQUIREMENTS = "requirements"
@ -91,7 +88,6 @@ class DomainRequestWizard(DomainRequestWizardPermissionView, TemplateView):
Step.CURRENT_SITES: _("Current websites"),
Step.DOTGOV_DOMAIN: _(".gov domain"),
Step.PURPOSE: _("Purpose of your domain"),
Step.YOUR_CONTACT: _("Your contact information"),
Step.OTHER_CONTACTS: _("Other employees from your organization"),
Step.ADDITIONAL_DETAILS: _("Additional details"),
Step.REQUIREMENTS: _("Requirements for operating a .gov domain"),
@ -152,7 +148,14 @@ class DomainRequestWizard(DomainRequestWizardPermissionView, TemplateView):
except DomainRequest.DoesNotExist:
logger.debug("DomainRequest id %s did not have a DomainRequest" % id)
self._domain_request = DomainRequest.objects.create(creator=self.request.user)
# If a user is creating a request, we assume that perms are handled upstream
if self.request.user.is_org_user(self.request):
self._domain_request = DomainRequest.objects.create(
creator=self.request.user,
portfolio=self.request.session.get("portfolio"),
)
else:
self._domain_request = DomainRequest.objects.create(creator=self.request.user)
self.storage["domain_request_id"] = self._domain_request.id
return self._domain_request
@ -375,7 +378,6 @@ class DomainRequestWizard(DomainRequestWizardPermissionView, TemplateView):
),
"dotgov_domain": self.domain_request.requested_domain is not None,
"purpose": self.domain_request.purpose is not None,
"your_contact": self.domain_request.submitter is not None,
"other_contacts": (
self.domain_request.other_contacts.exists()
or self.domain_request.no_other_contacts_rationale is not None
@ -395,6 +397,10 @@ class DomainRequestWizard(DomainRequestWizardPermissionView, TemplateView):
def get_context_data(self):
"""Define context for access on all wizard pages."""
requested_domain_name = None
if self.domain_request.requested_domain is not None:
requested_domain_name = self.domain_request.requested_domain.name
context_stuff = {}
if DomainRequest._form_complete(self.domain_request, self.request):
modal_button = '<button type="submit" ' 'class="usa-button" ' ">Submit request</button>"
@ -411,6 +417,7 @@ class DomainRequestWizard(DomainRequestWizardPermissionView, TemplateView):
Youll only be able to withdraw your request.",
"review_form_is_complete": True,
"user": self.request.user,
"requested_domain__name": requested_domain_name,
}
else: # form is not complete
modal_button = '<button type="button" class="usa-button" data-close-modal>Return to request</button>'
@ -426,6 +433,7 @@ class DomainRequestWizard(DomainRequestWizardPermissionView, TemplateView):
Return to the request and visit the steps that are marked as "incomplete."',
"review_form_is_complete": False,
"user": self.request.user,
"requested_domain__name": requested_domain_name,
}
return context_stuff
@ -439,9 +447,6 @@ class DomainRequestWizard(DomainRequestWizardPermissionView, TemplateView):
if condition:
step_list.append(step)
if flag_is_active(self.request, "profile_feature"):
step_list.remove(Step.YOUR_CONTACT)
return step_list
def goto(self, step):
@ -505,7 +510,11 @@ class DomainRequestWizard(DomainRequestWizardPermissionView, TemplateView):
# if user opted to save progress and return,
# return them to the home page
if button == "save_and_return":
return HttpResponseRedirect(reverse("home"))
if request.user.is_org_user(request):
return HttpResponseRedirect(reverse("domain-requests"))
else:
return HttpResponseRedirect(reverse("home"))
# otherwise, proceed as normal
return self.goto_next_step()
@ -582,15 +591,6 @@ class Purpose(DomainRequestWizard):
forms = [forms.PurposeForm]
class YourContact(DomainRequestWizard):
template_name = "domain_request_your_contact.html"
forms = [forms.YourContactForm]
@waffle_flag("!profile_feature") # type: ignore
def dispatch(self, request, *args, **kwargs): # type: ignore
return super().dispatch(request, *args, **kwargs)
class OtherContacts(DomainRequestWizard):
template_name = "domain_request_other_contacts.html"
forms = [forms.OtherContactsYesNoForm, forms.OtherContactsFormSet, forms.NoOtherContactsForm]
@ -774,7 +774,10 @@ class DomainRequestWithdrawn(DomainRequestPermissionWithdrawView):
domain_request = DomainRequest.objects.get(id=self.kwargs["pk"])
domain_request.withdraw()
domain_request.save()
return HttpResponseRedirect(reverse("home"))
if self.request.user.is_org_user(self.request):
return HttpResponseRedirect(reverse("domain-requests"))
else:
return HttpResponseRedirect(reverse("home"))
class DomainRequestDeleteView(DomainRequestPermissionDeleteView):
@ -813,7 +816,7 @@ class DomainRequestDeleteView(DomainRequestPermissionDeleteView):
# After a delete occurs, do a second sweep on any returned duplicates.
# This determines if any of these three fields share a contact, which is used for
# the edge case where the same user may be an SO, and a submitter, for example.
# the edge case where the same user may be an SO, and a creator, for example.
if len(duplicates) > 0:
duplicates_to_delete, _ = self._get_orphaned_contacts(domain_request, check_db=True)
Contact.objects.filter(id__in=duplicates_to_delete).delete()
@ -826,7 +829,7 @@ class DomainRequestDeleteView(DomainRequestPermissionDeleteView):
Collects all orphaned contacts associated with a given DomainRequest object.
An orphaned contact is defined as a contact that is associated with the domain request,
but not with any other domain_request. This includes the senior official, the submitter,
but not with any other domain_request. This includes the senior official, the creator,
and any other contacts linked to the domain_request.
Parameters:
@ -842,18 +845,16 @@ class DomainRequestDeleteView(DomainRequestPermissionDeleteView):
# Get each contact object on the DomainRequest object
so = domain_request.senior_official
submitter = domain_request.submitter
other_contacts = list(domain_request.other_contacts.all())
other_contact_ids = domain_request.other_contacts.all().values_list("id", flat=True)
# Check if the desired item still exists in the DB
if check_db:
so = self._get_contacts_by_id([so.id]).first() if so is not None else None
submitter = self._get_contacts_by_id([submitter.id]).first() if submitter is not None else None
other_contacts = self._get_contacts_by_id(other_contact_ids)
# Pair each contact with its db related name for use in checking if it has joins
checked_contacts = [(so, "senior_official"), (submitter, "submitted_domain_requests")]
checked_contacts = [(so, "senior_official")]
checked_contacts.extend((contact, "contact_domain_requests") for contact in other_contacts)
for contact, related_name in checked_contacts: