feat: cascade-delete hosts when removing a network

When a VLAN/LAN is deleted, all non-gateway, non-livebox devices
with an interface in that network are deleted automatically.
Gateway and livebox devices are preserved; their interface is
unlinked (vlan_id set to NULL).

The confirmation dialog now shows the exact count of devices
that will be deleted (all three locales: fr/en/es).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-05-18 10:48:36 +02:00
parent cf07461436
commit 14de657deb
4 changed files with 30 additions and 3 deletions
+15
View File
@@ -97,6 +97,21 @@ def delete_vlan(vlan_pk: int, db: Session = Depends(get_db)):
db_vlan = db.query(models.Vlan).filter(models.Vlan.id == vlan_pk).first()
if not db_vlan:
raise HTTPException(status_code=404, detail="VLAN introuvable")
# Collect devices with an interface in this VLAN
ifaces = (
db.query(models.DeviceInterface)
.filter(models.DeviceInterface.vlan_id == vlan_pk)
.all()
)
device_ids = {i.device_id for i in ifaces}
for device_id in device_ids:
device = db.query(models.Device).filter(models.Device.id == device_id).first()
if device and not device.is_gateway and not device.is_livebox:
db.delete(device) # cascade deletes all its interfaces
# Gateway/livebox interfaces in this VLAN will be SET NULL by SQLAlchemy
db.delete(db_vlan)
db.commit()
return {"ok": True}