1
0
Fork 0
forked from sr2/cloud-api

feat: user soft delete

This commit is contained in:
Chris Milne 2026-06-22 15:36:32 +01:00
parent 5b98be9787
commit a9e059bf0a

View file

@ -7,6 +7,7 @@ Endpoints:
- [GET](/user/): [super admin]: Returns user(id) details. - [GET](/user/): [super admin]: Returns user(id) details.
- [DELETE](/user/): [super admin]: Removes a User(id) from the hub database. - [DELETE](/user/): [super admin]: Removes a User(id) from the hub database.
""" """
from datetime import datetime, timezone
from fastapi import APIRouter, status, BackgroundTasks from fastapi import APIRouter, status, BackgroundTasks
@ -104,7 +105,7 @@ async def get_user_by_id(
status.HTTP_404_NOT_FOUND: {"description": "User not found"}, status.HTTP_404_NOT_FOUND: {"description": "User not found"},
}, },
) )
async def delete_user_by_id( async def soft_delete_user_by_id(
db: DbSession, db: DbSession,
user_model: user_model_query_dependency, user_model: user_model_query_dependency,
su: super_admin_dependency, su: super_admin_dependency,
@ -112,7 +113,8 @@ async def delete_user_by_id(
""" """
Deletes the user with the provided ID from the database. This will not remove them from OIDC, and they will be automatically readded on next login. Deletes the user with the provided ID from the database. This will not remove them from OIDC, and they will be automatically readded on next login.
""" """
db.delete(user_model) user_model.active = False
user_model.deleted_at = datetime.now(tz=timezone.utc)
db.commit() db.commit()