Merge branch 'main' into backup/2594-design-review

This commit is contained in:
zandercymatics 2024-11-08 11:22:46 -07:00
commit af3acbc773
No known key found for this signature in database
GPG key ID: FF4636ABEC9682B7
5 changed files with 85 additions and 25 deletions

View file

@ -1,11 +1,9 @@
name: Clone Staging Database
on:
# these will be uncommented after testing
# ----
# schedule:
# # Run daily at 2:00 PM EST
# - cron: '0 * * * *'
schedule:
# Run daily at 2:00 PM EST
- cron: '0 * * * *'
# Allow manual triggering
workflow_dispatch:
@ -16,7 +14,7 @@ env:
jobs:
clone-database:
runs-on: ubuntu-latest
runs-on: ubuntu-24.04
env:
CF_USERNAME: ${{ secrets.CF_MS_USERNAME }}
CF_PASSWORD: ${{ secrets.CF_MS_PASSWORD }}
@ -26,9 +24,10 @@ jobs:
# install cf cli and other tools
wget -q -O - https://packages.cloudfoundry.org/debian/cli.cloudfoundry.org.key | sudo gpg --dearmor -o /usr/share/keyrings/cli.cloudfoundry.org.gpg
echo "deb [signed-by=/usr/share/keyrings/cli.cloudfoundry.org.gpg] https://packages.cloudfoundry.org/debian stable main" | sudo tee /etc/apt/sources.list.d/cloudfoundry-cli.list
sudo apt-get update
sudo apt-get install cf8-cli postgresql-client-common
sudo apt-get install cf8-cli
# install cg-manage-rds tool
pip install git+https://github.com/cloud-gov/cg-manage-rds.git
@ -41,7 +40,8 @@ jobs:
cf share-service getgov-$DESTINATION_ENVIRONMENT-database -s $SOURCE_ENVIRONMENT
# clone from source to destination
cg-manage-rds clone getgov-$DESTINATION_ENVIRONMENT-database getgov-$SOURCE_ENVIRONMENT-database
# unshare the service
cf unshare-service getgov-$DESTINATION_ENVIRONMENT-database -s $SOURCE_ENVIRONMENT
cf target -s $SOURCE_ENVIRONMENT
cg-manage-rds clone --roptions "--clean --if-exists" getgov-$SOURCE_ENVIRONMENT-database getgov-$DESTINATION_ENVIRONMENT-database
- name: Cleanup
if: always()
run: cf unshare-service getgov-$DESTINATION_ENVIRONMENT-database -s $SOURCE_ENVIRONMENT -f

View file

@ -1640,6 +1640,70 @@ class DomainRequestAdmin(ListHeaderAdmin, ImportExportModelAdmin):
def lookups(self, request, model_admin):
return DomainRequest.DomainRequestStatus.choices
class GenericOrgFilter(admin.SimpleListFilter):
"""Custom Generic Organization filter that accomodates portfolio feature.
If we have a portfolio, use the portfolio's organization. If not, use the
organization in the Domain Request object."""
title = "generic organization"
parameter_name = "converted_generic_orgs"
def lookups(self, request, model_admin):
converted_generic_orgs = set()
for domain_request in DomainRequest.objects.all():
converted_generic_org = domain_request.converted_generic_org_type
if converted_generic_org:
converted_generic_orgs.add(converted_generic_org)
return sorted((org, org) for org in converted_generic_orgs)
# Filter queryset
def queryset(self, request, queryset):
if self.value(): # Check if a generic org is selected in the filter
return queryset.filter(
# Filter based on the generic org value returned by converted_generic_org_type
id__in=[
domain_request.id
for domain_request in queryset
if domain_request.converted_generic_org_type
and domain_request.converted_generic_org_type == self.value()
]
)
return queryset
class FederalTypeFilter(admin.SimpleListFilter):
"""Custom Federal Type filter that accomodates portfolio feature.
If we have a portfolio, use the portfolio's federal type. If not, use the
organization in the Domain Request object."""
title = "federal Type"
parameter_name = "converted_federal_types"
def lookups(self, request, model_admin):
converted_federal_types = set()
for domain_request in DomainRequest.objects.all():
converted_federal_type = domain_request.converted_federal_type
if converted_federal_type:
converted_federal_types.add(converted_federal_type)
return sorted((type, type) for type in converted_federal_types)
# Filter queryset
def queryset(self, request, queryset):
if self.value(): # Check if federal Type is selected in the filter
return queryset.filter(
# Filter based on the federal type returned by converted_federal_type
id__in=[
domain_request.id
for domain_request in queryset
if domain_request.converted_federal_type
and domain_request.converted_federal_type == self.value()
]
)
return queryset
class InvestigatorFilter(admin.SimpleListFilter):
"""Custom investigator filter that only displays users with the manager role"""
@ -1762,8 +1826,8 @@ class DomainRequestAdmin(ListHeaderAdmin, ImportExportModelAdmin):
# Filters
list_filter = (
StatusListFilter,
"generic_org_type",
"federal_type",
GenericOrgFilter,
FederalTypeFilter,
ElectionOfficeFilter,
"rejection_reason",
InvestigatorFilter,
@ -1876,7 +1940,7 @@ class DomainRequestAdmin(ListHeaderAdmin, ImportExportModelAdmin):
# Read only that we'll leverage for CISA Analysts
analyst_readonly_fields = [
"converted_federal_agency",
"federal_agency",
"creator",
"about_your_organization",
"requested_domain",

View file

@ -576,7 +576,7 @@ class TestDomainRequestAdmin(MockEppLib):
response = self.client.get("/admin/registrar/domainrequest/?generic_org_type__exact=federal")
# There are 2 template references to Federal (4) and two in the results data
# of the request
self.assertContains(response, "Federal", count=52)
self.assertContains(response, "Federal", count=51)
# This may be a bit more robust
self.assertContains(response, '<td class="field-converted_generic_org_type">federal</td>', count=1)
# Now let's make sure the long description does not exist
@ -1696,7 +1696,7 @@ class TestDomainRequestAdmin(MockEppLib):
"alternative_domains",
"is_election_board",
"status_history",
"converted_federal_agency",
"federal_agency",
"creator",
"about_your_organization",
"requested_domain",
@ -1935,8 +1935,8 @@ class TestDomainRequestAdmin(MockEppLib):
readonly_fields = self.admin.get_list_filter(request)
expected_fields = (
DomainRequestAdmin.StatusListFilter,
"generic_org_type",
"federal_type",
DomainRequestAdmin.GenericOrgFilter,
DomainRequestAdmin.FederalTypeFilter,
DomainRequestAdmin.ElectionOfficeFilter,
"rejection_reason",
DomainRequestAdmin.InvestigatorFilter,

View file

@ -682,7 +682,6 @@ class ExportDataTest(MockDbForIndividualTests, MockEppLib):
def test_domain_request_growth(self):
"""Shows submitted requests within a date range, sorted"""
# Remove "Submitted at" because we can't guess this immutable, dynamically generated test data
print("we are in here")
columns = [
"Domain request",
"Domain type",
@ -693,7 +692,6 @@ class ExportDataTest(MockDbForIndividualTests, MockEppLib):
# Create a CSV file in memory
csv_file = StringIO()
# Call the export functions
print("something")
DomainRequestGrowth.export_data_to_csv(
csv_file,
start_date=self.start_date.strftime("%Y-%m-%d"),
@ -701,11 +699,9 @@ class ExportDataTest(MockDbForIndividualTests, MockEppLib):
)
# Reset the CSV file's position to the beginning
csv_file.seek(0)
print("uuuuu")
print(csv_file)
# Read the content into a variable
csv_content = csv_file.read()
print(csv_content)
expected_content = (
"Domain request,Domain type,Federal type\n"
"city3.gov,Federal,Executive\n"

View file

@ -1269,7 +1269,7 @@ class DomainRequestExport(BaseExport):
human_readable_federal_type = BranchChoices.get_branch_label(federal_type) if federal_type else None
# Handle the org_type field
org_type = model.get("generic_org_type")
org_type = model.get("generic_org_type") or model.get("organization_type")
human_readable_org_type = DomainRequest.OrganizationChoices.get_org_label(org_type) if org_type else None
# Handle the status field. Defaults to the wrong format.