Skip to content

Commit

Permalink
Add in some logging
Browse files Browse the repository at this point in the history
Just added in for PUT operators for user and admin as of now

Signed-off-by: Akhil Narang <me@akhilnarang.dev>
  • Loading branch information
akhilnarang committed Mar 20, 2021
1 parent d5d6970 commit 9ae2cb2
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
6 changes: 5 additions & 1 deletion app/app/api/api_v1/endpoints/admins.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import logging
from typing import Any, List

from fastapi import APIRouter, Depends, HTTPException
Expand Down Expand Up @@ -64,13 +65,16 @@ def update_admin(
*,
db: Session = Depends(deps.get_db),
admin_in: schemas.AdminUpdate,
_: models.Admin = Depends(deps.get_current_active_admin_with_permission("admin")),
current_admin: models.Admin = Depends(deps.get_current_active_admin_with_permission("admin")),
) -> Any:
"""
Update admin.
"""

if admin := crud.admin.get(db, admin_in.user_id):
logging.info(
f"Admin {current_admin.user_id} ({current_admin.user.email}) is updating Admin {admin.user_id} ({admin.user.email}) to {admin_in.__dict__}"
)
return crud.admin.update(db, db_obj=admin, obj_in=admin_in)

raise HTTPException(
Expand Down
7 changes: 5 additions & 2 deletions app/app/api/api_v1/endpoints/users.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import logging
from typing import Any, List

from fastapi import APIRouter, Body, Depends, File, HTTPException, UploadFile
Expand Down Expand Up @@ -136,7 +137,7 @@ def update_user(
db: Session = Depends(deps.get_db),
user_id: int,
user_in: schemas.UserUpdate,
_: models.Admin = Depends(deps.get_current_active_admin_with_permission("user")),
current_admin: models.Admin = Depends(deps.get_current_active_admin_with_permission("user")),
) -> Any:
"""
Update a user.
Expand All @@ -152,7 +153,9 @@ def update_user(
status_code=400,
detail=f"A {user.type} cannot have admin roles changed!",
)

logging.info(
f"Admin {current_admin.user_id} ({current_admin.user.email}) is updating User {user.id} ({user.email}) to {user_in.__dict__}"
)
return crud.user.update(db, db_obj=user, obj_in=user_in)

raise HTTPException(
Expand Down
2 changes: 2 additions & 0 deletions app/app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,5 @@
)

app.include_router(api_router, prefix=settings.API_V1_STR)

logging.info("Starting application")

0 comments on commit 9ae2cb2

Please sign in to comment.