diff --git a/docs/operations/data_migration.md b/docs/operations/data_migration.md index 8185922a4..402489a47 100644 --- a/docs/operations/data_migration.md +++ b/docs/operations/data_migration.md @@ -894,32 +894,32 @@ Example: `cf ssh getgov-za` #### Step 5: Running the script To create a specific portfolio: -```./manage.py create_federal_portfolio --agency_name "{federal_agency_name}" --both``` +```./manage.py create_federal_portfolio --agency_name "{federal_agency_name}" --parse_domains --parse_requests --parse_managers``` Example (only requests): `./manage.py create_federal_portfolio "AMTRAK" --parse_requests` To create a portfolios for all federal agencies in a branch: -```./manage.py create_federal_portfolio --branch "{executive|legislative|judicial}" --both``` +```./manage.py create_federal_portfolio --branch "{executive|legislative|judicial}" --parse_domains --parse_requests --parse_managers``` Example (only requests): `./manage.py create_federal_portfolio --branch "executive" --parse_requests` ### Running locally #### Step 1: Running the script -```docker-compose exec app ./manage.py create_federal_portfolio --agency_name "{federal_agency_name}" --both``` +```docker-compose exec app ./manage.py create_federal_portfolio --agency_name "{federal_agency_name}" --parse_domains``` ##### Parameters | | Parameter | Description | |:-:|:---------------------------- |:-------------------------------------------------------------------------------------------| | 1 | **agency_name** | Name of the FederalAgency record surrounded by quotes. For instance,"AMTRAK". | | 2 | **branch** | Creates a portfolio for each federal agency in a branch: executive, legislative, judicial | -| 3 | **both** | If True, runs parse_requests and parse_domains. | -| 4 | **parse_requests** | If True, then the created portfolio is added to all related DomainRequests. | -| 5 | **parse_domains** | If True, then the created portfolio is added to all related Domains. | -| 6 | **add_managers** | If True, then the created portfolio will add all managers of the portfolio domains as members of the portfolio, including invited managers. | -| 7 | **skip_existing_portfolios** | If True, then the script will only create suborganizations, modify DomainRequest, and modify DomainInformation records only when creating a new portfolio. Use this flag when you do not want to modify existing records. | +| 3 | **parse_requests** | If True, then the created portfolio is added to all related DomainRequests. | +| 4 | **parse_domains** | If True, then the created portfolio is added to all related Domains. | +| 5 | **parse_members** | If True, then the created portfolio will add all managers of the portfolio domains as members of the portfolio, including invited managers. | +| 6 | **skip_existing_portfolios** | If True, then the script will only create suborganizations, modify DomainRequest, and modify DomainInformation records only when creating a new portfolio. Use this flag when you do not want to modify existing records. | +| 7 | **Debug** | Increases log verbosity | - Parameters #1-#2: Either `--agency_name` or `--branch` must be specified. Not both. -- Parameters #2-#3, you cannot use `--both` while using these. You must specify either `--parse_requests` or `--parse_domains` seperately. While all of these parameters are optional in that you do not need to specify all of them, -you must specify at least one to run this script. +- Parameters #3-#5, while all of these parameters are optional in that you do not need to specify all of them, +you must specify at least one to run this script. You can also chain all of them together. ## Patch suborganizations diff --git a/src/registrar/management/commands/create_federal_portfolio.py b/src/registrar/management/commands/create_federal_portfolio.py index 2113ed97a..aaee6fbde 100644 --- a/src/registrar/management/commands/create_federal_portfolio.py +++ b/src/registrar/management/commands/create_federal_portfolio.py @@ -257,7 +257,7 @@ class Command(BaseCommand): def print_final_run_summary(self, parse_domains, parse_requests, parse_managers, debug): self.portfolio_changes.print_script_run_summary( - no_changes_message="\n||============= No portfolios changed. =============||", + no_changes_message="||============= No portfolios changed. =============||", debug=debug, log_header="============= PORTFOLIOS =============", skipped_header="----- SOME PORTFOLIOS WERENT CREATED (BUT OTHER RECORDS ARE STILL PROCESSED) -----", @@ -265,7 +265,7 @@ class Command(BaseCommand): display_as_str=True, ) self.suborganization_changes.print_script_run_summary( - no_changes_message="\n||============= No suborganizations changed. =============||", + no_changes_message="||============= No suborganizations changed. =============||", debug=debug, log_header="============= SUBORGANIZATIONS =============", skipped_header="----- SUBORGANIZATIONS SKIPPED (SAME NAME AS PORTFOLIO NAME) -----", @@ -507,7 +507,7 @@ class Command(BaseCommand): # Clear the federal agency for started domain requests agency_name = normalize_string(domain_request.federal_agency.agency) portfolio_name = normalize_string(portfolio.organization_name) - if not domain_request.portfolio and agency_name == portfolio_name: + if agency_name == portfolio_name: domain_request.federal_agency = None logger.info(f"Set federal agency on started domain request '{domain_request}' to None.") updated_domain_requests.add(domain_request) diff --git a/src/registrar/tests/test_management_scripts.py b/src/registrar/tests/test_management_scripts.py index 9fdd5ba8e..5d9dc6759 100644 --- a/src/registrar/tests/test_management_scripts.py +++ b/src/registrar/tests/test_management_scripts.py @@ -1473,7 +1473,7 @@ class TestCreateFederalPortfolio(TestCase): generic_org_type=DomainRequest.OrganizationChoices.CITY, federal_agency=self.federal_agency, user=self.user, - organization_name="Testorg" + organization_name="Testorg", ) self.domain_request.approve() self.domain_info = DomainInformation.objects.filter(domain_request=self.domain_request).get() @@ -1875,7 +1875,9 @@ class TestCreateFederalPortfolio(TestCase): UserDomainRole.objects.create(user=manager2, domain=self.domain, role=UserDomainRole.Roles.MANAGER) # Run the management command - self.run_create_federal_portfolio(agency_name=self.federal_agency.agency, parse_domains=True, parse_managers=True) + self.run_create_federal_portfolio( + agency_name=self.federal_agency.agency, parse_domains=True, parse_managers=True + ) # Check that the portfolio was created self.portfolio = Portfolio.objects.get(federal_agency=self.federal_agency) @@ -1898,7 +1900,9 @@ class TestCreateFederalPortfolio(TestCase): ) # Run the management command - self.run_create_federal_portfolio(agency_name=self.federal_agency.agency, parse_domains=True, parse_managers=True) + self.run_create_federal_portfolio( + agency_name=self.federal_agency.agency, parse_domains=True, parse_managers=True + ) # Check that the portfolio was created self.portfolio = Portfolio.objects.get(federal_agency=self.federal_agency) @@ -1995,9 +1999,9 @@ class TestCreateFederalPortfolio(TestCase): skip_existing_portfolios=True, ) - # Check that managers were added to the portfolio + # Check that managers weren't added to the portfolio permissions = UserPortfolioPermission.objects.filter(portfolio=self.portfolio, user__in=[manager1, manager2]) - self.assertEqual(permissions.count(), 2) + self.assertEqual(permissions.count(), 0) for perm in permissions: self.assertIn(UserPortfolioRoleChoices.ORGANIZATION_MEMBER, perm.roles)