fix: Only delete selected containers, not all containers of a user
- Frontend API now accepts container_ids parameter - handleConfirmBulkDelete passes selected container IDs to API - Backend filters containers by ID instead of deleting all
This commit is contained in:
parent
e15583d8e5
commit
5c352fcf6f
24
admin_api.py
24
admin_api.py
|
|
@ -190,7 +190,7 @@ def resend_user_verification(user_id):
|
|||
@jwt_required()
|
||||
@admin_required()
|
||||
def delete_user_container(user_id):
|
||||
"""Loescht alle Container eines Benutzers (Multi-Container Support)"""
|
||||
"""Loescht spezifische Container eines Benutzers (Multi-Container Support)"""
|
||||
admin_id = get_jwt_identity()
|
||||
user = User.query.get(user_id)
|
||||
|
||||
|
|
@ -205,12 +205,30 @@ def delete_user_container(user_id):
|
|||
'skipped': True
|
||||
}), 200
|
||||
|
||||
# Hole container_ids aus Request-Body falls vorhanden
|
||||
data = request.get_json() or {}
|
||||
container_ids = data.get('container_ids', [])
|
||||
|
||||
# Bestimme welche Container zu löschen sind
|
||||
containers_to_delete = user.containers
|
||||
if container_ids:
|
||||
# Nur die spezifizierten Container löschen
|
||||
containers_to_delete = [c for c in user.containers if c.id in container_ids]
|
||||
|
||||
if not containers_to_delete:
|
||||
return jsonify({
|
||||
'message': 'Keine Container zum Löschen gefunden',
|
||||
'deleted': 0,
|
||||
'failed': [],
|
||||
'skipped': True
|
||||
}), 200
|
||||
|
||||
container_mgr = ContainerManager()
|
||||
deleted_count = 0
|
||||
failed_containers = []
|
||||
|
||||
# Iteriere über alle Container des Users
|
||||
for container in user.containers:
|
||||
# Iteriere über die Container die gelöscht werden sollen
|
||||
for container in containers_to_delete:
|
||||
if not container.container_id:
|
||||
continue
|
||||
|
||||
|
|
|
|||
|
|
@ -216,7 +216,7 @@ export default function AdminPage() {
|
|||
|
||||
// Lösche Container pro User
|
||||
for (const [userId, containerIds] of containersByUser) {
|
||||
const { data, error } = await adminApi.deleteUserContainer(userId);
|
||||
const { data, error } = await adminApi.deleteUserContainer(userId, containerIds);
|
||||
|
||||
if (error) {
|
||||
totalFailed += containerIds.length;
|
||||
|
|
|
|||
|
|
@ -289,9 +289,10 @@ export const adminApi = {
|
|||
}),
|
||||
|
||||
// Container
|
||||
deleteUserContainer: (id: number) =>
|
||||
deleteUserContainer: (id: number, containerIds?: number[]) =>
|
||||
fetchApi<AdminActionResponse>(`/api/admin/users/${id}/container`, {
|
||||
method: "DELETE",
|
||||
body: containerIds ? JSON.stringify({ container_ids: containerIds }) : undefined,
|
||||
}),
|
||||
|
||||
// Delete User
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user