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

@@ -10,7 +10,10 @@ Architektúra:
A csomagok rules JSONB oszlopa egy szabványos struktúrát követ:
{
"type": "private" | "corporate",
"pricing": {"monthly_price": float, "yearly_price": float, "currency": "EUR"},
"pricing_zones": {
"HU": {"monthly_price": 3000, "yearly_price": 32500, "currency": "HUF"},
"DEFAULT": {"monthly_price": 12.99, "yearly_price": 129.99, "currency": "EUR"}
},
"allowances": {"max_vehicles": int, "max_garages": int, "monthly_free_credits": int},
"entitlements": ["SRV_..."],
"affiliate": {"commission_rate_percent": int, "referral_bonus_credits": int}
@@ -31,6 +34,46 @@ logging.basicConfig(
logger = logging.getLogger("Seed-Packages")
# ---------------------------------------------------------------------------
# Pricing Zones helper
# ---------------------------------------------------------------------------
def pricing_zones(
eur_monthly: float,
eur_yearly: float,
eur_credit: int = 0,
huf_monthly: int = 0,
huf_yearly: int = 0,
huf_credit: int = 0,
usd_monthly: float = 0,
usd_yearly: float = 0,
usd_credit: int = 0,
) -> dict:
"""Create a pricing_zones dict with DEFAULT (EUR), HU (HUF), and optionally USD zones."""
zones = {
"DEFAULT": {
"monthly_price": eur_monthly,
"yearly_price": eur_yearly,
"currency": "EUR",
"credit_price": eur_credit if eur_credit > 0 else None,
},
}
if huf_monthly > 0:
zones["HU"] = {
"monthly_price": huf_monthly,
"yearly_price": huf_yearly,
"currency": "HUF",
"credit_price": huf_credit if huf_credit > 0 else None,
}
if usd_monthly > 0:
zones["US"] = {
"monthly_price": usd_monthly,
"yearly_price": usd_yearly,
"currency": "USD",
"credit_price": usd_credit if usd_credit > 0 else None,
}
return zones
# ---------------------------------------------------------------------------
# Csomagdefiníciók
# ---------------------------------------------------------------------------
@@ -46,6 +89,12 @@ PACKAGES = [
"currency": "EUR",
"credit_price": 0,
},
"pricing_zones": pricing_zones(
eur_monthly=0.0,
eur_yearly=0.0,
huf_monthly=0,
huf_yearly=0,
),
"allowances": {
"max_vehicles": 1,
"max_garages": 1,
@@ -59,6 +108,19 @@ PACKAGES = [
"lifecycle": {
"is_public": True,
},
"duration": {
"days": 30,
"allow_stacking": True,
},
"ad_policy": {
"show_ads": True,
"ad_free_grace_days": 0,
"max_daily_impressions": 50,
},
"marketing": {
"subtitle": "Alap szintű járműkövetés kezdőknek.",
"badge": "Ingyenes",
},
},
"is_custom": False,
},
@@ -73,6 +135,17 @@ PACKAGES = [
"currency": "EUR",
"credit_price": 500,
},
"pricing_zones": pricing_zones(
eur_monthly=4.99,
eur_yearly=49.99,
eur_credit=500,
huf_monthly=1890,
huf_yearly=18990,
huf_credit=500,
usd_monthly=5.99,
usd_yearly=59.99,
usd_credit=500,
),
"allowances": {
"max_vehicles": 3,
"max_garages": 1,
@@ -86,6 +159,20 @@ PACKAGES = [
"lifecycle": {
"is_public": True,
},
"duration": {
"days": 30,
"allow_stacking": True,
},
"ad_policy": {
"show_ads": True,
"ad_free_grace_days": 3,
"max_daily_impressions": 100,
},
"marketing": {
"subtitle": "Kisebb flotta esetén ideális választás.",
"badge": "Pro",
"highlight_color": "#70BC84",
},
},
"is_custom": False,
},
@@ -100,6 +187,17 @@ PACKAGES = [
"currency": "EUR",
"credit_price": 1200,
},
"pricing_zones": pricing_zones(
eur_monthly=9.99,
eur_yearly=99.99,
eur_credit=1200,
huf_monthly=3790,
huf_yearly=37990,
huf_credit=1200,
usd_monthly=11.99,
usd_yearly=119.99,
usd_credit=1200,
),
"allowances": {
"max_vehicles": 10,
"max_garages": 1,
@@ -113,6 +211,20 @@ PACKAGES = [
"lifecycle": {
"is_public": True,
},
"duration": {
"days": 30,
"allow_stacking": True,
},
"ad_policy": {
"show_ads": False,
"ad_free_grace_days": 0,
"max_daily_impressions": None,
},
"marketing": {
"subtitle": "VIP profi garázs kisvállalkozók számára.",
"badge": "VIP",
"highlight_color": "#F59E0B",
},
},
"is_custom": False,
},
@@ -127,6 +239,17 @@ PACKAGES = [
"currency": "EUR",
"credit_price": 3000,
},
"pricing_zones": pricing_zones(
eur_monthly=29.99,
eur_yearly=299.99,
eur_credit=3000,
huf_monthly=11990,
huf_yearly=119990,
huf_credit=3000,
usd_monthly=34.99,
usd_yearly=349.99,
usd_credit=3000,
),
"allowances": {
"max_vehicles": 20,
"max_garages": 3,
@@ -140,6 +263,20 @@ PACKAGES = [
"lifecycle": {
"is_public": True,
},
"duration": {
"days": 30,
"allow_stacking": True,
},
"ad_policy": {
"show_ads": False,
"ad_free_grace_days": 0,
"max_daily_impressions": None,
},
"marketing": {
"subtitle": "Közepes flották számára tervezve.",
"badge": "Prémium",
"highlight_color": "#3B82F6",
},
},
"is_custom": False,
},
@@ -154,6 +291,17 @@ PACKAGES = [
"currency": "EUR",
"credit_price": 6000,
},
"pricing_zones": pricing_zones(
eur_monthly=59.99,
eur_yearly=599.99,
eur_credit=6000,
huf_monthly=23990,
huf_yearly=239990,
huf_credit=6000,
usd_monthly=69.99,
usd_yearly=699.99,
usd_credit=6000,
),
"allowances": {
"max_vehicles": 50,
"max_garages": 10,
@@ -171,6 +319,20 @@ PACKAGES = [
"lifecycle": {
"is_public": True,
},
"duration": {
"days": 30,
"allow_stacking": True,
},
"ad_policy": {
"show_ads": False,
"ad_free_grace_days": 0,
"max_daily_impressions": None,
},
"marketing": {
"subtitle": "Nagy flották prémium menedzsmentje.",
"badge": "Plus",
"highlight_color": "#8B5CF6",
},
},
"is_custom": False,
},
@@ -185,6 +347,17 @@ PACKAGES = [
"currency": "EUR",
"credit_price": 15000,
},
"pricing_zones": pricing_zones(
eur_monthly=149.99,
eur_yearly=1499.99,
eur_credit=15000,
huf_monthly=59990,
huf_yearly=599990,
huf_credit=15000,
usd_monthly=169.99,
usd_yearly=1699.99,
usd_credit=15000,
),
"allowances": {
"max_vehicles": 200,
"max_garages": 50,
@@ -203,6 +376,20 @@ PACKAGES = [
"lifecycle": {
"is_public": True,
},
"duration": {
"days": 30,
"allow_stacking": True,
},
"ad_policy": {
"show_ads": False,
"ad_free_grace_days": 0,
"max_daily_impressions": None,
},
"marketing": {
"subtitle": "Vállalati szintű flottairányítás.",
"badge": "VIP",
"highlight_color": "#EF4444",
},
},
"is_custom": False,
},
@@ -215,28 +402,31 @@ async def seed():
logger.info("=" * 60)
async with AsyncSessionLocal() as db:
# 1. Töröljük a meglévő rekordokat (tiszta lap)
logger.info("Törlöm a meglévő subscription_tiers rekordokat...")
await db.execute(delete(SubscriptionTier))
await db.commit()
logger.info("✅ Meglévő rekordok törölve.")
# 1. UPSERT: Meglévő csomagok frissítése vagy új beszúrása
from sqlalchemy.dialects.postgresql import insert as pg_insert
# 2. Beszúrjuk a 6 új csomagot
inserted_count = 0
upserted_count = 0
for pkg in PACKAGES:
tier = SubscriptionTier(
stmt = pg_insert(SubscriptionTier).values(
name=pkg["name"],
rules=pkg["rules"],
is_custom=pkg["is_custom"],
)
db.add(tier)
inserted_count += 1
logger.info(f" Hozzáadva: {pkg['name']}")
stmt = stmt.on_conflict_do_update(
index_elements=[SubscriptionTier.name],
set_={
"rules": stmt.excluded.rules,
"is_custom": stmt.excluded.is_custom,
}
)
await db.execute(stmt)
upserted_count += 1
logger.info(f" Upsert: {pkg['name']}")
await db.commit()
logger.info(f"{inserted_count} csomag sikeresen beszúrva.")
logger.info(f"{upserted_count} csomag sikeresen upsertelve.")
# 3. Visszaigazolás: listázzuk ki az összes rekordot
# 2. Visszaigazolás
logger.info("-" * 60)
logger.info("Visszaigazolás - system.subscription_tiers tartalma:")
logger.info("-" * 60)
@@ -256,7 +446,7 @@ async def seed():
logger.info(f"\n✅ Összesen {len(tiers)} aktív csomag a rendszerben.")
# 4. JSONB példa kiírása
# 3. JSONB példa kiírása
if tiers:
sample = tiers[0]
logger.info("=" * 60)