RABAC felépítése megtörtént ill hirdetési portál alapok lerakva

This commit is contained in:
Roo
2026-06-19 06:06:34 +00:00
parent fe3c32597d
commit 9ba2d9180d
30 changed files with 4336 additions and 76 deletions

View File

@@ -7,7 +7,7 @@ from app.api.deps import get_db, get_current_user
from app.models.identity import User
from app.models import Asset # JAVÍTVA: Asset modell
from app.models.marketplace.organization import Organization
from app.models.core_logic import SubscriptionTier
from app.models.core_logic import SubscriptionTier, OrganizationSubscription
logger = logging.getLogger(__name__)
@@ -18,6 +18,7 @@ async def scan_registration_document(file: UploadFile = File(...), db: AsyncSess
# ── P0 FEATURE: Quota engine sync — read org's subscription_tier rules ──
# Instead of hardcoded plan-based lookup from system_parameters,
# we now read the organization's assigned subscription_tier rules.
# P0 BOOSTER: extra_allowances.extra_vehicles is added on top.
max_allowed = 1 # default fallback
if current_user.scope_id:
@@ -37,6 +38,22 @@ async def scan_registration_document(file: UploadFile = File(...), db: AsyncSess
elif org:
# Fallback to legacy base_asset_limit if no tier assigned
max_allowed = max(org.base_asset_limit or 1, 1)
# ── P0 BOOSTER: Add extra_allowances.extra_vehicles ──
try:
org_sub_stmt = select(OrganizationSubscription.extra_allowances).where(
OrganizationSubscription.org_id == current_user.scope_id,
OrganizationSubscription.is_active == True
).limit(1)
org_sub_result = await db.execute(org_sub_stmt)
extra_allowances = org_sub_result.scalar_one_or_none()
if extra_allowances and isinstance(extra_allowances, dict):
extra_vehicles = int(extra_allowances.get('extra_vehicles', 0))
max_allowed += extra_vehicles
if extra_vehicles > 0:
logger.info(f"[P0 BOOSTER] Extra vehicles for org {current_user.scope_id}: +{extra_vehicles}")
except Exception as e:
logger.debug(f"Could not read extra_allowances for org {current_user.scope_id}: {e}")
stmt_count = select(func.count(Asset.id)).where(
Asset.owner_org_id == current_user.scope_id,