(20241214) testing token keys instead of direct ids.
This commit is contained in:
@@ -156,17 +156,44 @@ async def get_one_mail(
|
||||
:return: A standard response structure.
|
||||
"""
|
||||
|
||||
# ┏┓ ┓ ┏┓┓ ┓
|
||||
# ┣┫┓┏╋┣┓ ┃ ┣┓┏┓┏┃┏
|
||||
# ┛┗┗┻┗┛┗ ┗┛┛┗┗ ┗┛┗
|
||||
|
||||
# If the session token is invalid/expired:
|
||||
if kwargs.get("session_info") is None:
|
||||
return ResponseModel(
|
||||
status_code = StatusCodes.FAILED,
|
||||
http_code = HttpCodes.UNAUTHORIZED
|
||||
http_code = HttpCodes.UNAUTHORIZED,
|
||||
messge = "invalid session"
|
||||
)
|
||||
|
||||
# ┏┓ ┓ ┏┳┓ ┓
|
||||
# ┣ ┏┓╋┏┣┓ ┃ ┏┓┃┏┏┓┏┓┏
|
||||
# ┻ ┗ ┗┗┛┗ ┻ ┗┛┛┗┗ ┛┗┛
|
||||
|
||||
# We first load the authorization tokens:
|
||||
auth_token = await current_app.mail_controller.get_token(
|
||||
mongo_conn = current_app.data_mongo,
|
||||
token_key = inbound_data.tokenKey,
|
||||
)
|
||||
|
||||
# If we failed to load the authorization tokens:
|
||||
if not auth_token:
|
||||
return ResponseModel(
|
||||
status_code = StatusCodes.FAILED,
|
||||
http_code = HttpCodes.UNAUTHORIZED,
|
||||
message = f"no such token key '{inbound_data.tokenKey}'"
|
||||
)
|
||||
|
||||
# ┏┓ ┓ ┳┳┓ •┓
|
||||
# ┣ ┏┓╋┏┣┓ ┃┃┃┏┓┓┃
|
||||
# ┻ ┗ ┗┗┛┗ ┛ ┗┗┻┗┗
|
||||
|
||||
# Get the mail:
|
||||
message = await current_app.mail_controller.get_one_mail(
|
||||
mongo_conn = current_app.data_mongo,
|
||||
token_id = inbound_data.tokenId,
|
||||
token_id = auth_token.authTokenId,
|
||||
message_id = inbound_data.messageId
|
||||
)
|
||||
|
||||
|
||||
@@ -163,16 +163,28 @@ async def list_mails(
|
||||
:return: A standard response structure.
|
||||
"""
|
||||
|
||||
# ┏┓ ┓ ┏┓┓ ┓
|
||||
# ┣┫┓┏╋┣┓ ┃ ┣┓┏┓┏┃┏
|
||||
# ┛┗┗┻┗┛┗ ┗┛┛┗┗ ┗┛┗
|
||||
|
||||
# If the session token is invalid/expired:
|
||||
if await token_check.is_not_authorized(
|
||||
if kwargs.get("session_info") is None:
|
||||
return ResponseModel(
|
||||
status_code = StatusCodes.FAILED,
|
||||
http_code = HttpCodes.UNAUTHORIZED,
|
||||
messge = "invalid session"
|
||||
)
|
||||
|
||||
# ┏┓ ┓• ┳┳┓ •┓
|
||||
# ┣ ┏┓┃┓┏╋ ┃┃┃┏┓┓┃┏
|
||||
# ┗┛┛┗┗┗┛┗ ┛ ┗┗┻┗┗┛
|
||||
|
||||
# Get the token ids from the token keys:
|
||||
auth_tokens = await current_app.mail_controller.get_tokens(
|
||||
mongo_conn = current_app.data_mongo,
|
||||
user_info = kwargs.get("session_info"),
|
||||
token_ids = inbound_data.tokenIds
|
||||
): return ResponseModel(
|
||||
status_code = StatusCodes.FAILED,
|
||||
http_code = HttpCodes.UNAUTHORIZED,
|
||||
message = "user not authorized to use this token"
|
||||
token_keys = inbound_data.tokenKeys
|
||||
)
|
||||
token_ids = [t.authTokenId for t in auth_tokens]
|
||||
|
||||
# Build the additional filter:
|
||||
additional_filter = {}
|
||||
@@ -182,7 +194,7 @@ async def list_mails(
|
||||
# Get the mails:
|
||||
mails_list = await current_app.mail_controller.list_mails(
|
||||
mongo_conn = current_app.data_mongo,
|
||||
token_ids = inbound_data.tokenIds,
|
||||
token_ids = token_ids,
|
||||
limit = inbound_data.count,
|
||||
skip = inbound_data.fromCount,
|
||||
additional_filter = additional_filter
|
||||
|
||||
Reference in New Issue
Block a user