felhasználói felületre pü

This commit is contained in:
Roo
2026-07-27 08:39:18 +00:00
parent c9118bf52f
commit 6f28d3e70d
72 changed files with 6311 additions and 749 deletions

View File

@@ -33,6 +33,7 @@ from app.models.marketplace.commission import (
CommissionTier,
)
from app.models.identity.identity import User, Wallet
from app.models.system import SystemParameter
from app.models.system.audit import (
FinancialLedger,
LedgerEntryType,
@@ -589,26 +590,59 @@ async def _credit_commission_to_wallet(
)
async def _get_inactivity_threshold(db: AsyncSession, default: int = 180) -> int:
"""
Read the inactivity_threshold_days from system.system_parameters.
Falls back to `default` (180) if not found.
"""
try:
stmt = select(SystemParameter).where(
SystemParameter.key == "inactivity_threshold_days",
SystemParameter.scope_level == "global",
SystemParameter.is_active == True,
)
result = await db.execute(stmt)
param = result.scalar_one_or_none()
if param is not None:
val = param.value
if isinstance(val, dict):
return int(val.get("value", val.get("days", default)))
return int(val)
except Exception as e:
logger.warning(
f"Failed to read inactivity_threshold_days from DB: {e}. "
f"Falling back to {default}."
)
return default
async def _is_user_recently_active(
db: AsyncSession,
user_id: int,
inactivity_days: int = 180,
inactivity_days: Optional[int] = None,
) -> bool:
"""
Check if a user has been active within the last `inactivity_days` days.
Check if a user has been active within the inactivity threshold.
A user is considered active if:
1. Their subscription is active (subscription_expires_at > now), OR
2. They have a FinancialLedger entry within the inactivity window.
The inactivity threshold is read from system.system_parameters
(key: inactivity_threshold_days), falling back to 180 days.
Args:
db: Database session.
user_id: The user to check.
inactivity_days: Number of days of inactivity before considered inactive.
inactivity_days: Optional override. If None, reads from DB settings.
Returns:
True if the user is recently active, False otherwise.
"""
# Resolve threshold: parameter override or DB setting
if inactivity_days is None:
inactivity_days = await _get_inactivity_threshold(db)
# Check subscription status first
user = await _lookup_user(db, user_id)
if not user: