Code clean up. Bug fixes for person, user, contact, and address methods
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
from __future__ import annotations
|
||||
import datetime, pytz
|
||||
import datetime, pytz, secrets
|
||||
|
||||
from typing import Dict, List, Optional, Set, Union
|
||||
from pydantic import BaseModel, EmailStr, Field, PrivateAttr, ValidationError, validator
|
||||
@@ -12,7 +12,7 @@ from app.methods.contact_methods import create_contact_obj, create_update_contac
|
||||
from app.methods.order_cart_methods import get_order_cart_id_for_person_id, load_order_cart_obj
|
||||
from app.methods.order_methods import get_order_rec_list, load_order_obj
|
||||
from app.methods.organization_methods import create_update_organization_obj, load_organization_obj, update_organization_obj
|
||||
# from app.methods.user_methods import create_user_obj # , load_user_obj, update_user_obj
|
||||
# from app.methods.user_methods import create_user_obj, load_user_obj, update_user_obj
|
||||
|
||||
from app.models.common_field_schema import default_num_bytes
|
||||
from app.models.contact_models import Contact_Base
|
||||
@@ -517,6 +517,7 @@ def create_person_kiss(
|
||||
|
||||
if user_id and person_obj.user:
|
||||
log.info('Updating User object')
|
||||
from app.methods.user_methods import update_user_obj # NOTE: This creates a loop if outside function
|
||||
if user_update_result := update_user_obj(
|
||||
user_id = user_id,
|
||||
user_dict_obj = person_obj.user,
|
||||
@@ -525,10 +526,12 @@ def create_person_kiss(
|
||||
else: return False
|
||||
elif person_obj.user:
|
||||
log.info('Creating User object')
|
||||
from app.methods.user_methods import create_user_obj # NOTE: This creates a loop if outside function
|
||||
if user_create_result := create_user_obj(
|
||||
account_id = account_id,
|
||||
user_dict_obj = person_obj.user,
|
||||
person_id = person_id,
|
||||
allow_update = True, # WARNING NOTE: This will allow an existing user record to be updated.
|
||||
): pass # NOTE: There is a trigger that will update the person record with the new user ID.
|
||||
else: return False
|
||||
else: pass
|
||||
@@ -608,6 +611,7 @@ def update_person_kiss(
|
||||
|
||||
if user_id and person_obj.user:
|
||||
log.info('Updating User object')
|
||||
from app.methods.user_methods import update_user_obj # NOTE: This creates a loop if outside function
|
||||
if user_update_result := update_user_obj(
|
||||
user_id = user_id,
|
||||
user_dict_obj = person_obj.user,
|
||||
@@ -616,10 +620,12 @@ def update_person_kiss(
|
||||
else: return False
|
||||
elif person_obj.user:
|
||||
log.info('Creating User object')
|
||||
from app.methods.user_methods import create_user_obj # NOTE: This creates a loop if outside function
|
||||
if user_create_result := create_user_obj(
|
||||
account_id = account_id,
|
||||
user_dict_obj = person_obj.user,
|
||||
person_id = person_id,
|
||||
allow_update = True, # WARNING NOTE: This will allow an existing user record to be updated.
|
||||
): pass # NOTE: There is a trigger that will update the person record with the new user ID.
|
||||
else: return False
|
||||
else: pass
|
||||
@@ -1695,10 +1701,10 @@ def update_person_obj(
|
||||
# # ### END ### API Person Methods ### create_update_person_obj_v4b() ###
|
||||
|
||||
|
||||
# ### BEGIN ### Person Methods ### email_person_create_url() ###
|
||||
# ### BEGIN ### Person Methods ### handle_email_person_auth_key_url() ###
|
||||
# This emails the actual one time use account creation URL for a person.
|
||||
# Updated 2021-12-03
|
||||
def email_person_create_url(
|
||||
def handle_email_person_auth_key_url(
|
||||
account_id: int|str,
|
||||
person_id: int|str,
|
||||
root_url: str,
|
||||
@@ -1716,6 +1722,23 @@ def email_person_create_url(
|
||||
person_id = person_id,
|
||||
):
|
||||
log.info('Person object loaded')
|
||||
if person_obj.enable and person_obj.allow_auth_key:
|
||||
new_auth_key = secrets.token_urlsafe(default_num_bytes)
|
||||
update_person_data = {}
|
||||
update_person_data['auth_key'] = new_auth_key
|
||||
|
||||
if person_rec_update_result := sql_update(
|
||||
table_name = 'person',
|
||||
record_id = person_id,
|
||||
data = update_person_data
|
||||
):
|
||||
log.info('The person record was updated with a new auth_key')
|
||||
else:
|
||||
log.warning('The person record was not updated with a new auth_key')
|
||||
return False
|
||||
else:
|
||||
log.warning('The person record was not enabled or auth_key is not allowed')
|
||||
return False
|
||||
else: return False
|
||||
log.debug(person_obj)
|
||||
|
||||
@@ -1743,9 +1766,9 @@ def email_person_create_url(
|
||||
|
||||
account_short_name = account_cfg.account_short_name
|
||||
|
||||
# person_create_url = f'{root_url}person/{person_id_random}/create'
|
||||
# person_create_auth_key_url = f'{root_url}?user_id={user_id_random}&auth_key={new_auth_key}'
|
||||
person_create_auth_key_url = f'{root_url}?person_id={user_id_random}&auth_key={new_auth_key}'
|
||||
# person_auth_key_url = f'{root_url}person/{person_id_random}/create'
|
||||
# person_auth_key_url = f'{root_url}?user_id={user_id_random}&auth_key={new_auth_key}'
|
||||
person_auth_key_url = f'{root_url}?person_id={person_id_random}&auth_key={new_auth_key}'
|
||||
|
||||
subject = f'{account_short_name}: One Time Use Create Account Link'
|
||||
# subject = f'{account_short_name}: One Time Use Create Account Link ({new_auth_key})'
|
||||
@@ -1757,10 +1780,10 @@ def email_person_create_url(
|
||||
|
||||
<p>The link below can only be used once. If you would like try again using this method, you must <a href="NOT READY YET">request a new account creation link</a>. If you request multiple links, only the newest link will work.</p>
|
||||
|
||||
<p><strong><a href="{person_create_url}" style="appearance: button; display: inline-block; text-align: center; text-decoration: none; padding: .2rem .4rem; border: solid thin gray; border-radius: .2rem; background-color: lightyellow; color: black; font-size: larger;">Click to Finish Account Creation With One Time Use Link</a></strong></p>
|
||||
<p><strong><a href="{person_auth_key_url}" style="appearance: button; display: inline-block; text-align: center; text-decoration: none; padding: .2rem .4rem; border: solid thin gray; border-radius: .2rem; background-color: lightyellow; color: black; font-size: larger;">Click to Finish Account Creation With One Time Use Link</a></strong></p>
|
||||
|
||||
<p>Or copy and paste the link:<br>
|
||||
<strong style="background-color: lightyellow; color: black; font-size: larger;"><a href="{person_create_url}">{person_create_url}</a></strong></p>
|
||||
<strong style="background-color: lightyellow; color: black; font-size: larger;"><a href="{person_auth_key_url}">{person_auth_key_url}</a></strong></p>
|
||||
|
||||
<p>If you have questions about this email or trouble with this one time use link, you can email <a href="mailto:{help_tech_email}">{help_tech_name} ({help_tech_email})</a>.</p>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user