Adds accommodations for guardianship data.
This commit is contained in:
parent
aa734628ea
commit
5861dae247
@ -24,6 +24,8 @@ def upgrade():
|
|||||||
sa.Column('preferred_language', sa.String(), nullable=True),
|
sa.Column('preferred_language', sa.String(), nullable=True),
|
||||||
sa.Column('password_hash', sa.String(), nullable=True),
|
sa.Column('password_hash', sa.String(), nullable=True),
|
||||||
sa.Column('failed_pin_attempts', sa.Integer(), nullable=False),
|
sa.Column('failed_pin_attempts', sa.Integer(), nullable=False),
|
||||||
|
sa.Column('guardians', sa.String(), nullable=True),
|
||||||
|
sa.Column('guardian_quora', sa.Integer(), nullable=False),
|
||||||
sa.Column('status', sa.Integer(), nullable=False),
|
sa.Column('status', sa.Integer(), nullable=False),
|
||||||
sa.Column('created', sa.DateTime(), nullable=False),
|
sa.Column('created', sa.DateTime(), nullable=False),
|
||||||
sa.Column('updated', sa.DateTime(), nullable=False),
|
sa.Column('updated', sa.DateTime(), nullable=False),
|
||||||
|
@ -4,6 +4,8 @@ import json
|
|||||||
# external imports
|
# external imports
|
||||||
from cic_eth.api import Api
|
from cic_eth.api import Api
|
||||||
from cic_types.condiments import MetadataPointer
|
from cic_types.condiments import MetadataPointer
|
||||||
|
from sqlalchemy import Column, Integer, String
|
||||||
|
from sqlalchemy.orm.session import Session
|
||||||
|
|
||||||
# local imports
|
# local imports
|
||||||
from cic_ussd.account.metadata import get_cached_preferred_language, parse_account_metadata
|
from cic_ussd.account.metadata import get_cached_preferred_language, parse_account_metadata
|
||||||
@ -12,8 +14,9 @@ from cic_ussd.db.enum import AccountStatus
|
|||||||
from cic_ussd.db.models.base import SessionBase
|
from cic_ussd.db.models.base import SessionBase
|
||||||
from cic_ussd.db.models.task_tracker import TaskTracker
|
from cic_ussd.db.models.task_tracker import TaskTracker
|
||||||
from cic_ussd.encoder import check_password_hash, create_password_hash
|
from cic_ussd.encoder import check_password_hash, create_password_hash
|
||||||
from sqlalchemy import Column, Integer, String
|
from cic_ussd.phone_number import Support
|
||||||
from sqlalchemy.orm.session import Session
|
|
||||||
|
support_phone = Support.phone_number
|
||||||
|
|
||||||
|
|
||||||
class Account(SessionBase):
|
class Account(SessionBase):
|
||||||
@ -29,12 +32,16 @@ class Account(SessionBase):
|
|||||||
failed_pin_attempts = Column(Integer)
|
failed_pin_attempts = Column(Integer)
|
||||||
status = Column(Integer)
|
status = Column(Integer)
|
||||||
preferred_language = Column(String)
|
preferred_language = Column(String)
|
||||||
|
guardians = Column(String)
|
||||||
|
guardian_quora = Column(Integer)
|
||||||
|
|
||||||
def __init__(self, blockchain_address, phone_number):
|
def __init__(self, blockchain_address, phone_number):
|
||||||
self.blockchain_address = blockchain_address
|
self.blockchain_address = blockchain_address
|
||||||
self.phone_number = phone_number
|
self.phone_number = phone_number
|
||||||
self.password_hash = None
|
self.password_hash = None
|
||||||
self.failed_pin_attempts = 0
|
self.failed_pin_attempts = 0
|
||||||
|
# self.guardians = f'{support_phone}' if support_phone else None
|
||||||
|
self.guardian_quora = 1
|
||||||
self.status = AccountStatus.PENDING.value
|
self.status = AccountStatus.PENDING.value
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
@ -45,6 +52,28 @@ class Account(SessionBase):
|
|||||||
self.failed_pin_attempts = 0
|
self.failed_pin_attempts = 0
|
||||||
self.status = AccountStatus.ACTIVE.value
|
self.status = AccountStatus.ACTIVE.value
|
||||||
|
|
||||||
|
def add_guardian(self, phone_number: str):
|
||||||
|
set_guardians = phone_number
|
||||||
|
if self.guardians:
|
||||||
|
set_guardians = self.guardians.split(',')
|
||||||
|
set_guardians.append(phone_number)
|
||||||
|
','.join(set_guardians)
|
||||||
|
self.guardians = set_guardians
|
||||||
|
|
||||||
|
def remove_guardian(self, phone_number: str):
|
||||||
|
set_guardians = self.guardians.split(',')
|
||||||
|
set_guardians.remove(phone_number)
|
||||||
|
if len(set_guardians) > 1:
|
||||||
|
self.guardians = ','.join(set_guardians)
|
||||||
|
else:
|
||||||
|
self.guardians = set_guardians[0]
|
||||||
|
|
||||||
|
def get_guardians(self) -> list:
|
||||||
|
return self.guardians.split(',') if self.guardians else []
|
||||||
|
|
||||||
|
def set_guardian_quora(self, quora: int):
|
||||||
|
self.guardian_quora = quora
|
||||||
|
|
||||||
def create_password(self, password):
|
def create_password(self, password):
|
||||||
"""This method takes a password value and hashes the value before assigning it to the corresponding
|
"""This method takes a password value and hashes the value before assigning it to the corresponding
|
||||||
`hashed_password` attribute in the user record.
|
`hashed_password` attribute in the user record.
|
||||||
|
Loading…
Reference in New Issue
Block a user