frontend költség beállítások
This commit is contained in:
@@ -184,7 +184,11 @@ async def get_my_organizations(
|
||||
):
|
||||
"""
|
||||
A bejelentkezett felhasználóhoz tartozó szervezetek listázása.
|
||||
P0: Minden szervezethez visszaadja a valós max_vehicles és max_garages limiteket
|
||||
a subscription_tier JSONB rules alapján.
|
||||
"""
|
||||
from app.models.core_logic import SubscriptionTier, OrganizationSubscription
|
||||
|
||||
subq = (
|
||||
select(Organization.id)
|
||||
.outerjoin(OrganizationMember, OrganizationMember.organization_id == Organization.id)
|
||||
@@ -206,6 +210,31 @@ async def get_my_organizations(
|
||||
)
|
||||
result = await db.execute(stmt)
|
||||
orgs = result.scalars().all()
|
||||
|
||||
# ── P0: Pre-fetch all org subscription tiers for limit resolution ──
|
||||
org_ids = [o.id for o in orgs]
|
||||
org_tier_map: dict[int, tuple[int, int]] = {}
|
||||
if org_ids:
|
||||
org_subs_stmt = (
|
||||
select(OrganizationSubscription.org_id, SubscriptionTier)
|
||||
.join(SubscriptionTier, OrganizationSubscription.tier_id == SubscriptionTier.id)
|
||||
.where(
|
||||
OrganizationSubscription.org_id.in_(org_ids),
|
||||
OrganizationSubscription.is_active == True
|
||||
)
|
||||
.distinct(OrganizationSubscription.org_id)
|
||||
.order_by(OrganizationSubscription.org_id, OrganizationSubscription.valid_from.desc())
|
||||
)
|
||||
org_subs_result = await db.execute(org_subs_stmt)
|
||||
for row in org_subs_result:
|
||||
o_id = row.org_id
|
||||
tier = row[1]
|
||||
if tier and tier.rules:
|
||||
allowances = tier.rules.get("allowances", {})
|
||||
org_tier_map[o_id] = (
|
||||
int(allowances.get("max_vehicles", 1)),
|
||||
int(allowances.get("max_garages", 1)),
|
||||
)
|
||||
|
||||
return [
|
||||
{
|
||||
@@ -220,6 +249,11 @@ async def get_my_organizations(
|
||||
"is_active": o.is_active,
|
||||
"is_deleted": o.is_deleted,
|
||||
"subscription_plan": o.subscription_plan,
|
||||
"subscription_expires_at": o.subscription_expires_at.isoformat() if o.subscription_expires_at else None,
|
||||
"subscription_tier_id": o.subscription_tier_id,
|
||||
# P0: Real limits from subscription tier
|
||||
"max_vehicles": org_tier_map.get(o.id, (o.base_asset_limit or 1, 1))[0],
|
||||
"max_garages": org_tier_map.get(o.id, (1, 1))[1],
|
||||
"org_type": o.org_type.value if hasattr(o.org_type, 'value') else str(o.org_type),
|
||||
"visual_settings": o.visual_settings if hasattr(o, 'visual_settings') else None,
|
||||
"user_role": _get_user_role(o, current_user.id),
|
||||
|
||||
Reference in New Issue
Block a user