mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-05-18 18:39:21 +02:00
basic logic
This commit is contained in:
parent
6f6beef6e4
commit
79077cce31
5 changed files with 62 additions and 1 deletions
|
@ -629,6 +629,10 @@ export function initRejectedEmail() {
|
|||
});
|
||||
}
|
||||
|
||||
function handleSuborganizationSelection() {
|
||||
console.log("cats are cool")
|
||||
}
|
||||
|
||||
/**
|
||||
* A function for dynamic DomainRequest fields
|
||||
*/
|
||||
|
@ -636,5 +640,6 @@ export function initDynamicDomainRequestFields(){
|
|||
const domainRequestPage = document.getElementById("domainrequest_form");
|
||||
if (domainRequestPage) {
|
||||
handlePortfolioSelection();
|
||||
handleSuborganizationSelection();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
# Generated by Django 4.2.10 on 2024-12-16 17:02
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("registrar", "0139_alter_domainrequest_action_needed_reason"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterUniqueTogether(
|
||||
name="suborganization",
|
||||
unique_together={("name", "portfolio")},
|
||||
),
|
||||
]
|
|
@ -237,6 +237,7 @@ class Domain(TimeStampedModel, DomainHelper):
|
|||
is called in the validate function on the request/domain page
|
||||
|
||||
throws- RegistryError or InvalidDomainError"""
|
||||
return True
|
||||
if not cls.string_could_be_domain(domain):
|
||||
logger.warning("Not a valid domain: %s" % str(domain))
|
||||
# throw invalid domain error so that it can be caught in
|
||||
|
|
|
@ -690,6 +690,18 @@ class DomainRequest(TimeStampedModel):
|
|||
# Update the cached values after saving
|
||||
self._cache_status_and_status_reasons()
|
||||
|
||||
def create_requested_suborganization(self):
|
||||
"""Creates the requested suborganization.
|
||||
Adds the name, portfolio, city, and state_territory fields.
|
||||
Returns the created suborganization."""
|
||||
Suborganization = apps.get_model("registrar.Suborganization")
|
||||
return Suborganization.objects.create(
|
||||
name=self.requested_suborganization,
|
||||
portfolio=self.portfolio,
|
||||
city=self.suborganization_city,
|
||||
state_territory=self.suborganization_state_territory,
|
||||
)
|
||||
|
||||
def send_custom_status_update_email(self, status):
|
||||
"""Helper function to send out a second status email when the status remains the same,
|
||||
but the reason has changed."""
|
||||
|
@ -785,6 +797,7 @@ class DomainRequest(TimeStampedModel):
|
|||
|
||||
def delete_and_clean_up_domain(self, called_from):
|
||||
try:
|
||||
# Clean up the approved domain
|
||||
domain_state = self.approved_domain.state
|
||||
# Only reject if it exists on EPP
|
||||
if domain_state != Domain.State.UNKNOWN:
|
||||
|
@ -796,6 +809,19 @@ class DomainRequest(TimeStampedModel):
|
|||
logger.error(err)
|
||||
logger.error(f"Can't query an approved domain while attempting {called_from}")
|
||||
|
||||
# Clean up any created suborgs, assuming its for this record only
|
||||
if self.sub_organization is not None:
|
||||
request_suborg_count = self.request_sub_organization.count()
|
||||
domain_suborgs = self.DomainRequest_info.filter(
|
||||
sub_organization=self.sub_organization
|
||||
).count()
|
||||
if request_suborg_count == 1 and domain_suborgs.count() <= 1:
|
||||
# if domain_suborgs.count() == 1:
|
||||
# domain_info = domain_suborgs.first()
|
||||
# domain_info.sub_organization = None
|
||||
# domain_info.save()
|
||||
self.sub_organization.delete()
|
||||
|
||||
def _send_status_update_email(
|
||||
self,
|
||||
new_status,
|
||||
|
@ -984,6 +1010,7 @@ class DomainRequest(TimeStampedModel):
|
|||
|
||||
if self.status == self.DomainRequestStatus.APPROVED:
|
||||
self.delete_and_clean_up_domain("action_needed")
|
||||
|
||||
elif self.status == self.DomainRequestStatus.REJECTED:
|
||||
self.rejection_reason = None
|
||||
|
||||
|
@ -1014,8 +1041,16 @@ class DomainRequest(TimeStampedModel):
|
|||
domain request into an admin on that domain. It also triggers an email
|
||||
notification."""
|
||||
|
||||
should_save = False
|
||||
if self.federal_agency is None:
|
||||
self.federal_agency = FederalAgency.objects.filter(agency="Non-Federal Agency").first()
|
||||
should_save = True
|
||||
|
||||
if self.is_requesting_new_suborganization():
|
||||
self.sub_organization = self.create_requested_suborganization()
|
||||
should_save = True
|
||||
|
||||
if should_save:
|
||||
self.save()
|
||||
|
||||
# create the domain
|
||||
|
@ -1148,7 +1183,7 @@ class DomainRequest(TimeStampedModel):
|
|||
def is_requesting_new_suborganization(self) -> bool:
|
||||
"""Determines if a user is trying to request
|
||||
a new suborganization using the domain request form, rather than one that already exists.
|
||||
Used for the RequestingEntity page.
|
||||
Used for the RequestingEntity page and on DomainInformation.create_from_da().
|
||||
|
||||
Returns True if a sub_organization does not exist and if requested_suborganization,
|
||||
suborganization_city, and suborganization_state_territory all exist.
|
||||
|
|
|
@ -9,6 +9,9 @@ class Suborganization(TimeStampedModel):
|
|||
Suborganization under an organization (portfolio)
|
||||
"""
|
||||
|
||||
class Meta:
|
||||
unique_together = ["name", "portfolio"]
|
||||
|
||||
name = models.CharField(
|
||||
unique=True,
|
||||
max_length=1000,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue