Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delete user avatars in user deletion api #9

Merged
merged 3 commits into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions app/adapters/assets.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import logging

import httpx

from app import settings

assets_service_http_client = httpx.AsyncClient(
base_url=settings.ASSETS_SERVICE_BASE_URL,
)


async def delete_avatar_by_user_id(user_id: int) -> None:
try:
response = await assets_service_http_client.delete(
f"/api/v1/users/{user_id}/avatar",
)
if response.status_code == 404:
return None
response.raise_for_status()
except Exception:
logging.exception(
"Failed to delete user avatar by user id",
extra={"user_id": user_id},
)
return None
2 changes: 2 additions & 0 deletions app/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,5 @@ def read_bool(s: str) -> bool:
AWS_S3_BUCKET_NAME = os.environ["AWS_S3_BUCKET_NAME"]
AWS_S3_ACCESS_KEY_ID = os.environ["AWS_S3_ACCESS_KEY_ID"]
AWS_S3_SECRET_ACCESS_KEY = os.environ["AWS_S3_SECRET_ACCESS_KEY"]

ASSETS_SERVICE_BASE_URL = os.environ["ASSETS_SERVICE_BASE_URL"]
2 changes: 2 additions & 0 deletions app/usecases/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import app.state
from app import security
from app.adapters import assets
from app.common_types import UserPrivileges
from app.errors import Error
from app.errors import ErrorCode
Expand Down Expand Up @@ -314,6 +315,7 @@ async def delete_one_by_user_id(user_id: int, /) -> None | Error:
# TODO: split this to make it more clear what's being done
# at the usecase layer
await users.anonymize_one_by_user_id(user_id)
await assets.delete_avatar_by_user_id(user_id)
FrostiDrinks marked this conversation as resolved.
Show resolved Hide resolved

# TODO: (technically required) anonymize data in data backups

Expand Down