Merge branch 'philip/custom-metadata' into 'master'
Philip/custom metadata See merge request grassrootseconomics/cic-internal-integration!192
This commit is contained in:
commit
e13c423daf
12
apps/cic-ussd/cic_ussd/metadata/custom.py
Normal file
12
apps/cic-ussd/cic_ussd/metadata/custom.py
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
# standard imports
|
||||||
|
|
||||||
|
# external imports
|
||||||
|
|
||||||
|
# local imports
|
||||||
|
from .base import MetadataRequestsHandler
|
||||||
|
|
||||||
|
|
||||||
|
class CustomMetadata(MetadataRequestsHandler):
|
||||||
|
|
||||||
|
def __init__(self, identifier: bytes):
|
||||||
|
super().__init__(cic_type=':cic.custom', identifier=identifier)
|
12
apps/cic-ussd/cic_ussd/metadata/preferences.py
Normal file
12
apps/cic-ussd/cic_ussd/metadata/preferences.py
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
# standard imports
|
||||||
|
|
||||||
|
# external imports
|
||||||
|
|
||||||
|
# local imports
|
||||||
|
from .base import MetadataRequestsHandler
|
||||||
|
|
||||||
|
|
||||||
|
class PreferencesMetadata(MetadataRequestsHandler):
|
||||||
|
|
||||||
|
def __init__(self, identifier: bytes):
|
||||||
|
super().__init__(cic_type=':cic.preferences', identifier=identifier)
|
@ -29,6 +29,16 @@ def change_preferred_language_to_en(state_machine_data: Tuple[str, dict, Account
|
|||||||
Account.session.add(user)
|
Account.session.add(user)
|
||||||
Account.session.commit()
|
Account.session.commit()
|
||||||
|
|
||||||
|
preferences_data = {
|
||||||
|
'preferred_language': 'en'
|
||||||
|
}
|
||||||
|
|
||||||
|
s = celery.signature(
|
||||||
|
'cic_ussd.tasks.metadata.add_preferences_metadata',
|
||||||
|
[user.blockchain_address, preferences_data]
|
||||||
|
)
|
||||||
|
s.apply_async(queue='cic-ussd')
|
||||||
|
|
||||||
|
|
||||||
def change_preferred_language_to_sw(state_machine_data: Tuple[str, dict, Account]):
|
def change_preferred_language_to_sw(state_machine_data: Tuple[str, dict, Account]):
|
||||||
"""This function changes the user's preferred language to swahili.
|
"""This function changes the user's preferred language to swahili.
|
||||||
@ -40,6 +50,16 @@ def change_preferred_language_to_sw(state_machine_data: Tuple[str, dict, Account
|
|||||||
Account.session.add(user)
|
Account.session.add(user)
|
||||||
Account.session.commit()
|
Account.session.commit()
|
||||||
|
|
||||||
|
preferences_data = {
|
||||||
|
'preferred_language': 'sw'
|
||||||
|
}
|
||||||
|
|
||||||
|
s = celery.signature(
|
||||||
|
'cic_ussd.tasks.metadata.add_preferences_metadata',
|
||||||
|
[user.blockchain_address, preferences_data]
|
||||||
|
)
|
||||||
|
s.apply_async(queue='cic-ussd')
|
||||||
|
|
||||||
|
|
||||||
def update_account_status_to_active(state_machine_data: Tuple[str, dict, Account]):
|
def update_account_status_to_active(state_machine_data: Tuple[str, dict, Account]):
|
||||||
"""This function sets user's account to active.
|
"""This function sets user's account to active.
|
||||||
|
@ -55,11 +55,23 @@ def process_account_creation_callback(self, result: str, url: str, status_code:
|
|||||||
session.close()
|
session.close()
|
||||||
|
|
||||||
queue = self.request.delivery_info.get('routing_key')
|
queue = self.request.delivery_info.get('routing_key')
|
||||||
s = celery.signature(
|
|
||||||
|
# add phone number metadata lookup
|
||||||
|
s_phone_pointer = celery.signature(
|
||||||
'cic_ussd.tasks.metadata.add_phone_pointer',
|
'cic_ussd.tasks.metadata.add_phone_pointer',
|
||||||
[result, phone_number]
|
[result, phone_number]
|
||||||
)
|
)
|
||||||
s.apply_async(queue=queue)
|
s_phone_pointer.apply_async(queue=queue)
|
||||||
|
|
||||||
|
# add custom metadata tags
|
||||||
|
custom_metadata = {
|
||||||
|
"tags": ["ussd", "individual"]
|
||||||
|
}
|
||||||
|
s_custom_metadata = celery.signature(
|
||||||
|
'cic_ussd.tasks.metadata.add_custom_metadata',
|
||||||
|
[result, custom_metadata]
|
||||||
|
)
|
||||||
|
s_custom_metadata.apply_async(queue=queue)
|
||||||
|
|
||||||
# expire cache
|
# expire cache
|
||||||
cache.expire(task_id, timedelta(seconds=180))
|
cache.expire(task_id, timedelta(seconds=180))
|
||||||
|
@ -7,8 +7,10 @@ from hexathon import strip_0x
|
|||||||
|
|
||||||
# local imports
|
# local imports
|
||||||
from cic_ussd.metadata import blockchain_address_to_metadata_pointer
|
from cic_ussd.metadata import blockchain_address_to_metadata_pointer
|
||||||
|
from cic_ussd.metadata.custom import CustomMetadata
|
||||||
from cic_ussd.metadata.person import PersonMetadata
|
from cic_ussd.metadata.person import PersonMetadata
|
||||||
from cic_ussd.metadata.phone import PhonePointerMetadata
|
from cic_ussd.metadata.phone import PhonePointerMetadata
|
||||||
|
from cic_ussd.metadata.preferences import PreferencesMetadata
|
||||||
from cic_ussd.tasks.base import CriticalMetadataTask
|
from cic_ussd.tasks.base import CriticalMetadataTask
|
||||||
|
|
||||||
celery_app = celery.current_app
|
celery_app = celery.current_app
|
||||||
@ -44,7 +46,7 @@ def create_person_metadata(blockchain_address: str, data: dict):
|
|||||||
|
|
||||||
|
|
||||||
@celery_app.task
|
@celery_app.task
|
||||||
def edit_person_metadata(blockchain_address: str, data: bytes):
|
def edit_person_metadata(blockchain_address: str, data: dict):
|
||||||
identifier = blockchain_address_to_metadata_pointer(blockchain_address=blockchain_address)
|
identifier = blockchain_address_to_metadata_pointer(blockchain_address=blockchain_address)
|
||||||
person_metadata_client = PersonMetadata(identifier=identifier)
|
person_metadata_client = PersonMetadata(identifier=identifier)
|
||||||
person_metadata_client.edit(data=data)
|
person_metadata_client.edit(data=data)
|
||||||
@ -56,3 +58,17 @@ def add_phone_pointer(self, blockchain_address: str, phone_number: str):
|
|||||||
stripped_address = strip_0x(blockchain_address)
|
stripped_address = strip_0x(blockchain_address)
|
||||||
phone_metadata_client = PhonePointerMetadata(identifier=identifier)
|
phone_metadata_client = PhonePointerMetadata(identifier=identifier)
|
||||||
phone_metadata_client.create(data=stripped_address)
|
phone_metadata_client.create(data=stripped_address)
|
||||||
|
|
||||||
|
|
||||||
|
@celery_app.task()
|
||||||
|
def add_custom_metadata(blockchain_address: str, data: dict):
|
||||||
|
identifier = blockchain_address_to_metadata_pointer(blockchain_address=blockchain_address)
|
||||||
|
custom_metadata_client = CustomMetadata(identifier=identifier)
|
||||||
|
custom_metadata_client.create(data=data)
|
||||||
|
|
||||||
|
|
||||||
|
@celery_app.task()
|
||||||
|
def add_preferences_metadata(blockchain_address: str, data: dict):
|
||||||
|
identifier = blockchain_address_to_metadata_pointer(blockchain_address=blockchain_address)
|
||||||
|
custom_metadata_client = PreferencesMetadata(identifier=identifier)
|
||||||
|
custom_metadata_client.create(data=data)
|
||||||
|
Loading…
Reference in New Issue
Block a user