mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-07-27 04:58:42 +02:00
simplify some things
This commit is contained in:
parent
b4176e4f86
commit
c969487bfc
1 changed files with 15 additions and 39 deletions
|
@ -30,8 +30,8 @@ class Command(BaseCommand):
|
||||||
self.failed_portfolios = set()
|
self.failed_portfolios = set()
|
||||||
self.added_managers = set()
|
self.added_managers = set()
|
||||||
self.added_invitations = set()
|
self.added_invitations = set()
|
||||||
|
self.skipped_invitations = set()
|
||||||
self.failed_managers = set()
|
self.failed_managers = set()
|
||||||
self.failed_invitations = set()
|
|
||||||
|
|
||||||
def add_arguments(self, parser):
|
def add_arguments(self, parser):
|
||||||
"""Add command line arguments to create federal portfolios.
|
"""Add command line arguments to create federal portfolios.
|
||||||
|
@ -162,8 +162,8 @@ class Command(BaseCommand):
|
||||||
|
|
||||||
TerminalHelper.log_script_run_summary(
|
TerminalHelper.log_script_run_summary(
|
||||||
self.added_invitations,
|
self.added_invitations,
|
||||||
self.failed_invitations,
|
[],
|
||||||
[], # can't skip invitations, can only add or fail
|
self.skipped_invitations,
|
||||||
log_header="----- INVITATIONS ADDED -----",
|
log_header="----- INVITATIONS ADDED -----",
|
||||||
debug=False,
|
debug=False,
|
||||||
display_as_str=True,
|
display_as_str=True,
|
||||||
|
@ -237,45 +237,21 @@ class Command(BaseCommand):
|
||||||
|
|
||||||
def create_portfolio_invitation(self, portfolio: Portfolio, email: str):
|
def create_portfolio_invitation(self, portfolio: Portfolio, email: str):
|
||||||
"""
|
"""
|
||||||
Create a portfolio invitation for the given user.
|
Create a portfolio invitation for the given email.
|
||||||
If the user already has a portfolio invitation, retreive their invitation and create a portfolio permission.
|
|
||||||
"""
|
"""
|
||||||
try:
|
_, created = PortfolioInvitation.objects.get_or_create(
|
||||||
user = User.objects.get(email=email)
|
portfolio=portfolio,
|
||||||
_, created = PortfolioInvitation.objects.get_or_create(
|
email=email,
|
||||||
portfolio=portfolio,
|
defaults={"status": PortfolioInvitation.PortfolioInvitationStatus.INVITED,
|
||||||
user=user,
|
"roles": [UserPortfolioRoleChoices.ORGANIZATION_MEMBER]
|
||||||
defaults={"status": PortfolioInvitation.PortfolioInvitationStatus.INVITED},
|
},
|
||||||
)
|
)
|
||||||
if created:
|
if created:
|
||||||
logger.info(f"Created portfolio invitation for '{user}' to portfolio '{portfolio}'")
|
|
||||||
else:
|
|
||||||
logger.info(f"Retrieved existing portfolio invitation for '{user}' to portfolio '{portfolio}'")
|
|
||||||
|
|
||||||
# Assign portfolio permissions
|
|
||||||
_, created = UserPortfolioPermission.objects.get_or_create(
|
|
||||||
portfolio=portfolio,
|
|
||||||
user=user,
|
|
||||||
defaults={"role": UserPortfolioRoleChoices.ORGANIZATION_MEMBER},
|
|
||||||
)
|
|
||||||
if created:
|
|
||||||
logger.info(f"Created portfolio permission for '{user}' to portfolio '{portfolio}'")
|
|
||||||
else:
|
|
||||||
logger.info(f"Retrieved existing portfolio permission for '{user}' to portfolio '{portfolio}'")
|
|
||||||
|
|
||||||
self.added_invitations.add(user)
|
|
||||||
except User.DoesNotExist:
|
|
||||||
PortfolioInvitation.objects.get_or_create(
|
|
||||||
portfolio=portfolio,
|
|
||||||
email=email,
|
|
||||||
defaults={"status": PortfolioInvitation.PortfolioInvitationStatus.INVITED},
|
|
||||||
)
|
|
||||||
self.added_invitations.add(email)
|
self.added_invitations.add(email)
|
||||||
logger.info(f"Created portfolio invitation for '{email}' to portfolio '{portfolio}'")
|
logger.info(f"Created portfolio invitation for '{email}' to portfolio '{portfolio}'")
|
||||||
except Exception as exc:
|
else:
|
||||||
self.failed_invitations.add(email)
|
self.skipped_invitations.add(email)
|
||||||
logger.error(exc, exc_info=True)
|
logger.info(f"Found existing portfolio invitation for '{email}' to portfolio '{portfolio}'")
|
||||||
logger.error(f"Failed to create portfolio invitation for '{email}' to portfolio '{portfolio}'")
|
|
||||||
|
|
||||||
def post_process_started_domain_requests(self, agencies, portfolios):
|
def post_process_started_domain_requests(self, agencies, portfolios):
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue