|
|
|
@@ -10,7 +10,7 @@ from app.db_sql import sql_insert, sql_update, sql_insert_or_update, sql_select,
|
|
|
|
from app.routers.api_crud import delete_obj_template, get_obj_template, get_obj_li_template, patch_obj_template, post_obj_template
|
|
|
|
from app.routers.api_crud import delete_obj_template, get_obj_template, get_obj_li_template, patch_obj_template, post_obj_template
|
|
|
|
|
|
|
|
|
|
|
|
from app.methods.order_methods import get_order_rec_list, load_order_obj
|
|
|
|
from app.methods.order_methods import get_order_rec_list, load_order_obj
|
|
|
|
from app.methods.user_methods import create_user_obj, load_user_obj
|
|
|
|
from app.methods.user_methods import create_user_obj, get_user_rec_list, load_user_obj
|
|
|
|
|
|
|
|
|
|
|
|
from app.models.common_field_schema import default_num_bytes
|
|
|
|
from app.models.common_field_schema import default_num_bytes
|
|
|
|
from app.models.response_models import Resp_Body_Base, mk_resp
|
|
|
|
from app.models.response_models import Resp_Body_Base, mk_resp
|
|
|
|
@@ -20,7 +20,7 @@ from app.models.user_models import User_Base, User_New_Base, User_Out_Base
|
|
|
|
router = APIRouter()
|
|
|
|
router = APIRouter()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@router.post('', response_model=Resp_Body_Base)
|
|
|
|
@router.post('/user', response_model=Resp_Body_Base)
|
|
|
|
async def post_user_obj(
|
|
|
|
async def post_user_obj(
|
|
|
|
obj: User_Base,
|
|
|
|
obj: User_Base,
|
|
|
|
x_account_id: str = Header(...),
|
|
|
|
x_account_id: str = Header(...),
|
|
|
|
@@ -46,7 +46,7 @@ async def post_user_obj(
|
|
|
|
|
|
|
|
|
|
|
|
# ### BEGIN ### API User ### post_user_obj_new() ###
|
|
|
|
# ### BEGIN ### API User ### post_user_obj_new() ###
|
|
|
|
# Updated 2021-08-21 (complete re-write)
|
|
|
|
# Updated 2021-08-21 (complete re-write)
|
|
|
|
@router.post('/new', response_model=Resp_Body_Base)
|
|
|
|
@router.post('/user/new', response_model=Resp_Body_Base)
|
|
|
|
async def post_user_obj_new(
|
|
|
|
async def post_user_obj_new(
|
|
|
|
user_obj: User_New_Base,
|
|
|
|
user_obj: User_New_Base,
|
|
|
|
allow_update: bool = False,
|
|
|
|
allow_update: bool = False,
|
|
|
|
@@ -86,7 +86,7 @@ async def post_user_obj_new(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# ### BEGIN ### API User ### user_obj_change_password() ###
|
|
|
|
# ### BEGIN ### API User ### user_obj_change_password() ###
|
|
|
|
@router.patch('/{user_id}/change_password', response_model=Resp_Body_Base)
|
|
|
|
@router.patch('/user/{user_id}/change_password', response_model=Resp_Body_Base)
|
|
|
|
async def user_obj_change_password(
|
|
|
|
async def user_obj_change_password(
|
|
|
|
user_id: Union[int,str],
|
|
|
|
user_id: Union[int,str],
|
|
|
|
user_obj: User_Base,
|
|
|
|
user_obj: User_Base,
|
|
|
|
@@ -148,7 +148,7 @@ async def user_obj_change_password(
|
|
|
|
# ### END ### API User ### user_obj_change_password() ###
|
|
|
|
# ### END ### API User ### user_obj_change_password() ###
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@router.patch('/{obj_id}', response_model=Resp_Body_Base)
|
|
|
|
@router.patch('/user/{obj_id}', response_model=Resp_Body_Base)
|
|
|
|
async def patch_user_obj(
|
|
|
|
async def patch_user_obj(
|
|
|
|
obj: User_Base,
|
|
|
|
obj: User_Base,
|
|
|
|
obj_id: str = Query(..., min_length=1, max_length=22),
|
|
|
|
obj_id: str = Query(..., min_length=1, max_length=22),
|
|
|
|
@@ -178,7 +178,7 @@ async def patch_user_obj(
|
|
|
|
|
|
|
|
|
|
|
|
# ### BEGIN ### API User Routers ### user_new_auth_key() ###
|
|
|
|
# ### BEGIN ### API User Routers ### user_new_auth_key() ###
|
|
|
|
# Generate a new one time use authorization key
|
|
|
|
# Generate a new one time use authorization key
|
|
|
|
@router.get('/new_auth_key', response_model=Resp_Body_Base)
|
|
|
|
@router.get('/user/new_auth_key', response_model=Resp_Body_Base)
|
|
|
|
async def user_new_auth_key(
|
|
|
|
async def user_new_auth_key(
|
|
|
|
user_id: Optional[str] = Query(None, min_length=2, max_length=50),
|
|
|
|
user_id: Optional[str] = Query(None, min_length=2, max_length=50),
|
|
|
|
x_account_id: str = Header(...),
|
|
|
|
x_account_id: str = Header(...),
|
|
|
|
@@ -223,7 +223,7 @@ async def user_new_auth_key(
|
|
|
|
# A new key will need to be requested for a particular user each time.
|
|
|
|
# A new key will need to be requested for a particular user each time.
|
|
|
|
# NOTE: Should this be divided into username/password and user ID/auth key endpoints?
|
|
|
|
# NOTE: Should this be divided into username/password and user ID/auth key endpoints?
|
|
|
|
# Updated 2021-10-06
|
|
|
|
# Updated 2021-10-06
|
|
|
|
@router.get('/authenticate', response_model=Resp_Body_Base)
|
|
|
|
@router.get('/user/authenticate', response_model=Resp_Body_Base)
|
|
|
|
async def user_authenticate(
|
|
|
|
async def user_authenticate(
|
|
|
|
account_id: Optional[Union[int,str]] = None,
|
|
|
|
account_id: Optional[Union[int,str]] = None,
|
|
|
|
user_id: Optional[str] = Query(None, min_length=11, max_length=22),
|
|
|
|
user_id: Optional[str] = Query(None, min_length=11, max_length=22),
|
|
|
|
@@ -380,7 +380,7 @@ async def user_authenticate(
|
|
|
|
|
|
|
|
|
|
|
|
# ### BEGIN ### API User ### user_verify_password() ###
|
|
|
|
# ### BEGIN ### API User ### user_verify_password() ###
|
|
|
|
# @router.post('/{user_id}/verify_password', response_model=Resp_Body_Base)
|
|
|
|
# @router.post('/{user_id}/verify_password', response_model=Resp_Body_Base)
|
|
|
|
@router.post('/verify_password', response_model=Resp_Body_Base)
|
|
|
|
@router.post('/user/verify_password', response_model=Resp_Body_Base)
|
|
|
|
async def user_verify_password(
|
|
|
|
async def user_verify_password(
|
|
|
|
user_obj: User_Base,
|
|
|
|
user_obj: User_Base,
|
|
|
|
# user_id: Optional[str] = Query(None, min_length=11, max_length=22),
|
|
|
|
# user_id: Optional[str] = Query(None, min_length=11, max_length=22),
|
|
|
|
@@ -471,7 +471,63 @@ async def user_verify_password(
|
|
|
|
# ### END ### API User ### user_verify_password() ###
|
|
|
|
# ### END ### API User ### user_verify_password() ###
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@router.get('/list', response_model=Resp_Body_Base)
|
|
|
|
|
|
|
|
|
|
|
|
@router.get('/account/{account_id}/user/list', response_model=Resp_Body_Base)
|
|
|
|
|
|
|
|
async def get_account_user_obj_li(
|
|
|
|
|
|
|
|
account_id: str = Query(..., min_length=11, 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
|
|
|
|
|
|
|
|
hidden: str = 'not_hidden', # hidden, not_hidden, all
|
|
|
|
|
|
|
|
inc_address: bool = False, # Priority l1
|
|
|
|
|
|
|
|
inc_contact: bool = False, # Priority l1
|
|
|
|
|
|
|
|
inc_person: bool = False, # Priority l1
|
|
|
|
|
|
|
|
inc_user_role_list: bool = False, # Priority l1
|
|
|
|
|
|
|
|
x_account_id: str = Header(...),
|
|
|
|
|
|
|
|
by_alias: Optional[bool] = True,
|
|
|
|
|
|
|
|
exclude_unset: Optional[bool] = True,
|
|
|
|
|
|
|
|
response: Response = Response,
|
|
|
|
|
|
|
|
):
|
|
|
|
|
|
|
|
log.setLevel(logging.INFO) # 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
|
|
|
|
|
|
|
|
else: return mk_resp(data=None, status_code=404, response=response)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Updated 2021-11-18
|
|
|
|
|
|
|
|
if user_rec_list_result := get_user_rec_list(
|
|
|
|
|
|
|
|
account_id = account_id,
|
|
|
|
|
|
|
|
hidden = hidden, # hidden, not_hidden, all
|
|
|
|
|
|
|
|
enabled = enabled,
|
|
|
|
|
|
|
|
limit = limit,
|
|
|
|
|
|
|
|
):
|
|
|
|
|
|
|
|
user_result_list = []
|
|
|
|
|
|
|
|
for user_rec in user_rec_list_result:
|
|
|
|
|
|
|
|
if load_user_result := load_user_obj(
|
|
|
|
|
|
|
|
user_id = user_rec.get('user_id', None),
|
|
|
|
|
|
|
|
enabled = enabled,
|
|
|
|
|
|
|
|
# hidden = hidden,
|
|
|
|
|
|
|
|
limit = limit,
|
|
|
|
|
|
|
|
inc_address = inc_address,
|
|
|
|
|
|
|
|
inc_contact = inc_contact,
|
|
|
|
|
|
|
|
inc_person = inc_person,
|
|
|
|
|
|
|
|
inc_user_role_list = inc_user_role_list,
|
|
|
|
|
|
|
|
by_alias = by_alias,
|
|
|
|
|
|
|
|
exclude_unset = exclude_unset,
|
|
|
|
|
|
|
|
# model_as_dict = model_as_dict,
|
|
|
|
|
|
|
|
):
|
|
|
|
|
|
|
|
user_result_list.append(load_user_result)
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
user_result_list.append(None)
|
|
|
|
|
|
|
|
response_data = user_result_list
|
|
|
|
|
|
|
|
elif isinstance(user_rec_list_result, list):
|
|
|
|
|
|
|
|
return mk_resp(data=False, status_code=404, response=response) # Not Found
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
return mk_resp(data=False, status_code=400, response=response) # Bad Request
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return mk_resp(data=response_data, response=response)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@router.get('/user/list', response_model=Resp_Body_Base)
|
|
|
|
async def get_user_obj_li(
|
|
|
|
async def get_user_obj_li(
|
|
|
|
for_obj_type: Optional[str] = Query(None, min_length=2, max_length=50),
|
|
|
|
for_obj_type: Optional[str] = Query(None, min_length=2, max_length=50),
|
|
|
|
for_obj_id: Optional[str] = Query(None, min_length=1, max_length=22),
|
|
|
|
for_obj_id: Optional[str] = Query(None, min_length=1, max_length=22),
|
|
|
|
@@ -495,7 +551,7 @@ async def get_user_obj_li(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Look up is only for account or person records
|
|
|
|
# Look up is only for account or person records
|
|
|
|
@router.get('/lookup', response_model=Resp_Body_Base)
|
|
|
|
@router.get('/user/lookup', response_model=Resp_Body_Base)
|
|
|
|
async def lookup_user_obj(
|
|
|
|
async def lookup_user_obj(
|
|
|
|
for_obj_id: Union[int,str],
|
|
|
|
for_obj_id: Union[int,str],
|
|
|
|
for_obj_type: str = Query(..., min_length=2, max_length=50),
|
|
|
|
for_obj_type: str = Query(..., min_length=2, max_length=50),
|
|
|
|
@@ -573,7 +629,7 @@ async def lookup_user_obj(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Look up a user with an email address for an account
|
|
|
|
# Look up a user with an email address for an account
|
|
|
|
@router.get('/lookup_email', response_model=Resp_Body_Base)
|
|
|
|
@router.get('/user/lookup_email', response_model=Resp_Body_Base)
|
|
|
|
async def lookup_email(
|
|
|
|
async def lookup_email(
|
|
|
|
account_id: Union[int,str],
|
|
|
|
account_id: Union[int,str],
|
|
|
|
email: str = Query(..., min_length=2, max_length=50),
|
|
|
|
email: str = Query(..., min_length=2, max_length=50),
|
|
|
|
@@ -673,7 +729,7 @@ async def lookup_email(
|
|
|
|
|
|
|
|
|
|
|
|
# Look up is only for account or person records
|
|
|
|
# Look up is only for account or person records
|
|
|
|
# Look up a user with a username for an account
|
|
|
|
# Look up a user with a username for an account
|
|
|
|
@router.get('/lookup_username', response_model=Resp_Body_Base)
|
|
|
|
@router.get('/user/lookup_username', response_model=Resp_Body_Base)
|
|
|
|
async def lookup_username(
|
|
|
|
async def lookup_username(
|
|
|
|
account_id: Union[int,str],
|
|
|
|
account_id: Union[int,str],
|
|
|
|
username: str = Query(..., min_length=2, max_length=50),
|
|
|
|
username: str = Query(..., min_length=2, max_length=50),
|
|
|
|
@@ -752,7 +808,7 @@ async def lookup_username(
|
|
|
|
|
|
|
|
|
|
|
|
# ### BEGIN ### API User ### get_user_obj() ###
|
|
|
|
# ### BEGIN ### API User ### get_user_obj() ###
|
|
|
|
# Working well as of 2021-06-25. Using as a template for other routes.
|
|
|
|
# Working well as of 2021-06-25. Using as a template for other routes.
|
|
|
|
@router.get('/{user_id}', response_model=Resp_Body_Base)
|
|
|
|
@router.get('/user/{user_id}', response_model=Resp_Body_Base)
|
|
|
|
async def get_user_obj(
|
|
|
|
async def get_user_obj(
|
|
|
|
user_id: str = Query(..., min_length=1, max_length=22),
|
|
|
|
user_id: str = Query(..., min_length=1, max_length=22),
|
|
|
|
limit: int = 500, # For now this covers any included objects or object lists
|
|
|
|
limit: int = 500, # For now this covers any included objects or object lists
|
|
|
|
@@ -823,7 +879,7 @@ async def get_user_obj(
|
|
|
|
|
|
|
|
|
|
|
|
# ### BEGIN ### API User ### get_user_obj_order_list() ###
|
|
|
|
# ### BEGIN ### API User ### get_user_obj_order_list() ###
|
|
|
|
# Working well as of 2021-06-28. Using as a template for other routes.
|
|
|
|
# Working well as of 2021-06-28. Using as a template for other routes.
|
|
|
|
@router.get('/{user_id}/order_list', response_model=Resp_Body_Base)
|
|
|
|
@router.get('/user/{user_id}/order_list', response_model=Resp_Body_Base)
|
|
|
|
async def get_user_obj_order_list(
|
|
|
|
async def get_user_obj_order_list(
|
|
|
|
user_id: str = Query(..., min_length=1, max_length=22),
|
|
|
|
user_id: str = Query(..., min_length=1, max_length=22),
|
|
|
|
limit: int = 500, # For now this covers any included objects or object lists
|
|
|
|
limit: int = 500, # For now this covers any included objects or object lists
|
|
|
|
@@ -883,7 +939,7 @@ async def get_user_obj_order_list(
|
|
|
|
# ### END ### API User ### get_user_obj_order_list() ###
|
|
|
|
# ### END ### API User ### get_user_obj_order_list() ###
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@router.delete('/{obj_id}', response_model=Resp_Body_Base)
|
|
|
|
@router.delete('/user/{obj_id}', response_model=Resp_Body_Base)
|
|
|
|
async def delete_user_obj(
|
|
|
|
async def delete_user_obj(
|
|
|
|
obj_id: str = Query(..., min_length=1, max_length=22),
|
|
|
|
obj_id: str = Query(..., min_length=1, max_length=22),
|
|
|
|
x_account_id: str = Header(...),
|
|
|
|
x_account_id: str = Header(...),
|
|
|
|
|