Merge pull request #390 from Fr1ngg/revert-389-bedolaga/fix-server-switch-function-in-promo-group

Revert "Fix server management visibility for promo groups"
This commit is contained in:
Egor
2025-09-25 14:17:22 +03:00
committed by GitHub
2 changed files with 1 additions and 43 deletions

View File

@@ -146,27 +146,6 @@ async def get_available_server_squads(
return result.scalars().unique().all()
async def get_promo_group_server_count(
db: AsyncSession,
promo_group_id: int,
*,
include_unavailable: bool = True,
) -> int:
"""Возвращает количество серверов, связанных с промогруппой."""
query = (
select(func.count(func.distinct(ServerSquad.id)))
.join(ServerSquad.allowed_promo_groups)
.where(PromoGroup.id == promo_group_id)
)
if not include_unavailable:
query = query.where(ServerSquad.is_available.is_(True))
result = await db.execute(query)
return result.scalar_one_or_none() or 0
async def update_server_squad_promo_groups(
db: AsyncSession, server_id: int, promo_group_ids: Iterable[int]
) -> Optional[ServerSquad]:

View File

@@ -4198,28 +4198,7 @@ async def _should_show_countries_management(user: Optional[User] = None) -> bool
promo_group_id = user.promo_group_id if user else None
countries = await _get_available_countries(promo_group_id)
available_countries = [c for c in countries if c.get('is_available', True)]
if len(available_countries) > 1:
return True
if user and getattr(user, "subscription", None):
connected = user.subscription.connected_squads or []
if len(set(connected)) > 1:
return True
if promo_group_id is not None:
from app.database.database import AsyncSessionLocal
from app.database.crud.server_squad import get_promo_group_server_count
async with AsyncSessionLocal() as db:
total_servers = await get_promo_group_server_count(
db,
promo_group_id,
include_unavailable=True,
)
return total_servers > 1
return False
return len(available_countries) > 1
except Exception as e:
logger.error(f"Ошибка проверки доступных серверов: {e}")
return True