Ariella/gdpr.py
Dan 27b051f9eb DOC: Added *.db to the .gitignore to prevent any data from being shared.
FEAT: Updated code to start following GDPR compliance.
2024-06-19 09:29:16 -04:00

34 lines
960 B
Python

import aiosqlite
async def check_consent(user_id: int) -> bool:
async with aiosqlite.connect("ariella.db") as db:
cursor = await db.execute(
"SELECT consent FROM user_consent WHERE user_id = ?",
(user_id,)
)
row = await cursor.fetchone()
return row and row[0] == 1
async def give_consent(user_id: int):
async with aiosqlite.connect("ariella.db") as db:
await db.execute(
"INSERT OR REPLACE INTO user_consent (user_id, consent) VALUES (?, ?)", # noqa: E501
(user_id, 1)
)
await db.commit()
async def revoke_consent(user_id: int):
async with aiosqlite.connect("ariella.db") as db:
await db.execute(
"DELETE FROM user_consent WHERE user_id = ?",
(user_id,)
)
await db.execute(
"DELETE FROM user_notes WHERE user_id = ?",
(user_id,)
)
await db.commit()