class method to export portfolio data as dictionary as an arg to state machine
This commit is contained in:
parent
da283e4615
commit
6f6d3720bc
@ -145,7 +145,7 @@ def do_work(fn, task, csp, **kwargs):
|
|||||||
def do_provision_portfolio(csp: CloudProviderInterface, portfolio_id=None):
|
def do_provision_portfolio(csp: CloudProviderInterface, portfolio_id=None):
|
||||||
portfolio = Portfolios.get_for_update(portfolio_id)
|
portfolio = Portfolios.get_for_update(portfolio_id)
|
||||||
fsm = Portfolios.get_or_create_state_machine(portfolio)
|
fsm = Portfolios.get_or_create_state_machine(portfolio)
|
||||||
fsm.trigger_next_transition()
|
fsm.trigger_next_transition(csp_data=portfolio.to_dictionary())
|
||||||
|
|
||||||
|
|
||||||
@celery.task(bind=True, base=RecordFailure)
|
@celery.task(bind=True, base=RecordFailure)
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
import re
|
||||||
|
|
||||||
from sqlalchemy import Column, String
|
from sqlalchemy import Column, String
|
||||||
from sqlalchemy.orm import relationship
|
from sqlalchemy.orm import relationship
|
||||||
from sqlalchemy.types import ARRAY
|
from sqlalchemy.types import ARRAY
|
||||||
@ -6,6 +8,7 @@ from itertools import chain
|
|||||||
from atst.models.base import Base
|
from atst.models.base import Base
|
||||||
import atst.models.types as types
|
import atst.models.types as types
|
||||||
import atst.models.mixins as mixins
|
import atst.models.mixins as mixins
|
||||||
|
from atst.models.task_order import TaskOrder
|
||||||
from atst.models.portfolio_role import PortfolioRole, Status as PortfolioRoleStatus
|
from atst.models.portfolio_role import PortfolioRole, Status as PortfolioRoleStatus
|
||||||
from atst.domain.permission_sets import PermissionSets
|
from atst.domain.permission_sets import PermissionSets
|
||||||
from atst.utils import first_or_none
|
from atst.utils import first_or_none
|
||||||
@ -153,6 +156,48 @@ class Portfolio(
|
|||||||
def application_id(self):
|
def application_id(self):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
def to_dictionary(self):
|
||||||
|
ppoc = self.owner
|
||||||
|
user_id = f"{ppoc.first_name[0]}{ppoc.last_name}".lower()
|
||||||
|
domain_name = re.sub("[^0-9a-zA-Z]+", "", self.name).lower()
|
||||||
|
portfolio_data = {
|
||||||
|
"user_id": user_id,
|
||||||
|
"password": "jklfsdNCVD83nklds2#202", # pragma: allowlist secret
|
||||||
|
"domain_name": domain_name,
|
||||||
|
"first_name": ppoc.first_name,
|
||||||
|
"last_name": ppoc.last_name,
|
||||||
|
"country_code": "US",
|
||||||
|
"password_recovery_email_address": ppoc.email,
|
||||||
|
"address": { # TODO: TBD if we're sourcing this from data or config
|
||||||
|
"company_name": "",
|
||||||
|
"address_line_1": "",
|
||||||
|
"city": "",
|
||||||
|
"region": "",
|
||||||
|
"country": "",
|
||||||
|
"postal_code": "",
|
||||||
|
},
|
||||||
|
"billing_profile_display_name": "My Billing Profile",
|
||||||
|
}
|
||||||
|
|
||||||
|
try:
|
||||||
|
initial_task_order: TaskOrder = self.task_orders[0]
|
||||||
|
initial_clin = initial_task_order.sorted_clins[0]
|
||||||
|
portfolio_data.update(
|
||||||
|
{
|
||||||
|
"initial_clin_amount": initial_clin.obligated_amount,
|
||||||
|
"initial_clin_start_date": initial_clin.start_date.strftime(
|
||||||
|
"%Y/%m/%d"
|
||||||
|
),
|
||||||
|
"initial_clin_end_date": initial_clin.end_date.strftime("%Y/%m/%d"),
|
||||||
|
"initial_clin_type": initial_clin.number,
|
||||||
|
"initial_task_order_id": initial_task_order.number,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
except IndexError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
return portfolio_data
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "<Portfolio(name='{}', user_count='{}', id='{}')>".format(
|
return "<Portfolio(name='{}', user_count='{}', id='{}')>".format(
|
||||||
self.name, self.user_count, self.id
|
self.name, self.user_count, self.id
|
||||||
|
@ -99,6 +99,8 @@ class PortfolioStateMachine(
|
|||||||
def trigger_next_transition(self, **kwargs):
|
def trigger_next_transition(self, **kwargs):
|
||||||
state_obj = self.machine.get_state(self.state)
|
state_obj = self.machine.get_state(self.state)
|
||||||
|
|
||||||
|
csp_data = kwargs.get("csp_data", {})
|
||||||
|
|
||||||
if state_obj.is_system:
|
if state_obj.is_system:
|
||||||
if self.current_state in (FSMStates.UNSTARTED, FSMStates.STARTING):
|
if self.current_state in (FSMStates.UNSTARTED, FSMStates.STARTING):
|
||||||
# call the first trigger availabe for these two system states
|
# call the first trigger availabe for these two system states
|
||||||
|
Loading…
x
Reference in New Issue
Block a user