Skip to content

Commit

Permalink
fix: ansi->colors for logger and run black
Browse files Browse the repository at this point in the history
  • Loading branch information
tiptenbrink committed Dec 9, 2023
1 parent 909418d commit e240eda
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 18 deletions.
17 changes: 13 additions & 4 deletions backend/src/apiserver/app/routers/onboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ async def init_signup(
su_ex = await data.signedup.signedup_exists(conn, signup.email)

do_send_email = not u_ex and not su_ex
logger.debug(f"{signup.email} not u_ex={u_ex} and not su_ex={su_ex} is {do_send_email}")
logger.debug(
f"{signup.email} not u_ex={u_ex} and not su_ex={su_ex} is {do_send_email}"
)

confirm_id = random_time_hash_hex()

Expand All @@ -78,7 +80,9 @@ async def init_signup(
confirmation_url = f"{DEFINE.credentials_url}email/?{urlencode(params)}"

if do_send_email:
logger.opt(ansi=True).debug(f"Creating email with confirmation url <u><red>{confirmation_url}</red></u>")
logger.opt(colors=True).debug(
f"Creating email with confirmation url <u><red>{confirmation_url}</red></u>"
)
send_signup_email(
background_tasks,
signup.email,
Expand Down Expand Up @@ -230,7 +234,10 @@ async def confirm_join(
)
await data.signedup.confirm_signup(conn, signup_email)

logger.debug(f"Confirmed onboard for {signup_email} = {signed_up.firstname} {signed_up.lastname}")
logger.debug(
f"Confirmed onboard for {signup_email} ="
f" {signed_up.firstname} {signed_up.lastname}"
)
info = {
"register_id": register_id,
"firstname": signed_up.firstname,
Expand All @@ -242,7 +249,9 @@ async def confirm_join(
params = {"info": info_str}
registration_url = f"{DEFINE.credentials_url}register/?{urlencode(params)}"

logger.opt(ansi=True).debug(f"Creating email with registration url <u><red>{registration_url}</red></u>")
logger.opt(colors=True).debug(
f"Creating email with registration url <u><red>{registration_url}</red></u>"
)
send_register_email(
background_tasks, signup_email, mail_from_config(dsrc.config), registration_url
)
Expand Down
41 changes: 29 additions & 12 deletions backend/src/apiserver/app/routers/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ async def request_password_change(
params = {"reset_id": flow_id, "email": change_pass.email}
reset_url = f"{DEFINE.credentials_url}reset/?{urlencode(params)}"

logger.opt(ansi=True).debug(f"Creating password reset email with url <u><red>{reset_url}</red></u>")
logger.opt(colors=True).debug(
f"Creating password reset email with url <u><red>{reset_url}</red></u>"
)
send_reset_email(
background_tasks,
change_pass.email,
Expand All @@ -89,7 +91,10 @@ async def update_password_start(
) -> PasswordResponse:
stored_email = await data.trs.pop_string(dsrc, update_pass.flow_id)
if stored_email is None:
reason = f"Password reset of account {update_pass.email}: No reset has been requested for this user."
reason = (
f"Password reset of account {update_pass.email}: No reset has been"
" requested for this user."
)
raise ErrorResponse(
400, err_type="invalid_reset", err_desc=reason, debug_key="no_user_reset"
)
Expand Down Expand Up @@ -117,7 +122,9 @@ async def update_password_start(
debug_key="reset_user_not_exists",
)

logger.debug(f"Initiating password reset for user {u.user_id} with email {update_pass.email}")
logger.debug(
f"Initiating password reset for user {u.user_id} with email {update_pass.email}"
)
return await send_register_start(
dsrc.store, auth_context.register_ctx, u.user_id, update_pass.client_request
)
Expand Down Expand Up @@ -172,11 +179,11 @@ async def update_email(
async with data.get_conn(dsrc) as conn:
u = await ops.user.get_user_by_id(conn, user_id)
except NoDataError:
message = f"User {user_id} updating email to {new_email.new_email} no longer exists."
logger.debug(message)
raise ErrorResponse(
400, "bad_update", message, "update_user_empty"
message = (
f"User {user_id} updating email to {new_email.new_email} no longer exists."
)
logger.debug(message)
raise ErrorResponse(400, "bad_update", message, "update_user_empty")
old_email = u.email

flow_id = auth.core.util.random_time_hash_hex(user_id)
Expand All @@ -196,9 +203,14 @@ async def update_email(
)

await data.trs.reg.store_update_email(dsrc, user_id, state)
logger.debug(f"Stored user {user_id} email change from {old_email} to {new_email.new_email} with flow_id {flow_id}.")
logger.debug(
f"Stored user {user_id} email change from {old_email} to"
f" {new_email.new_email} with flow_id {flow_id}."
)

logger.opt(ansi=True).debug(f"Creating email change email with url <red><u>{reset_url}</u></red>")
logger.opt(colors=True).debug(
f"Creating email change email with url <red><u>{reset_url}</u></red>"
)
send_change_email_email(
background_tasks,
new_email.new_email,
Expand Down Expand Up @@ -229,7 +241,9 @@ async def update_email_check(
auth_context.login_ctx, dsrc.store, update_check.code
)
except NoDataError as e:
logger.debug(f"No flow_user for code {update_check.code} with error {e.message}")
logger.debug(
f"No flow_user for code {update_check.code} with error {e.message}"
)
reason = "Expired or missing auth code"
raise ErrorResponse(
status_code=400,
Expand Down Expand Up @@ -276,7 +290,7 @@ async def update_email_check(
400,
err_type="bad_update",
err_desc=reason,
debug_key="update_email_user_not_exists"
debug_key="update_email_user_not_exists",
)

# If someone changed their email by now, we do not want it possible to happen again
Expand All @@ -297,7 +311,10 @@ async def update_email_check(
)
if count_ud != 1:
raise DataError("Internal data error.", "user_data_error")
logger.debug(f"User {user_id} successfully changed email from {stored_email.old_email} to {stored_email.new_email}.")
logger.debug(
f"User {user_id} successfully changed email from {stored_email.old_email} to"
f" {stored_email.new_email}."
)

return ChangedEmailResponse(
old_email=stored_email.old_email, new_email=stored_email.new_email
Expand Down
12 changes: 10 additions & 2 deletions backend/src/apiserver/data/api/trainings.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
from datetime import date
from schema.model.model import C_EVENTS_CATEGORY, C_EVENTS_DATE, C_EVENTS_DESCRIPTION, C_EVENTS_ID, CLASS_EVENTS_TABLE, CLASS_ID
from schema.model.model import (
C_EVENTS_CATEGORY,
C_EVENTS_DATE,
C_EVENTS_DESCRIPTION,
C_EVENTS_ID,
CLASS_EVENTS_TABLE,
CLASS_ID,
)
from sqlalchemy.ext.asyncio import AsyncConnection
from store.db import LiteralDict, insert_many


async def add_training_event(
conn: AsyncConnection,
classification_id: int,
Expand All @@ -16,7 +24,7 @@ async def add_training_event(
idList = []
event_rows: list[LiteralDict] = []
for subCategory in categories:
subEventId = f'training{event_date.isoformat()}{subCategory}'
subEventId = f"training{event_date.isoformat()}{subCategory}"
idList.append(subEventId)

event_row: LiteralDict = {
Expand Down

0 comments on commit e240eda

Please sign in to comment.