优化(账号自动化): 履约保护登录配额与重登优先级
This commit is contained in:
@@ -69,6 +69,8 @@ class LoginQuotaUpdate(BaseModel):
|
||||
hourly_attempt_limit: int = Field(..., ge=1, le=100_000)
|
||||
per_account_daily_limit: int = Field(..., ge=1, le=100)
|
||||
onboarding_daily_limit: int = Field(..., ge=0, le=100_000)
|
||||
relogin_protected_daily_limit: int = Field(default=500, ge=0, le=100_000)
|
||||
lease_refresh_daily_limit: int = Field(default=300, ge=0, le=100_000)
|
||||
relogin_high_value_daily_limit: int = Field(..., ge=0, le=100_000)
|
||||
relogin_ordinary_daily_limit: int = Field(..., ge=0, le=100_000)
|
||||
manual_daily_limit: int = Field(..., ge=0, le=100_000)
|
||||
@@ -77,12 +79,21 @@ class LoginQuotaUpdate(BaseModel):
|
||||
enabled: bool = True
|
||||
|
||||
|
||||
def _login_quota_out(row: LoginQuotaSetting) -> dict[str, Any]:
|
||||
return {
|
||||
def _login_quota_out(
|
||||
row: LoginQuotaSetting,
|
||||
db: Session | None = None,
|
||||
) -> dict[str, Any]:
|
||||
payload: dict[str, Any] = {
|
||||
"daily_attempt_limit": int(row.daily_attempt_limit),
|
||||
"hourly_attempt_limit": int(row.hourly_attempt_limit),
|
||||
"per_account_daily_limit": int(row.per_account_daily_limit),
|
||||
"onboarding_daily_limit": int(row.onboarding_daily_limit),
|
||||
"relogin_protected_daily_limit": int(
|
||||
getattr(row, "relogin_protected_daily_limit", 500)
|
||||
),
|
||||
"lease_refresh_daily_limit": int(
|
||||
getattr(row, "lease_refresh_daily_limit", 300)
|
||||
),
|
||||
"relogin_high_value_daily_limit": int(
|
||||
row.relogin_high_value_daily_limit
|
||||
),
|
||||
@@ -95,6 +106,11 @@ def _login_quota_out(row: LoginQuotaSetting) -> dict[str, Any]:
|
||||
"enabled": bool(row.enabled),
|
||||
"updated_at": row.updated_at.isoformat() if row.updated_at else None,
|
||||
}
|
||||
if db is not None:
|
||||
from ..services.login_quota_service import get_login_quota_usage_summary
|
||||
|
||||
payload["usage"] = get_login_quota_usage_summary(db)
|
||||
return payload
|
||||
|
||||
|
||||
def _job_out(job: AutomationJob) -> dict[str, Any]:
|
||||
@@ -228,7 +244,7 @@ def get_login_quota(
|
||||
row = LoginQuotaSetting(id=1)
|
||||
db.add(row)
|
||||
db.commit()
|
||||
return _login_quota_out(row)
|
||||
return _login_quota_out(row, db=db)
|
||||
|
||||
|
||||
@router.get("/login-quota/recommendation")
|
||||
@@ -257,6 +273,8 @@ def update_login_quota(
|
||||
"hourly_attempt_limit",
|
||||
"per_account_daily_limit",
|
||||
"onboarding_daily_limit",
|
||||
"relogin_protected_daily_limit",
|
||||
"lease_refresh_daily_limit",
|
||||
"relogin_high_value_daily_limit",
|
||||
"relogin_ordinary_daily_limit",
|
||||
"manual_daily_limit",
|
||||
@@ -275,7 +293,7 @@ def update_login_quota(
|
||||
detail={"before": before, "after": _login_quota_out(row)},
|
||||
)
|
||||
db.commit()
|
||||
return _login_quota_out(row)
|
||||
return _login_quota_out(row, db=db)
|
||||
|
||||
|
||||
@router.patch("/jobs/{key}")
|
||||
|
||||
Reference in New Issue
Block a user