Philip/refactor signup steps.

This commit is contained in:
Philip Wafula 2021-06-07 07:47:02 +00:00
parent 65f722b291
commit 77d9936e39
3 changed files with 21 additions and 18 deletions

View File

@ -270,7 +270,24 @@ def process_display_user_metadata(user: Account, display_key: str):
products=products products=products
) )
else: else:
raise MetadataNotFoundError(f'Expected person metadata but found none in cache for key: {key}') # TODO [Philip]: All these translations could be moved to translation files.
logg.warning(f'Expected person metadata but found none in cache for key: {key}')
absent = ''
if user.preferred_language == 'en':
absent = 'Not provided'
elif user.preferred_language == 'sw':
absent = 'Haijawekwa'
return translation_for(
key=display_key,
preferred_language=user.preferred_language,
full_name=absent,
gender=absent,
location=absent,
products=absent
)
def process_account_statement(user: Account, display_key: str, ussd_session: dict): def process_account_statement(user: Account, display_key: str, ussd_session: dict):

View File

@ -11,7 +11,7 @@ from cic_ussd.balance import BalanceManager, compute_operational_balance
from cic_ussd.chain import Chain from cic_ussd.chain import Chain
from cic_ussd.db.models.account import AccountStatus, Account from cic_ussd.db.models.account import AccountStatus, Account
from cic_ussd.operations import save_to_in_memory_ussd_session_data from cic_ussd.operations import save_to_in_memory_ussd_session_data
from cic_ussd.phone_number import get_user_by_phone_number from cic_ussd.phone_number import get_user_by_phone_number, process_phone_number
from cic_ussd.processor import retrieve_token_symbol from cic_ussd.processor import retrieve_token_symbol
from cic_ussd.redis import create_cached_data_key, get_cached_data from cic_ussd.redis import create_cached_data_key, get_cached_data
from cic_ussd.transactions import OutgoingTransactionProcessor from cic_ussd.transactions import OutgoingTransactionProcessor
@ -30,7 +30,7 @@ def is_valid_recipient(state_machine_data: Tuple[str, dict, Account]) -> bool:
""" """
user_input, ussd_session, user = state_machine_data user_input, ussd_session, user = state_machine_data
recipient = get_user_by_phone_number(phone_number=user_input) recipient = get_user_by_phone_number(phone_number=user_input)
is_not_initiator = user_input != user.phone_number is_not_initiator = process_phone_number(user_input, 'KE') != user.phone_number
has_active_account_status = user.get_account_status() == AccountStatus.ACTIVE.name has_active_account_status = user.get_account_status() == AccountStatus.ACTIVE.name
return is_not_initiator and has_active_account_status and recipient is not None return is_not_initiator and has_active_account_status and recipient is not None

View File

@ -36,26 +36,12 @@
"source": "initial_pin_entry", "source": "initial_pin_entry",
"dest": "exit_invalid_pin" "dest": "exit_invalid_pin"
}, },
{
"trigger": "scan_data",
"source": "initial_pin_confirmation",
"dest": "start",
"conditions": [
"cic_ussd.state_machine.logic.pin.pins_match",
"cic_ussd.state_machine.logic.validator.has_cached_user_metadata"
],
"after": [
"cic_ussd.state_machine.logic.pin.complete_pin_change",
"cic_ussd.state_machine.logic.user.get_user_metadata",
"cic_ussd.state_machine.logic.user.update_account_status_to_active"
]
},
{ {
"trigger": "scan_data", "trigger": "scan_data",
"source": "initial_pin_confirmation", "source": "initial_pin_confirmation",
"unless": "cic_ussd.state_machine.logic.validator.has_cached_user_metadata", "unless": "cic_ussd.state_machine.logic.validator.has_cached_user_metadata",
"conditions": "cic_ussd.state_machine.logic.pin.pins_match", "conditions": "cic_ussd.state_machine.logic.pin.pins_match",
"dest": "enter_given_name", "dest": "start",
"after": [ "after": [
"cic_ussd.state_machine.logic.pin.complete_pin_change", "cic_ussd.state_machine.logic.pin.complete_pin_change",
"cic_ussd.state_machine.logic.user.update_account_status_to_active" "cic_ussd.state_machine.logic.user.update_account_status_to_active"