Code clean up. Person and User related is being worked on.
This commit is contained in:
@@ -477,9 +477,13 @@ def create_person_kiss(
|
||||
person_dict = person_obj.dict(by_alias=False, exclude_defaults=False, exclude_unset=True, exclude={'contact', 'contact_id', 'contact_id_random', 'email', 'cc_email', 'membership_person_id', 'membership_person_id_random', 'organization', 'user', 'created_on', 'updated_on'})
|
||||
|
||||
# ### SECTION ### Process data
|
||||
person_obj.account_id = account_id # Is this needed?
|
||||
person_dict['account_id'] = account_id
|
||||
|
||||
if user_id:
|
||||
# Link to an existing user
|
||||
log.info(f'Adding user_id to person_dict. User ID: {user_id}')
|
||||
person_obj.user_id = user_id # Is this needed?
|
||||
person_dict['user_id'] = user_id
|
||||
|
||||
if person_dict_in_result := sql_insert(data=person_dict, table_name='person', rm_id_random=True, id_random_length=default_num_bytes): pass
|
||||
@@ -493,7 +497,8 @@ def create_person_kiss(
|
||||
|
||||
if contact_id and person.contact:
|
||||
log.info('Updating Contact object')
|
||||
if contact_update_result := update_contact(
|
||||
if contact_update_result := update_contact_obj(
|
||||
contact_id = contact_id,
|
||||
contact_dict_obj = person_obj.contact,
|
||||
for_type = 'person',
|
||||
for_id = person_id,
|
||||
@@ -501,7 +506,7 @@ def create_person_kiss(
|
||||
else: return False
|
||||
elif person.contact:
|
||||
log.info('Creating Contact object')
|
||||
if contact_create_result := create_contact(
|
||||
if contact_create_result := create_contact_obj(
|
||||
account_id = account_id,
|
||||
contact_dict_obj = person_obj.contact,
|
||||
for_type = 'person',
|
||||
@@ -512,14 +517,15 @@ def create_person_kiss(
|
||||
|
||||
if user_id and person.user:
|
||||
log.info('Updating User object')
|
||||
if user_update_result := update_user(
|
||||
if user_update_result := update_user_obj(
|
||||
user_id = user_id,
|
||||
user_dict_obj = person_obj.user,
|
||||
person_id = person_id,
|
||||
): pass # NOTE: There is a trigger that will update the person record with the new user ID.
|
||||
else: return False
|
||||
elif person.user:
|
||||
log.info('Creating User object')
|
||||
if user_create_result := create_user(
|
||||
if user_create_result := create_user_obj(
|
||||
account_id = account_id,
|
||||
user_dict_obj = person_obj.user,
|
||||
person_id = person_id,
|
||||
@@ -527,6 +533,8 @@ def create_person_kiss(
|
||||
else: return False
|
||||
else: pass
|
||||
|
||||
log.info(f'Returning the new person_id: {person_id}')
|
||||
|
||||
return person_id
|
||||
# ### END ### API Person Methods ### create_person_kiss() ###
|
||||
|
||||
@@ -543,6 +551,7 @@ def update_person_kiss(
|
||||
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.debug(locals())
|
||||
|
||||
# ### SECTION ### Secondary data validation
|
||||
log.info('Create dictionary or Pydantic object')
|
||||
log.debug(type(person_dict_obj))
|
||||
if isinstance(person_dict_obj, dict):
|
||||
@@ -556,13 +565,17 @@ def update_person_kiss(
|
||||
return False
|
||||
else:
|
||||
person_obj = person_dict_obj
|
||||
person_obj.account_id = account_id
|
||||
|
||||
person_dict = person_obj.dict(by_alias=False, exclude_defaults=False, exclude_unset=True, exclude={'contact', 'contact_id', 'contact_id_random', 'email', 'cc_email', 'membership_person_id', 'membership_person_id_random', 'organization', 'user', 'created_on', 'updated_on'})
|
||||
|
||||
# ### SECTION ### Process data
|
||||
person_obj.person_id = person_id # Is this needed?
|
||||
person_dict['person_id'] = person_id
|
||||
|
||||
if user_id:
|
||||
# Link to an existing user
|
||||
log.info(f'Adding user_id to person_dict. User ID: {user_id}')
|
||||
person_obj.user_id = user_id # Is this needed?
|
||||
person_dict['user_id'] = user_id
|
||||
|
||||
if person_dict_up_result := sql_update(data=person_dict, table_name='person', rm_id_random=True, id_random_length=default_num_bytes): pass
|
||||
@@ -575,7 +588,8 @@ def update_person_kiss(
|
||||
|
||||
if contact_id and person.contact:
|
||||
log.info('Updating Contact object')
|
||||
if contact_update_result := update_contact(
|
||||
if contact_update_result := update_contact_obj(
|
||||
contact_id = contact_id,
|
||||
contact_dict_obj = person_obj.contact,
|
||||
for_type = 'person',
|
||||
for_id = person_id,
|
||||
@@ -583,7 +597,7 @@ def update_person_kiss(
|
||||
else: return False
|
||||
elif person.contact:
|
||||
log.info('Creating Contact object')
|
||||
if contact_create_result := create_contact(
|
||||
if contact_create_result := create_contact_obj(
|
||||
account_id = account_id,
|
||||
contact_dict_obj = person_obj.contact,
|
||||
for_type = 'person',
|
||||
@@ -594,11 +608,15 @@ def update_person_kiss(
|
||||
|
||||
if user_id and person.user:
|
||||
log.info('Updating User object')
|
||||
if user_update_result := update_user(): pass
|
||||
if user_update_result := update_user_obj(
|
||||
user_id = user_id,
|
||||
user_dict_obj = person_obj.user,
|
||||
person_id = person_id,
|
||||
): pass # NOTE: There is a trigger that will update the person record with the new user ID.
|
||||
else: return False
|
||||
elif person.user:
|
||||
log.info('Creating User object')
|
||||
if user_create_result := create_user(
|
||||
if user_create_result := create_user_obj(
|
||||
account_id = account_id,
|
||||
user_dict_obj = person_obj.user,
|
||||
person_id = person_id,
|
||||
@@ -780,7 +798,7 @@ def create_update_person_obj_v4b(
|
||||
from app.methods.user_methods import update_user_obj
|
||||
if update_user_obj_result := update_user_obj(
|
||||
user_id = user_id,
|
||||
user_obj_up = user_obj,
|
||||
user_dict_obj = user_obj,
|
||||
# create_sub_obj = create_sub_obj,
|
||||
# fail_any = fail_any,
|
||||
):
|
||||
@@ -800,7 +818,7 @@ def create_update_person_obj_v4b(
|
||||
from app.methods.user_methods import create_user_obj
|
||||
if create_user_obj_result := create_user_obj(
|
||||
account_id = account_id,
|
||||
user_obj_new = user_obj,
|
||||
user_dict_obj = user_obj,
|
||||
# create_sub_obj = create_sub_obj,
|
||||
# fail_any = fail_any,
|
||||
):
|
||||
@@ -1078,7 +1096,7 @@ def create_person_obj_v3(
|
||||
from app.methods.user_methods import update_user_obj
|
||||
if update_user_obj_result := update_user_obj(
|
||||
user_id = user_id,
|
||||
user_obj_up = user_obj_unknown,
|
||||
user_dict_obj = user_obj_unknown,
|
||||
# create_sub_obj = create_sub_obj,
|
||||
# fail_any = fail_any,
|
||||
):
|
||||
@@ -1131,7 +1149,7 @@ def create_person_obj_v3(
|
||||
from app.methods.user_methods import create_user_obj
|
||||
if create_user_obj_result := create_user_obj(
|
||||
account_id = account_id,
|
||||
user_obj_new = user_obj_unknown,
|
||||
user_dict_obj = user_obj_unknown,
|
||||
# create_sub_obj = create_sub_obj,
|
||||
# fail_any = fail_any,
|
||||
):
|
||||
@@ -1181,9 +1199,9 @@ def create_person_obj_v3(
|
||||
# if person_obj_new.user:
|
||||
# log.info(f'User data was found. Create a new user and link it to the new person. Person ID: {person_id}')
|
||||
# from app.methods.user_methods import create_user_obj
|
||||
# user_obj_new = person_obj_new.user
|
||||
# user_obj = person_obj_new.user
|
||||
# user_obj_new.person_id = person_id
|
||||
# create_user_obj_result = create_user_obj(user_obj_new=user_obj_new)
|
||||
# create_user_obj_result = create_user_obj(user_dict_obj=user_obj_new)
|
||||
# if isinstance(create_user_obj_result, int):
|
||||
# log.info(f'User created. User ID: {user_id} Update person {person_id} with new user ID.')
|
||||
# user_id = create_user_obj_result
|
||||
@@ -1352,7 +1370,7 @@ def update_person_obj_v3(
|
||||
from app.methods.user_methods import update_user_obj
|
||||
if update_user_obj_result := update_user_obj(
|
||||
user_id = user_id,
|
||||
user_obj_up = user_obj_unknown,
|
||||
user_dict_obj = user_obj_unknown,
|
||||
create_sub_obj = create_sub_obj,
|
||||
fail_any = fail_any,
|
||||
):
|
||||
@@ -1408,7 +1426,7 @@ def update_person_obj_v3(
|
||||
from app.methods.user_methods import create_user_obj
|
||||
if create_user_obj_result := create_user_obj(
|
||||
account_id = account_id,
|
||||
user_obj_new = user_obj_unknown,
|
||||
user_dict_obj = user_obj_unknown,
|
||||
create_sub_obj = create_sub_obj,
|
||||
fail_any = fail_any,
|
||||
):
|
||||
@@ -1536,7 +1554,7 @@ def update_person_obj(
|
||||
log.debug(user_obj_up)
|
||||
if user_obj_up_result := update_user_obj(
|
||||
user_id = user_id,
|
||||
user_obj_up = user_obj_up,
|
||||
user_dict_obj = user_obj_up,
|
||||
create_sub_obj = create_sub_obj,
|
||||
):
|
||||
log.debug(user_obj_up_result)
|
||||
@@ -1547,7 +1565,7 @@ def update_person_obj(
|
||||
# NOTE: This will blindly create a new user even if there was one associated but the person.user_id was not found.
|
||||
user_obj_in = person_obj_up.user
|
||||
log.debug(user_obj_in)
|
||||
if user_obj_in_result := create_user_obj(account_id=account_id, user_obj_new=user_obj_in):
|
||||
if user_obj_in_result := create_user_obj(account_id=account_id, user_dict_obj=user_obj_in):
|
||||
# log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.debug(user_obj_in_result)
|
||||
# Need to update the person with the new user_id
|
||||
|
||||
Reference in New Issue
Block a user