felhasználói felületre pü
This commit is contained in:
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user