From 7aa2ecc4afb5d70558132160a7068bed760a233d Mon Sep 17 00:00:00 2001 From: Scott Idem Date: Wed, 8 Dec 2021 12:27:29 -0500 Subject: [PATCH] Clean up and testing. Starting to mark things as deprecated. --- app/config.py.default | 1 + app/methods/account_methods.py | 8 +- app/methods/event_person_methods.py | 1 + app/methods/membership_person_methods.py | 1 + app/methods/order_methods.py | 1 + app/methods/post_comment_methods.py | 1 + app/methods/post_methods.py | 1 + app/methods/test user_load_methods.py | 128 ----------------------- app/methods/user_methods.py | 83 ++++++++------- app/routers/event.py | 2 +- app/routers/user.py | 10 +- 11 files changed, 57 insertions(+), 180 deletions(-) delete mode 100644 app/methods/test user_load_methods.py diff --git a/app/config.py.default b/app/config.py.default index 695325d..08414f4 100644 --- a/app/config.py.default +++ b/app/config.py.default @@ -24,6 +24,7 @@ class Settings(BaseSettings): HTTP_STATUS_LI[409] = { 'name': 'Conflict', 'message': 'The request conflicts with another request (perhaps due to using the same idempotent key).' } HTTP_STATUS_LI[429] = { 'name': 'Too Many Requests', 'message': 'Too many requests hit the API too quickly. We recommend an exponential backoff of your requests.' } HTTP_STATUS_LI[500] = { 'name': 'Internal Server Error', 'message': 'The server encountered an unexpected condition which prevented it from fulfilling the request.' } + HTTP_STATUS_LI[501] = { 'name': 'Not Implemented', 'message': 'The server does not support the functionality required to fulfill the request. This is the appropriate response when the server does not recognize the request method and is not capable of supporting it for any resource.' } HTTP_STATUS_LI[502] = { 'name': 'Bad Gateway', 'message': 'The server, while acting as a gateway or proxy, received an invalid response from the upstream server it accessed in attempting to fulfill the request.' } HTTP_STATUS_LI[503] = { 'name': 'Service Unavailable', 'message': 'The server is currently unable to handle the request due to a temporary overloading or maintenance of the server. The implication is that this is a temporary condition which will be alleviated after some delay. If known, the length of the delay MAY be indicated in a Retry-After header. If no Retry-After is given, the client SHOULD handle the response as it would for a 500 response.' } HTTP_STATUS_LI[504] = { 'name': 'Gateway Timeout', 'message': 'The server, while acting as a gateway or proxy, did not receive a timely response from the upstream server specified by the URI (e.g. HTTP, FTP, LDAP) or some other auxiliary server (e.g. DNS) it needed to access in attempting to complete the request.' } diff --git a/app/methods/account_methods.py b/app/methods/account_methods.py index f8682b1..5cac08a 100644 --- a/app/methods/account_methods.py +++ b/app/methods/account_methods.py @@ -529,7 +529,7 @@ def load_account_obj( account_obj.site_list = site_result_list else: account_obj.site_list = [] - # Updated 2021-06-17 + # Updated 2021-12-08 if inc_user_list: if user_rec_list_result := get_user_rec_list( account_id = account_id, @@ -549,14 +549,10 @@ def load_account_obj( inc_address = inc_address, inc_contact = inc_contact, inc_event_list = inc_event_list, - inc_journal_list = inc_journal_list, - inc_membership_person = inc_membership_person, inc_order_list = inc_order_list, inc_order_cart_list = inc_order_cart_list, - inc_organization = inc_organization, + # inc_organization = inc_organization, inc_person = inc_person, - inc_post_list = inc_post_list, - inc_post_comment_list = inc_post_comment_list, inc_user_role_list = inc_user_role_list, ) ) diff --git a/app/methods/event_person_methods.py b/app/methods/event_person_methods.py index 4a11ffa..d9a0d96 100644 --- a/app/methods/event_person_methods.py +++ b/app/methods/event_person_methods.py @@ -168,6 +168,7 @@ def load_event_person_obj( # Updated 2021-08-17 if inc_user: + log.warning(f'This is being deprecated? load_event_person_obj() inc_user') log.info('Need to include user data...') # log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL from app.methods.user_methods import load_user_obj diff --git a/app/methods/membership_person_methods.py b/app/methods/membership_person_methods.py index 832f068..8942b96 100644 --- a/app/methods/membership_person_methods.py +++ b/app/methods/membership_person_methods.py @@ -240,6 +240,7 @@ def load_membership_person_obj( # Updated 2021-06-18 if inc_user: + log.warning(f'This is being deprecated? load_membership_person_obj() inc_user') user_id = membership_person_rec.get('user_id', None) if user_result := load_user_obj( user_id = user_id, diff --git a/app/methods/order_methods.py b/app/methods/order_methods.py index 5739bd4..c2557e6 100644 --- a/app/methods/order_methods.py +++ b/app/methods/order_methods.py @@ -256,6 +256,7 @@ def load_order_obj( # Updated 2021-06-22 if inc_user: + log.warning(f'This is being deprecated? load_order_obj() inc_user') from app.methods.user_methods import load_user_obj if user_result := load_user_obj( user_id = order_rec.get('user_id', None), diff --git a/app/methods/post_comment_methods.py b/app/methods/post_comment_methods.py index 086db2f..9b41287 100644 --- a/app/methods/post_comment_methods.py +++ b/app/methods/post_comment_methods.py @@ -84,6 +84,7 @@ def load_post_comment_obj( # Updated 2021-06-18 if inc_user: + log.warning(f'This is being deprecated? load_post_comment_obj() inc_user') # from app.methods.user_methods import load_user_obj # user_result = load_user_obj( # user_id = post_comment_rec.get('user_id', None), diff --git a/app/methods/post_methods.py b/app/methods/post_methods.py index 813701e..d87451c 100644 --- a/app/methods/post_methods.py +++ b/app/methods/post_methods.py @@ -111,6 +111,7 @@ def load_post_obj( # Updated 2021-06-18 if inc_user: + log.warning(f'This is being deprecated? load_post_obj() inc_user') # from app.methods.user_methods import load_user_obj # user_result = load_user_obj( # user_id = post_rec.get('user_id', None), diff --git a/app/methods/test user_load_methods.py b/app/methods/test user_load_methods.py deleted file mode 100644 index 075ee55..0000000 --- a/app/methods/test user_load_methods.py +++ /dev/null @@ -1,128 +0,0 @@ -from __future__ import annotations -import datetime - -from typing import Dict, List, Optional, Set, Union -from pydantic import BaseModel, EmailStr, Field, PrivateAttr, ValidationError, validator - -from app.db_sql import redis_lookup_id_random, sql_insert, sql_select, sql_update -from app.lib_general import log, logging - -from app.methods.contact_methods import load_contact_obj -# from app.methods.event_methods import load_event_obj_list -from app.methods.organization_methods import load_organization_obj -# from app.methods.person_methods import load_person_obj -# from app.methods.post_methods import load_post_obj_list - -from app.models.user_models import User_Base, User_New_Base, User_Out_Base -from app.models.user_role_models import User_Role_Base - - -# ### BEGIN ### API User Methods ### load_user_obj() ### -def load_user_obj( - user_id: int|str, - limit: int = 1000, - model_as_dict: bool = False, - enabled: str = 'enabled', # enabled, disabled, all - inc_address: bool = False, - inc_contact: bool = False, - inc_event_list: bool = False, - inc_journal_list: bool = False, - inc_membership: bool = False, - inc_order_list: bool = False, - inc_order_cart_list: bool = False, - inc_organization: bool = False, - inc_person: bool = False, - inc_post_list: bool = False, - inc_post_comment_list: 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()) - - if user_id := redis_lookup_id_random(record_id_random=user_id, table_name='user'): pass - else: return False - - if user_rec := sql_select(table_name='v_user', record_id=user_id): pass - else: return False - - #log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL - log.debug(user_rec) - - try: - user_obj = User_Out_Base(**user_rec) - log.debug(user_obj) - except ValidationError as e: - log.error(e.json()) - return False - - if inc_contact: - contact_id = user_rec.get('contact_id', None) - if contact_obj_result := load_contact_obj(contact_id=contact_id): - contact_obj = contact_obj_result - user_rec['contact'] = contact_obj - log.debug(user_rec) - user_obj.contact = contact_obj - else: - user_rec['contact'] = None - user_obj.contact = None - - if inc_event_list: - if event_dict_list := load_event_obj_list( - user_id = user_id, - limit = limit, - model_as_dict = model_as_dict, - enabled = enabled, - ): - user_obj.event_list = event_dict_list - else: user_obj.event_list = None - - - if inc_organization: - organization_id = user_rec.get('organization_id', None) - if organization_obj_result := load_organization_obj(organization_id=organization_id): - organization_obj = organization_obj_result - user_rec['organization'] = organization_obj - log.debug(user_rec) - user_obj.organization = organization_obj - else: - user_rec['organization'] = None - user_obj.organization = None - - # if inc_person: - # person_id = user_rec.get('person_id', None) - # if person_obj_result := load_person_obj(person_id=person_id): - # person_obj = person_obj_result - # user_rec['person'] = person_obj - # log.debug(user_rec) - # user_obj.person = person_obj - # else: - # user_rec['person'] = None - # user_obj.person = None - - if inc_post_list: - if post_dict_list := load_post_obj_list( - user_id = user_id, - limit = limit, - model_as_dict = model_as_dict, - enabled = enabled, - ): - user_obj.post_list = post_dict_list - else: user_obj.post_list = None - - - # NOTE: Including user roles should probably be reviewed - 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 - log.debug(role_rec_li) - user_obj.role_list = role_rec_li - else: - user_rec['role_list'] = None - user_obj.role_list = None - - #log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL - log.debug(user_rec) - - return user_obj -# ### END ### API User Methods ### load_user_obj() ### diff --git a/app/methods/user_methods.py b/app/methods/user_methods.py index 67a33be..baa95f1 100644 --- a/app/methods/user_methods.py +++ b/app/methods/user_methods.py @@ -249,22 +249,22 @@ def load_user_obj( model_as_dict: bool = False, enabled: str = 'enabled', # enabled, disabled, all inc_address: bool = False, - # inc_archive_list: bool = False, + # inc_archive_list: bool = False, # deprecated inc_contact: bool = False, - inc_event_list: bool = False, - # inc_hosted_file_list: bool = False, - inc_journal_list: bool = False, - inc_journal_entry_list: bool = False, - inc_membership_person: bool = False, - inc_order_cfg: bool = False, - inc_order_line_list: bool = False, - inc_order_list: bool = False, - inc_order_cart_list: bool = False, - inc_organization: bool = False, + inc_event_list: bool = False, # deprecated + # inc_hosted_file_list: bool = False, # deprecated + # inc_journal_list: bool = False, # deprecated + # inc_journal_entry_list: bool = False, # deprecated + # inc_membership_person: bool = False, # deprecated + inc_order_cfg: bool = False, # deprecated + inc_order_line_list: bool = False, # deprecated + inc_order_list: bool = False, # deprecated + inc_order_cart_list: bool = False, # deprecated + inc_organization: bool = False, # deprecated inc_person: bool = False, - # inc_person_list: bool = False, - inc_post_list: bool = False, - inc_post_comment_list: bool = False, + # inc_person_list: bool = False, # deprecated + # inc_post_list: bool = False, # deprecated + # inc_post_comment_list: bool = False, # deprecated inc_user_role_list: bool = False, ) -> User_Out_Base|dict|bool: log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL @@ -286,7 +286,8 @@ def load_user_obj( return False # Updated 2021-06-18 - # if inc_contact: + if inc_contact: + log.warning(f'This is being deprecated? load_user_obj() inc_contact') # contact_id = user_rec.get('contact_id', None) # log.debug(contact_id) # if contact_result := load_contact_obj( @@ -302,6 +303,7 @@ def load_user_obj( # else: user_obj.contact = None if inc_event_list: + log.warning(f'This is being deprecated? load_user_obj() inc_event_list') from app.methods.event_methods import load_event_obj_list if event_dict_list := load_event_obj_list( user_id = user_id, @@ -314,6 +316,7 @@ def load_user_obj( # Updated 2021-06-18 if inc_order_list: + log.warning(f'This is being deprecated? load_user_obj() inc_order_list') if order_rec_list_result := get_order_rec_list( for_obj_type = 'user', for_obj_id = user_id, @@ -340,6 +343,7 @@ def load_user_obj( # Updated 2021-06-18 if inc_organization: + log.warning(f'This is being deprecated? load_user_obj() inc_organization') organization_id = user_rec.get('organization_id', None) log.debug(organization_id) if organization_result := load_organization_obj( @@ -373,30 +377,31 @@ def load_user_obj( log.debug(person_result) # Updated 2021-06-18 - if inc_post_list: - if post_rec_list_result := get_post_rec_list( - for_obj_type = 'user', - for_obj_id = user_id, - limit = limit, - enabled = enabled, - ): - post_result_list = [] - for post_rec in post_rec_list_result: - if load_post_result := load_post_obj( - post_id = post_rec.get('post_id', None), - limit = limit, - by_alias = by_alias, - exclude_unset = exclude_unset, - model_as_dict = model_as_dict, - enabled = enabled, - inc_post_comment_list = inc_post_comment_list, - inc_person = inc_person, - # inc_user = inc_user, - ): - post_result_list.append(load_post_result) - else: post_result_list.append(None) - user_obj.post_list = post_result_list - else: user_obj.post_list = [] + # if inc_post_list: + # log.warning(f'This is being deprecated? load_user_obj() inc_post_list') + # if post_rec_list_result := get_post_rec_list( + # for_obj_type = 'user', + # for_obj_id = user_id, + # limit = limit, + # enabled = enabled, + # ): + # post_result_list = [] + # for post_rec in post_rec_list_result: + # if load_post_result := load_post_obj( + # post_id = post_rec.get('post_id', None), + # limit = limit, + # by_alias = by_alias, + # exclude_unset = exclude_unset, + # model_as_dict = model_as_dict, + # enabled = enabled, + # inc_post_comment_list = inc_post_comment_list, + # inc_person = inc_person, + # # inc_user = inc_user, + # ): + # post_result_list.append(load_post_result) + # else: post_result_list.append(None) + # user_obj.post_list = post_result_list + # else: user_obj.post_list = [] # Updated 2021-06-25 if inc_user_role_list: diff --git a/app/routers/event.py b/app/routers/event.py index b88ab9b..39a7bf8 100644 --- a/app/routers/event.py +++ b/app/routers/event.py @@ -309,7 +309,7 @@ async def get_event_obj( # Updated 2021-09-28 @router.get('/account/{account_id}/event/list', response_model=Resp_Body_Base) async def get_account_obj_event_list( - account_id: str = Query(..., min_length=1, max_length=22), + account_id: str = Query(..., min_length=11, max_length=22), limit: int = 500, enabled: str = 'enabled', archived: str = 'not_archived', # archived, not_archived, all diff --git a/app/routers/user.py b/app/routers/user.py index 58968b8..49e58b0 100644 --- a/app/routers/user.py +++ b/app/routers/user.py @@ -780,7 +780,6 @@ async def lookup_username( user_id = user_id, inc_address = inc_address, inc_contact = inc_contact, - inc_organization = inc_organization, inc_person = inc_person, inc_user_role_list = inc_user_role_list, ).dict(by_alias = by_alias, exclude_unset=exclude_unset) @@ -794,7 +793,6 @@ async def lookup_username( user_id = user_id, inc_address = inc_address, inc_contact = inc_contact, - inc_organization = inc_organization, inc_person = inc_person, inc_user_role_list = inc_user_role_list, ).dict(by_alias=by_alias, exclude_unset=exclude_unset) @@ -890,18 +888,18 @@ async def get_user_obj( inc_contact = inc_contact, inc_event_list = inc_event_list, # inc_hosted_file_list = inc_hosted_file_list, - inc_journal_list = inc_journal_list, + # inc_journal_list = inc_journal_list, # inc_journal_entry_list = inc_journal_entry_list, - inc_membership_person = inc_membership_person, + # inc_membership_person = inc_membership_person, # inc_membership_list = inc_membership_list, # ??? inc_order_line_list = inc_order_line_list, inc_order_list = inc_order_list, inc_order_cart_list = inc_order_cart_list, - inc_organization = inc_organization, + # inc_organization = inc_organization, # inc_organization_list = inc_organization_list, inc_person = inc_person, # inc_person_list = inc_person_list, - inc_post_list = inc_post_list, + # inc_post_list = inc_post_list, # inc_post_comment_list = inc_post_comment_list, inc_user_role_list = inc_user_role_list, ):