mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-05-17 10:07:04 +02:00
migrations
This commit is contained in:
parent
c9c6890e7d
commit
de926b1abb
7 changed files with 261 additions and 100 deletions
|
@ -2465,18 +2465,29 @@ class VerifiedByStaffAdmin(ListHeaderAdmin):
|
|||
|
||||
|
||||
class PortfolioAdmin(ListHeaderAdmin):
|
||||
# list_display = ("email", "requestor", "truncated_notes", "created_at")
|
||||
# search_fields = ["email"]
|
||||
# search_help_text = "Search by email."
|
||||
# NOTE: these are just placeholders. Not part of ACs (haven't been defined yet). Update in future tickets.
|
||||
list_display = ("organization_name", "federal_agency", "creator")
|
||||
search_fields = ["organization_name"]
|
||||
search_help_text = "Search by organization name."
|
||||
# readonly_fields = [
|
||||
# "requestor",
|
||||
# ]
|
||||
|
||||
# change_form_template = "django/admin/email_clipboard_change_form.html"
|
||||
|
||||
def save_model(self, request, obj, form, change):
|
||||
# ---- update creator ----
|
||||
# Set the creator field to the current admin user
|
||||
obj.creator = request.user if request.user.is_authenticated else None
|
||||
|
||||
# ---- update organization name ----
|
||||
# org name will be the same as federal agency, if it is federal,
|
||||
# otherwise it will be the actual org name. If nothing is entered for
|
||||
# org name and it is a federal organization, have this field fill with
|
||||
# the federal agency text name.
|
||||
is_federal = obj.organization_type == DomainRequest.OrganizationChoices.FEDERAL
|
||||
if is_federal:
|
||||
obj.organization_name = obj.organization_type
|
||||
#NOTE: What is meant by "federal agency text name?"
|
||||
|
||||
super().save_model(request, obj, form, change)
|
||||
|
||||
|
||||
|
@ -2551,6 +2562,7 @@ admin.site.register(models.PublicContact, PublicContactAdmin)
|
|||
admin.site.register(models.DomainRequest, DomainRequestAdmin)
|
||||
admin.site.register(models.TransitionDomain, TransitionDomainAdmin)
|
||||
admin.site.register(models.VerifiedByStaff, VerifiedByStaffAdmin)
|
||||
admin.site.register(models.Portfolio, PortfolioAdmin)
|
||||
|
||||
# Register our custom waffle implementations
|
||||
admin.site.register(models.WaffleFlag, WaffleFlagAdmin)
|
||||
|
|
|
@ -0,0 +1,174 @@
|
|||
# Generated by Django 4.2.10 on 2024-06-12 22:15
|
||||
|
||||
from django.conf import settings
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
import registrar.models.portfolio
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("registrar", "0100_domainrequest_action_needed_reason"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name="Portfolio",
|
||||
fields=[
|
||||
("id", models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID")),
|
||||
("created_at", models.DateTimeField(auto_now_add=True)),
|
||||
("updated_at", models.DateTimeField(auto_now=True)),
|
||||
("notes", models.TextField(blank=True, null=True)),
|
||||
(
|
||||
"organization_type",
|
||||
models.CharField(
|
||||
blank=True,
|
||||
choices=[
|
||||
("federal", "Federal"),
|
||||
("interstate", "Interstate"),
|
||||
("state_or_territory", "State or territory"),
|
||||
("tribal", "Tribal"),
|
||||
("county", "County"),
|
||||
("city", "City"),
|
||||
("special_district", "Special district"),
|
||||
("school_district", "School district"),
|
||||
],
|
||||
help_text="Type of organization",
|
||||
max_length=255,
|
||||
null=True,
|
||||
),
|
||||
),
|
||||
("organization_name", models.CharField(blank=True, null=True)),
|
||||
("address_line1", models.CharField(blank=True, null=True, verbose_name="address line 1")),
|
||||
("address_line2", models.CharField(blank=True, null=True, verbose_name="address line 2")),
|
||||
("city", models.CharField(blank=True, null=True)),
|
||||
(
|
||||
"state_territory",
|
||||
models.CharField(
|
||||
blank=True,
|
||||
choices=[
|
||||
("AL", "Alabama (AL)"),
|
||||
("AK", "Alaska (AK)"),
|
||||
("AS", "American Samoa (AS)"),
|
||||
("AZ", "Arizona (AZ)"),
|
||||
("AR", "Arkansas (AR)"),
|
||||
("CA", "California (CA)"),
|
||||
("CO", "Colorado (CO)"),
|
||||
("CT", "Connecticut (CT)"),
|
||||
("DE", "Delaware (DE)"),
|
||||
("DC", "District of Columbia (DC)"),
|
||||
("FL", "Florida (FL)"),
|
||||
("GA", "Georgia (GA)"),
|
||||
("GU", "Guam (GU)"),
|
||||
("HI", "Hawaii (HI)"),
|
||||
("ID", "Idaho (ID)"),
|
||||
("IL", "Illinois (IL)"),
|
||||
("IN", "Indiana (IN)"),
|
||||
("IA", "Iowa (IA)"),
|
||||
("KS", "Kansas (KS)"),
|
||||
("KY", "Kentucky (KY)"),
|
||||
("LA", "Louisiana (LA)"),
|
||||
("ME", "Maine (ME)"),
|
||||
("MD", "Maryland (MD)"),
|
||||
("MA", "Massachusetts (MA)"),
|
||||
("MI", "Michigan (MI)"),
|
||||
("MN", "Minnesota (MN)"),
|
||||
("MS", "Mississippi (MS)"),
|
||||
("MO", "Missouri (MO)"),
|
||||
("MT", "Montana (MT)"),
|
||||
("NE", "Nebraska (NE)"),
|
||||
("NV", "Nevada (NV)"),
|
||||
("NH", "New Hampshire (NH)"),
|
||||
("NJ", "New Jersey (NJ)"),
|
||||
("NM", "New Mexico (NM)"),
|
||||
("NY", "New York (NY)"),
|
||||
("NC", "North Carolina (NC)"),
|
||||
("ND", "North Dakota (ND)"),
|
||||
("MP", "Northern Mariana Islands (MP)"),
|
||||
("OH", "Ohio (OH)"),
|
||||
("OK", "Oklahoma (OK)"),
|
||||
("OR", "Oregon (OR)"),
|
||||
("PA", "Pennsylvania (PA)"),
|
||||
("PR", "Puerto Rico (PR)"),
|
||||
("RI", "Rhode Island (RI)"),
|
||||
("SC", "South Carolina (SC)"),
|
||||
("SD", "South Dakota (SD)"),
|
||||
("TN", "Tennessee (TN)"),
|
||||
("TX", "Texas (TX)"),
|
||||
("UM", "United States Minor Outlying Islands (UM)"),
|
||||
("UT", "Utah (UT)"),
|
||||
("VT", "Vermont (VT)"),
|
||||
("VI", "Virgin Islands (VI)"),
|
||||
("VA", "Virginia (VA)"),
|
||||
("WA", "Washington (WA)"),
|
||||
("WV", "West Virginia (WV)"),
|
||||
("WI", "Wisconsin (WI)"),
|
||||
("WY", "Wyoming (WY)"),
|
||||
("AA", "Armed Forces Americas (AA)"),
|
||||
("AE", "Armed Forces Africa, Canada, Europe, Middle East (AE)"),
|
||||
("AP", "Armed Forces Pacific (AP)"),
|
||||
],
|
||||
max_length=2,
|
||||
null=True,
|
||||
verbose_name="state / territory",
|
||||
),
|
||||
),
|
||||
("zipcode", models.CharField(blank=True, max_length=10, null=True, verbose_name="zip code")),
|
||||
(
|
||||
"urbanization",
|
||||
models.CharField(
|
||||
blank=True, help_text="Required for Puerto Rico only", null=True, verbose_name="urbanization"
|
||||
),
|
||||
),
|
||||
(
|
||||
"security_contact_email",
|
||||
models.EmailField(blank=True, max_length=320, null=True, verbose_name="security contact e-mail"),
|
||||
),
|
||||
(
|
||||
"creator",
|
||||
models.ForeignKey(
|
||||
help_text="Associated user",
|
||||
on_delete=django.db.models.deletion.PROTECT,
|
||||
to=settings.AUTH_USER_MODEL,
|
||||
),
|
||||
),
|
||||
(
|
||||
"federal_agency",
|
||||
models.ForeignKey(
|
||||
default=registrar.models.portfolio.get_default_federal_agency,
|
||||
help_text="Associated federal agency",
|
||||
on_delete=django.db.models.deletion.PROTECT,
|
||||
to="registrar.federalagency",
|
||||
),
|
||||
),
|
||||
],
|
||||
options={
|
||||
"abstract": False,
|
||||
},
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name="domaininformation",
|
||||
name="portfolio",
|
||||
field=models.OneToOneField(
|
||||
blank=True,
|
||||
help_text="Portfolio associated with this domain",
|
||||
null=True,
|
||||
on_delete=django.db.models.deletion.PROTECT,
|
||||
related_name="DomainRequest_portfolio",
|
||||
to="registrar.portfolio",
|
||||
),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name="domainrequest",
|
||||
name="portfolio",
|
||||
field=models.OneToOneField(
|
||||
blank=True,
|
||||
help_text="Portfolio associated with this domain",
|
||||
null=True,
|
||||
on_delete=django.db.models.deletion.PROTECT,
|
||||
related_name="DomainInformation_portfolio",
|
||||
to="registrar.portfolio",
|
||||
),
|
||||
),
|
||||
]
|
37
src/registrar/migrations/0102_create_groups_v13.py
Normal file
37
src/registrar/migrations/0102_create_groups_v13.py
Normal file
|
@ -0,0 +1,37 @@
|
|||
# This migration creates the create_full_access_group and create_cisa_analyst_group groups
|
||||
# It is dependent on 0079 (which populates federal agencies)
|
||||
# If permissions on the groups need changing, edit CISA_ANALYST_GROUP_PERMISSIONS
|
||||
# in the user_group model then:
|
||||
# [NOT RECOMMENDED]
|
||||
# step 1: docker-compose exec app ./manage.py migrate --fake registrar 0035_contenttypes_permissions
|
||||
# step 2: docker-compose exec app ./manage.py migrate registrar 0036_create_groups
|
||||
# step 3: fake run the latest migration in the migrations list
|
||||
# [RECOMMENDED]
|
||||
# Alternatively:
|
||||
# step 1: duplicate the migration that loads data
|
||||
# step 2: docker-compose exec app ./manage.py migrate
|
||||
|
||||
from django.db import migrations
|
||||
from registrar.models import UserGroup
|
||||
from typing import Any
|
||||
|
||||
|
||||
# For linting: RunPython expects a function reference,
|
||||
# so let's give it one
|
||||
def create_groups(apps, schema_editor) -> Any:
|
||||
UserGroup.create_cisa_analyst_group(apps, schema_editor)
|
||||
UserGroup.create_full_access_group(apps, schema_editor)
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
dependencies = [
|
||||
("registrar", "0101_portfolio_domaininformation_portfolio_and_more"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RunPython(
|
||||
create_groups,
|
||||
reverse_code=migrations.RunPython.noop,
|
||||
atomic=True,
|
||||
),
|
||||
]
|
|
@ -16,6 +16,7 @@ from .website import Website
|
|||
from .transition_domain import TransitionDomain
|
||||
from .verified_by_staff import VerifiedByStaff
|
||||
from .waffle_flag import WaffleFlag
|
||||
from .portfolio import Portfolio
|
||||
|
||||
|
||||
__all__ = [
|
||||
|
@ -36,6 +37,7 @@ __all__ = [
|
|||
"TransitionDomain",
|
||||
"VerifiedByStaff",
|
||||
"WaffleFlag",
|
||||
"Portfolio"
|
||||
]
|
||||
|
||||
auditlog.register(Contact)
|
||||
|
@ -55,3 +57,4 @@ auditlog.register(Website)
|
|||
auditlog.register(TransitionDomain)
|
||||
auditlog.register(VerifiedByStaff)
|
||||
auditlog.register(WaffleFlag)
|
||||
auditlog.register(Portfolio)
|
||||
|
|
|
@ -59,14 +59,14 @@ class DomainInformation(TimeStampedModel):
|
|||
|
||||
|
||||
# portfolio
|
||||
# portfolio = models.OneToOneField(
|
||||
# "registrar.Portfolio",
|
||||
# on_delete=models.PROTECT,
|
||||
# null=True,
|
||||
# blank=True,
|
||||
# related_name="DomainRequest_portfolio",
|
||||
# help_text="Portfolio associated with this domain",
|
||||
# )
|
||||
portfolio = models.OneToOneField(
|
||||
"registrar.Portfolio",
|
||||
on_delete=models.PROTECT,
|
||||
null=True,
|
||||
blank=True,
|
||||
related_name="DomainRequest_portfolio",
|
||||
help_text="Portfolio associated with this domain",
|
||||
)
|
||||
|
||||
domain_request = models.OneToOneField(
|
||||
"registrar.DomainRequest",
|
||||
|
|
|
@ -287,14 +287,14 @@ class DomainRequest(TimeStampedModel):
|
|||
)
|
||||
|
||||
# portfolio
|
||||
# portfolio = models.OneToOneField(
|
||||
# "registrar.Portfolio",
|
||||
# on_delete=models.PROTECT,
|
||||
# null=True,
|
||||
# blank=True,
|
||||
# related_name="DomainInformation_portfolio",
|
||||
# help_text="Portfolio associated with this domain",
|
||||
# )
|
||||
portfolio = models.OneToOneField(
|
||||
"registrar.Portfolio",
|
||||
on_delete=models.PROTECT,
|
||||
null=True,
|
||||
blank=True,
|
||||
related_name="DomainInformation_portfolio",
|
||||
help_text="Portfolio associated with this domain",
|
||||
)
|
||||
|
||||
# This is the domain request user who created this domain request. The contact
|
||||
# information that they gave is in the `submitter` field
|
||||
|
|
|
@ -3,10 +3,12 @@ from django_fsm import FSMField # type: ignore
|
|||
|
||||
from registrar.models.domain_request import DomainRequest
|
||||
from registrar.models.federal_agency import FederalAgency
|
||||
from registrar.models.domain import State
|
||||
|
||||
from .utility.time_stamped_model import TimeStampedModel
|
||||
|
||||
def get_default_federal_agency():
|
||||
"""returns non-federal agency"""
|
||||
return FederalAgency.objects.filter(agency="Non-Federal Agency").first()
|
||||
|
||||
class Portfolio(TimeStampedModel):
|
||||
"""
|
||||
|
@ -16,11 +18,10 @@ class Portfolio(TimeStampedModel):
|
|||
|
||||
# use the short names in Django admin
|
||||
OrganizationChoices = DomainRequest.OrganizationChoices
|
||||
|
||||
StateTerritoryChoices = DomainRequest.StateTerritoryChoices
|
||||
|
||||
# creator- user foreign key- stores who created this model should get the user who is adding
|
||||
# it via django admin if there is a user (aka not done via commandline/ manual means)"""
|
||||
# TODO: auto-populate
|
||||
creator = models.ForeignKey(
|
||||
"registrar.User",
|
||||
on_delete=models.PROTECT,
|
||||
|
@ -40,18 +41,7 @@ class Portfolio(TimeStampedModel):
|
|||
on_delete=models.PROTECT,
|
||||
help_text="Associated federal agency",
|
||||
unique=False,
|
||||
default=FederalAgency.objects.filter(agency="Non-Federal Agency").first()
|
||||
)
|
||||
|
||||
# creator- user foreign key- stores who created this model
|
||||
# should get the user who is adding it via django admin if there
|
||||
# is a user (aka not done via commandline/ manual means)
|
||||
# TODO: auto-populate
|
||||
creator = models.ForeignKey(
|
||||
"registrar.User",
|
||||
on_delete=models.PROTECT,
|
||||
help_text="Associated user",
|
||||
unique=False
|
||||
default=get_default_federal_agency
|
||||
)
|
||||
|
||||
# organization type- should match organization types allowed on domain info
|
||||
|
@ -64,7 +54,7 @@ class Portfolio(TimeStampedModel):
|
|||
)
|
||||
|
||||
# organization name
|
||||
# TODO: org name will be the same as federal agency, if it is federal,
|
||||
# NOTE: org name will be the same as federal agency, if it is federal,
|
||||
# otherwise it will be the actual org name. If nothing is entered for
|
||||
# org name and it is a federal organization, have this field fill with
|
||||
# the federal agency text name.
|
||||
|
@ -90,17 +80,13 @@ class Portfolio(TimeStampedModel):
|
|||
null=True,
|
||||
blank=True,
|
||||
)
|
||||
# state (copied from domain.py -- imports enums from domain.py)
|
||||
state = FSMField(
|
||||
max_length=21,
|
||||
choices=State.choices,
|
||||
default=State.UNKNOWN,
|
||||
# cannot change state directly, particularly in Django admin
|
||||
protected=True,
|
||||
# This must be defined for custom state help messages,
|
||||
# as otherwise the view will purge the help field as it does not exist.
|
||||
help_text=" ",
|
||||
verbose_name="domain state",
|
||||
# state (copied from domain_request.py -- imports enums from domain_request.py)
|
||||
state_territory = models.CharField(
|
||||
max_length=2,
|
||||
choices=StateTerritoryChoices.choices,
|
||||
null=True,
|
||||
blank=True,
|
||||
verbose_name="state / territory",
|
||||
)
|
||||
# zipcode
|
||||
zipcode = models.CharField(
|
||||
|
@ -123,55 +109,4 @@ class Portfolio(TimeStampedModel):
|
|||
blank=True,
|
||||
verbose_name="security contact e-mail",
|
||||
max_length=320,
|
||||
)
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
# Call the parent class's save method to perform the actual save
|
||||
super().save(*args, **kwargs)
|
||||
|
||||
# TODO:
|
||||
# ---- auto-populate creator ----
|
||||
# creator- user foreign key- stores who created this model
|
||||
# should get the user who is adding it via django admin if there
|
||||
# is a user (aka not done via commandline/ manual means)
|
||||
|
||||
# ---- update organization name ----
|
||||
# org name will be the same as federal agency, if it is federal,
|
||||
# otherwise it will be the actual org name. If nothing is entered for
|
||||
# org name and it is a federal organization, have this field fill with
|
||||
# the federal agency text name.
|
||||
is_federal = self.organization_type == self.OrganizationChoices.FEDERAL
|
||||
if is_federal:
|
||||
self.organization_name = DomainRequest.OrganizationChoicesVerbose(self.organization_type)
|
||||
#NOTE: Is this what is meant by "federal agency text name?"
|
||||
|
||||
|
||||
# -----------------------------------
|
||||
# if self.user:
|
||||
# updated = False
|
||||
|
||||
# # Update first name and last name if necessary
|
||||
# if not self.user.first_name or not self.user.last_name:
|
||||
# self.user.first_name = self.first_name
|
||||
# self.user.last_name = self.last_name
|
||||
# updated = True
|
||||
|
||||
# # Update phone if necessary
|
||||
# if not self.user.phone:
|
||||
# self.user.phone = self.phone
|
||||
# updated = True
|
||||
|
||||
# # Save user if any updates were made
|
||||
# if updated:
|
||||
# self.user.save()
|
||||
# -----------------------------------
|
||||
|
||||
# def __str__(self):
|
||||
# if self.first_name or self.last_name:
|
||||
# return self.get_formatted_name()
|
||||
# elif self.email:
|
||||
# return self.email
|
||||
# elif self.pk:
|
||||
# return str(self.pk)
|
||||
# else:
|
||||
# return ""
|
||||
)
|
Loading…
Add table
Add a link
Reference in a new issue