Separate staff roles and protect message delivery with operator guides
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2026-09-13 21:00:53 +09:00
parent d5a9c13b68
commit 3c1a6a02a5
25 changed files with 916 additions and 548 deletions

View File

@@ -10,7 +10,8 @@ def build_release(destination=None):
destination = Path(destination or ROOT / "dist" / "lottery.tar.gz")
destination.parent.mkdir(parents=True, exist_ok=True)
allowed = ["src", "migrations", "scripts", "main.py", "requirements.txt", "alembic.ini",
"Dockerfile", "docker-compose.yml", ".dockerignore"]
"Dockerfile", "docker-compose.yml", ".dockerignore", "docs/ADMIN_GUIDE.md",
"docs/CASHIER_GUIDE.md", "docs/SYSTEM_ADMIN_GUIDE.md"]
with tarfile.open(destination, "w:gz") as archive:
for name in allowed:
entry = ROOT / name

View File

@@ -23,7 +23,7 @@ async def example_usage():
first_name="Администратор",
last_name="Бота"
)
await UserService.set_admin(session, 123456789, True)
# Staff roles are assigned by a system administrator through /staff.
print(f"✅ Создан админ: {admin.first_name} (@{admin.username})")
# Создаем обычных пользователей

View File

@@ -51,60 +51,11 @@ async def list_admins():
async def add_admin(telegram_id: int):
"""Добавить администратора"""
async with async_session_maker() as session:
# Проверяем, существует ли пользователь
user = await UserService.get_user_by_telegram_id(session, telegram_id)
if not user:
print(f"❌ Пользователь с ID {telegram_id} не найден")
return
if telegram_id in ADMIN_IDS:
print(f"❌ ID {telegram_id} - это главный администратор (.env)")
return
if user.is_admin:
print(f"❌ Пользователь {user.first_name or user.username} уже администратор")
return
# Назначаем админа
success = await UserService.set_admin(session, telegram_id, is_admin=True)
if success:
name = user.first_name or user.username or f"@ID_{telegram_id}"
print(f"{name} назначен администратором")
else:
print(f"❌ Ошибка при назначении администратора")
print(f"Use /add_admin {telegram_id} in the bot as a system administrator and confirm the change.")
async def remove_admin(telegram_id: int):
"""Удалить администратора"""
async with async_session_maker() as session:
if telegram_id in ADMIN_IDS:
print(f"❌ Нельзя удалить главного администратора (.env)")
print(f" Для изменения отредактируйте .env")
return
# Проверяем, существует ли пользователь
user = await UserService.get_user_by_telegram_id(session, telegram_id)
if not user:
print(f"❌ Пользователь с ID {telegram_id} не найден")
return
if not user.is_admin:
print(f"❌ Пользователь {user.first_name or user.username} не является администратором")
return
# Удаляем админа
success = await UserService.set_admin(session, telegram_id, is_admin=False)
if success:
name = user.first_name or user.username or f"@ID_{telegram_id}"
print(f"✅ Права администратора удалены у {name}")
else:
print(f"❌ Ошибка при удалении прав администратора")
print(f"Use /remove_admin {telegram_id} in the bot as a system administrator and confirm the change.")
async def main():