Add account deletion, admin user removal, household deletion, grayed-out other-user chips (47 tests)
This commit is contained in:
@@ -111,6 +111,19 @@ def count_household_users(household_id: int) -> int:
|
||||
).fetchone()[0]
|
||||
|
||||
|
||||
def delete_household(household_id: int) -> None:
|
||||
"""Delete a household, all its users, and all their responses."""
|
||||
with get_db() as db:
|
||||
# Delete responses for all users in the household
|
||||
db.execute(
|
||||
"DELETE FROM responses WHERE user_id IN "
|
||||
"(SELECT id FROM users WHERE household_id = ?)",
|
||||
(household_id,),
|
||||
)
|
||||
db.execute("DELETE FROM users WHERE household_id = ?", (household_id,))
|
||||
db.execute("DELETE FROM households WHERE id = ?", (household_id,))
|
||||
|
||||
|
||||
# ── Users ─────────────────────────────────────────────────────────────────────
|
||||
|
||||
def get_user_by_id(user_id: int) -> dict | None:
|
||||
@@ -143,6 +156,13 @@ def create_user(username: str, password_hash: str, household_id: int,
|
||||
return get_user_by_id(user_id)
|
||||
|
||||
|
||||
def delete_user(user_id: int) -> None:
|
||||
"""Delete a user and all their responses."""
|
||||
with get_db() as db:
|
||||
db.execute("DELETE FROM responses WHERE user_id = ?", (user_id,))
|
||||
db.execute("DELETE FROM users WHERE id = ?", (user_id,))
|
||||
|
||||
|
||||
def get_household_users(household_id: int) -> list[dict]:
|
||||
"""Return all users in a given household."""
|
||||
with get_db() as db:
|
||||
|
||||
Reference in New Issue
Block a user