feat: Allow assigned admins to access admin panel via command and buttons
Some checks failed
continuous-integration/drone/pr Build is failing
Some checks failed
continuous-integration/drone/pr Build is failing
- Modified check_admin_access() to check both super admins (.env) and assigned admins (DB) - Updated /admin command handler to support both admin types - Replaced all is_admin() checks with async check_admin_access() in admin panel - Assigned admins can now use /admin command and navigate via buttons - Super admin check (is_super_admin) remains unchanged for admin management - Added proper async/await for database queries in all admin checks
This commit is contained in:
21
main.py
21
main.py
@@ -192,7 +192,26 @@ async def btn_main_menu(message: Message):
|
||||
async def cmd_admin(message: Message):
|
||||
"""Обработчик команды /admin (регистронезависимо) - перенаправляет в admin_panel"""
|
||||
from src.core.config import ADMIN_IDS
|
||||
if message.from_user.id not in ADMIN_IDS:
|
||||
from src.core.database import async_session_maker
|
||||
from src.core.models import User
|
||||
from sqlalchemy import select
|
||||
|
||||
# Проверяем, является ли пользователь главным администратором из .env
|
||||
user_id = message.from_user.id
|
||||
is_super_admin = user_id in ADMIN_IDS
|
||||
|
||||
# Проверяем, является ли пользователь назначенным администратором
|
||||
is_assigned_admin = False
|
||||
if not is_super_admin:
|
||||
async with async_session_maker() as session:
|
||||
user = await session.execute(
|
||||
select(User).where(User.telegram_id == user_id)
|
||||
)
|
||||
user = user.scalar_one_or_none()
|
||||
is_assigned_admin = user and user.is_admin
|
||||
|
||||
# Если не администратор ни того, ни другого типа
|
||||
if not (is_super_admin or is_assigned_admin):
|
||||
await message.answer("❌ Недостаточно прав для доступа к админ панели")
|
||||
return
|
||||
|
||||
|
||||
Reference in New Issue
Block a user