User related clean up
This commit is contained in:
@@ -75,7 +75,7 @@ def load_user_obj(
|
||||
inc_contact: bool = False,
|
||||
inc_organization: bool = False,
|
||||
inc_person: bool = False,
|
||||
inc_user_role_li: bool = False,
|
||||
inc_user_role_list: bool = False,
|
||||
) -> User_Out_Base|bool:
|
||||
#log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.debug(locals())
|
||||
@@ -130,7 +130,7 @@ def load_user_obj(
|
||||
# user_obj.person = None
|
||||
|
||||
# NOTE: Including user roles should probably be reviewed
|
||||
if inc_user_role_li:
|
||||
if inc_user_role_list:
|
||||
if role_rec_li := sql_select(table_name='v_user_role_detail', field_name='user_id', field_value=user_id, as_list=True):
|
||||
user_rec['role_list'] = role_rec_li
|
||||
#log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
|
||||
@@ -8,8 +8,8 @@ from app.db_sql import redis_lookup_id_random
|
||||
from app.lib_general import log, logging, secure_hash_string
|
||||
|
||||
from app.models.common_field_schema import base_fields, default_num_bytes
|
||||
# from app.models.account_models import Account_Base
|
||||
from app.models.contact_models import Contact_Base
|
||||
# from app.models.membership_models import Membership_Base
|
||||
from app.models.organization_models import Organization_Base
|
||||
# from app.models.person_models import Person_Base # Causes circular import
|
||||
from app.models.user_role_models import User_Role_Base
|
||||
@@ -181,12 +181,19 @@ class User_Out_Base(BaseModel):
|
||||
updated_on: Optional[datetime.datetime]
|
||||
|
||||
# Including other related objects
|
||||
#account: Optional[Account_Base]
|
||||
contact: Optional[Union[Contact_Base, None]]
|
||||
organization: Optional[Union[Organization_Base, None]]
|
||||
#person: Optional[Union[Person_Base, None]]# Causes circular import
|
||||
role_list: Optional[Union[list, None]] = []
|
||||
|
||||
archive_list: Optional[list] # Archive_Base()
|
||||
contact: Optional[Contact_Base]
|
||||
event_list: Optional[list] # Event_Base() # Priority l1
|
||||
hosted_file_list: Optional[list] # Hosted_File_Base() # Priority l2
|
||||
journal_list: Optional[list] # Journal_Base() # Priority l3
|
||||
# membership: Optional[Membership_Base] # Priority l2
|
||||
order_list: Optional[list] # Order_Base() # Priority l2
|
||||
order_cart_list: Optional[list] # Order_Base() # Priority l2
|
||||
organization: Optional[Organization_Base] # Organization_Base() # Priority l3
|
||||
# person: Optional[Person_Base] # Person_Base() # Priority l2
|
||||
post_list: Optional[list] # Post_Base() # Priority l1
|
||||
user_role_list: Optional[list] # User_Role_Base()
|
||||
role_list: Optional[list] = [] # User_Role_Base() # NOTE <- This is a duplicate of above!
|
||||
|
||||
_processed_at: datetime.datetime = PrivateAttr(default_factory=datetime.datetime.now)
|
||||
|
||||
@@ -201,11 +208,6 @@ class User_Base(BaseModel):
|
||||
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.debug(locals())
|
||||
|
||||
#from .account_models import Account_Base
|
||||
#from .contact_models import Contact_Base
|
||||
#from .organization_models import Organization_Base
|
||||
#from .person_models import Person_Base
|
||||
|
||||
#if TYPE_CHECKING:
|
||||
#from .person_models import Person_Base
|
||||
|
||||
@@ -259,11 +261,19 @@ class User_Base(BaseModel):
|
||||
updated_on: Optional[datetime.datetime] = None
|
||||
|
||||
# Including other related objects
|
||||
#account: Optional[Account_Base]
|
||||
archive_list: Optional[list] # Archive_Base()
|
||||
contact: Optional[Contact_Base]
|
||||
#organization: Optional[Organization_Base]
|
||||
#person: Optional[Person_Base]
|
||||
role_list: Optional[list] = [] # User_Role_Base()
|
||||
event_list: Optional[list] # Event_Base() # Priority l1
|
||||
hosted_file_list: Optional[list] # Hosted_File_Base() # Priority l2
|
||||
journal_list: Optional[list] # Journal_Base() # Priority l3
|
||||
# membership: Optional[Membership_Base] # Priority l2
|
||||
order_list: Optional[list] # Order_Base() # Priority l2
|
||||
order_cart_list: Optional[list] # Order_Base() # Priority l2
|
||||
organization: Optional[Organization_Base] # Organization_Base() # Priority l3
|
||||
# person: Optional[Person_Base] # Person_Base() # Priority l2
|
||||
post_list: Optional[list] # Post_Base() # Priority l1
|
||||
user_role_list: Optional[list] # User_Role_Base()
|
||||
role_list: Optional[list] = [] # User_Role_Base() # NOTE <- This is a duplicate of above!
|
||||
|
||||
_processed_at: datetime.datetime = PrivateAttr(default_factory=datetime.datetime.now)
|
||||
|
||||
|
||||
@@ -566,54 +566,24 @@ async def get_user_obj_new(
|
||||
account_id: str = Query(..., min_length=1, max_length=22),
|
||||
limit: int = 500, # For now this covers any included objects or object lists
|
||||
enabled: str = 'enabled', # For now this covers any included objects or object lists
|
||||
inc_account_cfg: bool = False, # Priority l1
|
||||
inc_address: bool = False, # Under contact
|
||||
inc_contact: bool = False,
|
||||
inc_event: bool = False,
|
||||
inc_address: bool = False, # Priority l1
|
||||
inc_archive_list: bool = False, # Priority l3
|
||||
inc_contact: bool = False, # Priority l1
|
||||
inc_event_list: bool = False, # Priority l1
|
||||
# inc_event_abstract: bool = False,
|
||||
inc_event_abstract_list: bool = False,
|
||||
# inc_event_badge: bool = False,
|
||||
inc_event_badge_list: bool = False,
|
||||
# inc_event_device: bool = False,
|
||||
# inc_event_device_list: bool = False,
|
||||
# inc_event_exhibit: bool = False,
|
||||
inc_event_exhibit_list: bool = False,
|
||||
# inc_event_file: bool = False,
|
||||
inc_event_file_list: bool = False,
|
||||
# inc_event_location: bool = False, # For event_session child object
|
||||
inc_event_location_list: bool = False,
|
||||
# inc_event_person: bool = False,
|
||||
inc_event_person_list: bool = False,
|
||||
# inc_event_presentation: bool = False,
|
||||
inc_event_presentation_list: bool = False,
|
||||
# inc_event_presenter_cat: bool = False, # For event_session child object
|
||||
# inc_event_presenter: bool = False,
|
||||
inc_event_presenter_list: bool = False,
|
||||
# inc_event_registration: bool = False,
|
||||
inc_event_registration_list: bool = False,
|
||||
# inc_event_session: bool = False,
|
||||
inc_event_session_list: bool = False,
|
||||
# inc_event_track: bool = False, # For event_session child object
|
||||
inc_event_track_list: bool = False,
|
||||
inc_hosted_file_list: bool = False,
|
||||
inc_journal_list: bool = False,
|
||||
inc_membership: bool = False,
|
||||
# inc_membership_list: bool = False,
|
||||
# inc_order: bool = False,
|
||||
inc_order_list: bool = False,
|
||||
# inc_order_cart: bool = False,
|
||||
inc_order_cart_list: bool = False,
|
||||
inc_organization: bool = False,
|
||||
inc_organization_list: bool = False,
|
||||
inc_person: bool = False,
|
||||
inc_person_list: bool = False,
|
||||
# inc_post: bool = False,
|
||||
inc_post_list: bool = False, # Priority l1
|
||||
# inc_post_comment: bool = False,
|
||||
inc_post_comment_list: bool = False,
|
||||
inc_user: bool = False,
|
||||
inc_user_list: bool = False,
|
||||
inc_hosted_file_list: bool = False, # Priority l3
|
||||
inc_journal_list: bool = False, # Priority l2
|
||||
# inc_journal_entry_list: bool = False, # Priority l3
|
||||
inc_membership: bool = False, # Priority l2
|
||||
# inc_membership_list: bool = False, # ???
|
||||
inc_order_list: bool = False, # Priority l1
|
||||
inc_order_cart_list: bool = False, # Priority l1
|
||||
inc_organization: bool = False, # Priority l1
|
||||
# inc_organization_list: bool = False,
|
||||
inc_person: bool = False, # Priority l1
|
||||
# inc_person_list: bool = False,
|
||||
inc_post_list: bool = False, # Priority l2
|
||||
inc_post_comment_list: bool = False, # Priority l3
|
||||
inc_user_role_list: bool = False, # Priority l1
|
||||
x_account_id: str = Header(...),
|
||||
by_alias: Optional[bool] = True,
|
||||
exclude_unset: Optional[bool] = True,
|
||||
@@ -621,71 +591,43 @@ async def get_user_obj_new(
|
||||
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.debug(locals())
|
||||
|
||||
if account_id := redis_lookup_id_random(record_id_random=account_id, table_name='account'): pass
|
||||
if user_id := redis_lookup_id_random(record_id_random=user_id, table_name='user'): pass
|
||||
else:
|
||||
return mk_resp(data=None, status_code=404)
|
||||
|
||||
if account_dict := load_user_obj(
|
||||
account_id = account_id,
|
||||
enabled = enabled,
|
||||
if user_dict := load_user_obj(
|
||||
user_id = user_id,
|
||||
limit = limit,
|
||||
model_as_dict = True, # NOTE: returning model as a dict
|
||||
enabled = enabled,
|
||||
inc_address = inc_address,
|
||||
# inc_address_list = inc_address_list,
|
||||
# inc_archive = inc_archive,
|
||||
# inc_archive_list = inc_archive_list,
|
||||
# inc_archive_content = inc_archive_content,
|
||||
# inc_archive_content_list = inc_archive_content_list,
|
||||
inc_contact = inc_contact,
|
||||
inc_contact_list = inc_contact_list,
|
||||
inc_event = inc_event,
|
||||
inc_event_list = inc_event_list,
|
||||
# inc_event_abstract_list = inc_event_abstract_list,
|
||||
# inc_event_badge_list = inc_event_badge_list,
|
||||
# inc_event_device_list = inc_event_device_list,
|
||||
# inc_event_file_list = inc_event_file_list,
|
||||
# inc_event_location = inc_event_location,
|
||||
# inc_event_person = inc_event_person,
|
||||
inc_event_person_list = inc_event_person_list,
|
||||
inc_event_presentation_list = inc_event_presentation_list,
|
||||
# inc_event_presenter_cat = inc_event_presenter_cat,
|
||||
inc_event_presenter_list = inc_event_presenter_list,
|
||||
inc_event_registration_list = inc_event_registration_list,
|
||||
inc_event_session_list = inc_event_session_list,
|
||||
# inc_event_track = inc_event_track,
|
||||
# inc_event_track_list = inc_event_track_list,
|
||||
# inc_fundraising_cfg = inc_fundraising_cfg,
|
||||
inc_hosted_file_list = inc_hosted_file_list,
|
||||
# inc_hosted_file_list = inc_hosted_file_list,
|
||||
inc_journal_list = inc_journal_list,
|
||||
# inc_journal_entry_list = inc_journal_entry_list,
|
||||
inc_membership = inc_membership,
|
||||
# inc_membership_cfg = inc_membership_cfg,
|
||||
# inc_membership_list = inc_membership_list,
|
||||
inc_order = inc_order,
|
||||
# inc_membership_list = inc_membership_list, # ???
|
||||
inc_order_list = inc_order_list,
|
||||
inc_order_cart = inc_order_cart,
|
||||
inc_order_cart_list = inc_order_cart_list,
|
||||
inc_organization = inc_organization,
|
||||
inc_organization_list = inc_organization_list,
|
||||
# inc_organization_list = inc_organization_list,
|
||||
inc_person = inc_person,
|
||||
inc_person_list = inc_person_list,
|
||||
inc_post = inc_post,
|
||||
# inc_person_list = inc_person_list,
|
||||
inc_post_list = inc_post_list,
|
||||
# inc_product = inc_product,
|
||||
# inc_product_list = inc_product_list,
|
||||
# inc_site = inc_site,
|
||||
# inc_site_list = inc_site_list,
|
||||
# inc_user = inc_user,
|
||||
# inc_user_list = inc_user_list,
|
||||
inc_post_comment_list = inc_post_comment_list,
|
||||
inc_user_role_list = inc_user_role_list,
|
||||
):
|
||||
if isinstance(account_dict, dict):
|
||||
response_data = account_dict
|
||||
if isinstance(user_dict, dict):
|
||||
response_data = user_dict
|
||||
else:
|
||||
response_data = account_dict
|
||||
response_data = user_dict
|
||||
else:
|
||||
return mk_resp(data=False, status_code=400) # Bad Request
|
||||
|
||||
return mk_resp(data=response_data)
|
||||
# ### END ### API User ### get_user_obj() ###
|
||||
# ### END ### API User ### get_user_obj_new() ###
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user