Separate staff roles and protect message delivery with operator guides
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -80,10 +80,15 @@ class UserService:
|
||||
@staticmethod
|
||||
async def delete_user(session: AsyncSession, user_id: int) -> bool:
|
||||
"""Удалить пользователя и все связанные данные"""
|
||||
user = await session.get(User, user_id)
|
||||
user = await session.scalar(select(User).where(User.id == user_id).with_for_update()
|
||||
.execution_options(populate_existing=True))
|
||||
if not user:
|
||||
return False
|
||||
|
||||
from .config import ADMIN_IDS, CASHIER_IDS
|
||||
if user.is_admin or user.is_cashier or user.telegram_id in set(ADMIN_IDS) | set(CASHIER_IDS):
|
||||
return False
|
||||
|
||||
# Keep records needed by draws, claims, chat history, or staff audit trails.
|
||||
# Cleanup may delete only users without linked data; moderation uses bans.
|
||||
from .database import Base
|
||||
@@ -107,17 +112,6 @@ class UserService:
|
||||
await session.commit()
|
||||
return True
|
||||
|
||||
@staticmethod
|
||||
async def set_admin(session: AsyncSession, telegram_id: int, is_admin: bool = True) -> bool:
|
||||
"""Установить/снять права администратора"""
|
||||
result = await session.execute(
|
||||
update(User)
|
||||
.where(User.telegram_id == telegram_id)
|
||||
.values(is_admin=is_admin)
|
||||
)
|
||||
await session.commit()
|
||||
return result.rowcount > 0
|
||||
|
||||
@staticmethod
|
||||
async def set_account_number(session, telegram_id, account_number):
|
||||
from sqlalchemy.exc import IntegrityError
|
||||
|
||||
Reference in New Issue
Block a user