mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-05-16 09:37:03 +02:00
Add conditionals for domain managers
This commit is contained in:
parent
28d37fc869
commit
8ed88aa137
1 changed files with 29 additions and 24 deletions
|
@ -14,14 +14,14 @@ from registrar.utility.enums import DefaultEmail
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
def write_header(writer, columns, max_dm_count):
|
def write_header(writer, columns, max_dm_count, get_domain_managers):
|
||||||
"""
|
"""
|
||||||
Receives params from the parent methods and outputs a CSV with a header row.
|
Receives params from the parent methods and outputs a CSV with a header row.
|
||||||
Works with write_header as long as the same writer object is passed.
|
Works with write_header as long as the same writer object is passed.
|
||||||
"""
|
"""
|
||||||
|
if get_domain_managers:
|
||||||
for i in range(1, max_dm_count + 1):
|
for i in range(1, max_dm_count + 1):
|
||||||
columns.append(f"Domain manager email {i}")
|
columns.append(f"Domain manager email {i}")
|
||||||
|
|
||||||
writer.writerow("hello")
|
writer.writerow("hello")
|
||||||
writer.writerow(columns)
|
writer.writerow(columns)
|
||||||
|
@ -48,7 +48,7 @@ def get_domain_infos(filter_condition, sort_fields):
|
||||||
return domain_infos_cleaned
|
return domain_infos_cleaned
|
||||||
|
|
||||||
|
|
||||||
def parse_row(columns, domain_info: DomainInformation, security_emails_dict=None):
|
def parse_row(columns, domain_info: DomainInformation, get_domain_managers, security_emails_dict=None):
|
||||||
"""Given a set of columns, generate a new row from cleaned column data"""
|
"""Given a set of columns, generate a new row from cleaned column data"""
|
||||||
|
|
||||||
# Domain should never be none when parsing this information
|
# Domain should never be none when parsing this information
|
||||||
|
@ -97,12 +97,13 @@ def parse_row(columns, domain_info: DomainInformation, security_emails_dict=None
|
||||||
"Deleted": domain.deleted,
|
"Deleted": domain.deleted,
|
||||||
}
|
}
|
||||||
|
|
||||||
# Get each domain managers email and add to list
|
if get_domain_managers:
|
||||||
dm_emails = [dm.email for dm in domain.permissions]
|
# Get each domain managers email and add to list
|
||||||
|
dm_emails = [dm.email for dm in domain.permissions]
|
||||||
|
|
||||||
# Matching header for domain managers to be dynamic
|
# Matching header for domain managers to be dynamic
|
||||||
for i, dm_email in enumerate(dm_emails, start=1):
|
for i, dm_email in enumerate(dm_emails, start=1):
|
||||||
FIELDS[f"Domain Manager email {i}":dm_email]
|
FIELDS[f"Domain Manager email {i}":dm_email]
|
||||||
|
|
||||||
row = [FIELDS.get(column, "") for column in columns]
|
row = [FIELDS.get(column, "") for column in columns]
|
||||||
return row
|
return row
|
||||||
|
@ -113,12 +114,17 @@ def write_body(
|
||||||
columns,
|
columns,
|
||||||
sort_fields,
|
sort_fields,
|
||||||
filter_condition,
|
filter_condition,
|
||||||
|
get_domain_managers=False,
|
||||||
):
|
):
|
||||||
"""
|
"""
|
||||||
Receives params from the parent methods and outputs a CSV with fltered and sorted domains.
|
Receives params from the parent methods and outputs a CSV with fltered and sorted domains.
|
||||||
Works with write_header as longas the same writer object is passed.
|
Works with write_header as longas the same writer object is passed.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
# We only want to write the domain manager information for export_thing_here so we have to make it conditional
|
||||||
|
|
||||||
|
# Trying to make the domain managers logic conditional
|
||||||
|
|
||||||
# Get the domainInfos
|
# Get the domainInfos
|
||||||
all_domain_infos = get_domain_infos(filter_condition, sort_fields)
|
all_domain_infos = get_domain_infos(filter_condition, sort_fields)
|
||||||
|
|
||||||
|
@ -151,12 +157,12 @@ def write_body(
|
||||||
rows = []
|
rows = []
|
||||||
for domain_info in page.object_list:
|
for domain_info in page.object_list:
|
||||||
# Get count of all the domain managers for an account
|
# Get count of all the domain managers for an account
|
||||||
dm_count = len(domain_info.domain.permissions)
|
if get_domain_managers:
|
||||||
if dm_count > max_dm_count:
|
dm_count = len(domain_info.domain.permissions)
|
||||||
max_dm_count = dm_count
|
if dm_count > max_dm_count:
|
||||||
|
max_dm_count = dm_count
|
||||||
try:
|
try:
|
||||||
row = parse_row(columns, domain_info, security_emails_dict)
|
row = parse_row(columns, domain_info, security_emails_dict, get_domain_managers)
|
||||||
rows.append(row)
|
rows.append(row)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
# This should not happen. If it does, just skip this row.
|
# This should not happen. If it does, just skip this row.
|
||||||
|
@ -165,8 +171,8 @@ def write_body(
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# We only want this to run once just for the column header
|
# We only want this to run once just for the column header
|
||||||
if paginator_ran is False:
|
if paginator_ran is False and "Domain name" in columns:
|
||||||
write_header(writer, columns, max_dm_count)
|
write_header(writer, columns, max_dm_count, get_domain_managers)
|
||||||
|
|
||||||
writer.writerows(rows)
|
writer.writerows(rows)
|
||||||
paginator_ran = True
|
paginator_ran = True
|
||||||
|
@ -189,14 +195,9 @@ def export_data_type_to_csv(csv_file):
|
||||||
"AO",
|
"AO",
|
||||||
"AO email",
|
"AO email",
|
||||||
"Security contact email",
|
"Security contact email",
|
||||||
"Domain Manager email",
|
# For domain manager we are pass it in as a parameter below in write_body
|
||||||
]
|
]
|
||||||
|
|
||||||
# STUCK HERE
|
|
||||||
|
|
||||||
# So the problem is we don't even have access to domains or a count here.
|
|
||||||
# We could pass it in, but it's messy. Maybe helper function? Seems repetitive
|
|
||||||
|
|
||||||
# Coalesce is used to replace federal_type of None with ZZZZZ
|
# Coalesce is used to replace federal_type of None with ZZZZZ
|
||||||
sort_fields = [
|
sort_fields = [
|
||||||
"organization_type",
|
"organization_type",
|
||||||
|
@ -212,7 +213,7 @@ def export_data_type_to_csv(csv_file):
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
# write_header(writer, columns)
|
# write_header(writer, columns)
|
||||||
write_body(writer, columns, sort_fields, filter_condition)
|
write_body(writer, columns, sort_fields, filter_condition, True)
|
||||||
|
|
||||||
|
|
||||||
def export_data_full_to_csv(csv_file):
|
def export_data_full_to_csv(csv_file):
|
||||||
|
@ -345,5 +346,9 @@ def export_data_growth_to_csv(csv_file, start_date, end_date):
|
||||||
}
|
}
|
||||||
|
|
||||||
# write_header(writer, columns)
|
# write_header(writer, columns)
|
||||||
|
# Domains that got created
|
||||||
write_body(writer, columns, sort_fields, filter_condition)
|
write_body(writer, columns, sort_fields, filter_condition)
|
||||||
|
# Domains that got deleted
|
||||||
|
# Have a way to skip the header for this one
|
||||||
|
|
||||||
write_body(writer, columns, sort_fields_for_deleted_domains, filter_condition_for_deleted_domains)
|
write_body(writer, columns, sort_fields_for_deleted_domains, filter_condition_for_deleted_domains)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue