Skip to content

Commit

Permalink
Merge pull request #2392 from cisagov/gd/2365-add-suborg-to-domain-info
Browse files Browse the repository at this point in the history
Ticket #2365: add suborg to domain info
  • Loading branch information
zandercymatics authored Jul 2, 2024
2 parents 43697a5 + a5f1413 commit 5a8ac1c
Show file tree
Hide file tree
Showing 5 changed files with 131 additions and 15 deletions.
30 changes: 19 additions & 11 deletions src/registrar/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -1233,7 +1233,7 @@ class DomainInformationAdmin(ListHeaderAdmin, ImportExportModelAdmin):
search_help_text = "Search by domain."

fieldsets = [
(None, {"fields": ["portfolio", "creator", "submitter", "domain_request", "notes"]}),
(None, {"fields": ["portfolio", "sub_organization", "creator", "submitter", "domain_request", "notes"]}),
(".gov domain", {"fields": ["domain"]}),
("Contacts", {"fields": ["senior_official", "other_contacts", "no_other_contacts_rationale"]}),
("Background info", {"fields": ["anything_else"]}),
Expand Down Expand Up @@ -1312,6 +1312,8 @@ class DomainInformationAdmin(ListHeaderAdmin, ImportExportModelAdmin):
"senior_official",
"domain",
"submitter",
"portfolio",
"sub_organization",
]

# Table ordering
Expand All @@ -1321,6 +1323,7 @@ class DomainInformationAdmin(ListHeaderAdmin, ImportExportModelAdmin):

superuser_only_fields = [
"portfolio",
"sub_organization",
]

# DEVELOPER's NOTE:
Expand Down Expand Up @@ -1509,6 +1512,7 @@ def custom_election_board(self, obj):
{
"fields": [
"portfolio",
"sub_organization",
"status",
"rejection_reason",
"action_needed_reason",
Expand Down Expand Up @@ -1616,11 +1620,14 @@ def custom_election_board(self, obj):
"creator",
"senior_official",
"investigator",
"portfolio",
"sub_organization",
]
filter_horizontal = ("current_websites", "alternative_domains", "other_contacts")

superuser_only_fields = [
"portfolio",
"sub_organization",
]

# DEVELOPER's NOTE:
Expand Down Expand Up @@ -2035,14 +2042,7 @@ class DomainInformationInline(admin.StackedInline):
fieldsets = DomainInformationAdmin.fieldsets
readonly_fields = DomainInformationAdmin.readonly_fields
analyst_readonly_fields = DomainInformationAdmin.analyst_readonly_fields

autocomplete_fields = [
"creator",
"domain_request",
"senior_official",
"domain",
"submitter",
]
autocomplete_fields = DomainInformationAdmin.autocomplete_fields

def has_change_permission(self, request, obj=None):
"""Custom has_change_permission override so that we can specify that
Expand Down Expand Up @@ -2154,8 +2154,7 @@ def queryset(self, request, queryset):
),
)

# this ordering effects the ordering of results
# in autocomplete_fields for domain
# this ordering effects the ordering of results in autocomplete_fields for domain
ordering = ["name"]

def generic_org_type(self, obj):
Expand Down Expand Up @@ -2639,6 +2638,11 @@ class PortfolioAdmin(ListHeaderAdmin):
# readonly_fields = [
# "requestor",
# ]
# Creates select2 fields (with search bars)
autocomplete_fields = [
"creator",
"federal_agency",
]

def save_model(self, request, obj, form, change):

Expand Down Expand Up @@ -2722,6 +2726,10 @@ class DomainGroupAdmin(ListHeaderAdmin, ImportExportModelAdmin):

class SuborganizationAdmin(ListHeaderAdmin, ImportExportModelAdmin):
list_display = ["name", "portfolio"]
autocomplete_fields = [
"portfolio",
]
search_fields = ["name"]


admin.site.unregister(LogEntry) # Unregister the default registration
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# Generated by Django 4.2.10 on 2024-07-02 16:59

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
("registrar", "0108_domaininformation_authorizing_official_and_more"),
]

operations = [
migrations.AddField(
model_name="domaininformation",
name="sub_organization",
field=models.ForeignKey(
blank=True,
help_text="The suborganization that this domain is included under",
null=True,
on_delete=django.db.models.deletion.PROTECT,
related_name="information_sub_organization",
to="registrar.suborganization",
),
),
migrations.AddField(
model_name="domainrequest",
name="sub_organization",
field=models.ForeignKey(
blank=True,
help_text="The suborganization that this domain request is included under",
null=True,
on_delete=django.db.models.deletion.PROTECT,
related_name="request_sub_organization",
to="registrar.suborganization",
),
),
migrations.AlterField(
model_name="domaininformation",
name="portfolio",
field=models.ForeignKey(
blank=True,
help_text="Portfolio associated with this domain",
null=True,
on_delete=django.db.models.deletion.PROTECT,
related_name="information_portfolio",
to="registrar.portfolio",
),
),
migrations.AlterField(
model_name="domainrequest",
name="approved_domain",
field=models.OneToOneField(
blank=True,
help_text="Domain associated with this request; will be blank until request is approved",
null=True,
on_delete=django.db.models.deletion.SET_NULL,
related_name="domain_request_approved_domain",
to="registrar.domain",
),
),
migrations.AlterField(
model_name="domainrequest",
name="portfolio",
field=models.ForeignKey(
blank=True,
help_text="Portfolio associated with this domain request",
null=True,
on_delete=django.db.models.deletion.PROTECT,
related_name="DomainRequest_portfolio",
to="registrar.portfolio",
),
),
migrations.AlterField(
model_name="domainrequest",
name="requested_domain",
field=models.OneToOneField(
blank=True,
null=True,
on_delete=django.db.models.deletion.PROTECT,
related_name="domain_request_requested_domain",
to="registrar.draftdomain",
),
),
]
15 changes: 14 additions & 1 deletion src/registrar/models/domain_information.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,19 @@ class Meta:
on_delete=models.PROTECT,
null=True,
blank=True,
related_name="DomainRequest_portfolio",
related_name="information_portfolio",
help_text="Portfolio associated with this domain",
)

sub_organization = models.ForeignKey(
"registrar.Suborganization",
on_delete=models.PROTECT,
null=True,
blank=True,
related_name="information_sub_organization",
help_text="The suborganization that this domain is included under",
)

domain_request = models.OneToOneField(
"registrar.DomainRequest",
on_delete=models.PROTECT,
Expand Down Expand Up @@ -361,6 +370,10 @@ def create_from_da(cls, domain_request: DomainRequest, domain=None):
# domain_request, if so short circuit the create
existing_domain_info = cls.objects.filter(domain_request__id=domain_request.id).first()
if existing_domain_info:
logger.info(
f"create_from_da() -> Shortcircuting create on {existing_domain_info}. "
"This record already exists. No values updated!"
)
return existing_domain_info

# Get the fields that exist on both DomainRequest and DomainInformation
Expand Down
15 changes: 12 additions & 3 deletions src/registrar/models/domain_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,10 +315,19 @@ def get_action_needed_reason_label(cls, action_needed_reason: str):
on_delete=models.PROTECT,
null=True,
blank=True,
related_name="DomainInformation_portfolio",
related_name="DomainRequest_portfolio",
help_text="Portfolio associated with this domain request",
)

sub_organization = models.ForeignKey(
"registrar.Suborganization",
on_delete=models.PROTECT,
null=True,
blank=True,
related_name="request_sub_organization",
help_text="The suborganization that this domain request is included under",
)

# This is the domain request user who created this domain request. The contact
# information that they gave is in the `submitter` field
creator = models.ForeignKey(
Expand Down Expand Up @@ -444,15 +453,15 @@ def get_action_needed_reason_label(cls, action_needed_reason: str):
null=True,
blank=True,
help_text="Domain associated with this request; will be blank until request is approved",
related_name="domain_request",
related_name="domain_request_approved_domain",
on_delete=models.SET_NULL,
)

requested_domain = models.OneToOneField(
"DraftDomain",
null=True,
blank=True,
related_name="domain_request",
related_name="domain_request_requested_domain",
on_delete=models.PROTECT,
)

Expand Down
1 change: 1 addition & 0 deletions src/registrar/tests/test_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -2249,6 +2249,7 @@ def test_readonly_when_restricted_creator(self):
"action_needed_reason_email",
"federal_agency",
"portfolio",
"sub_organization",
"creator",
"investigator",
"generic_org_type",
Expand Down

0 comments on commit 5a8ac1c

Please sign in to comment.