fix: 会话失效时自动重新登录,管理端可改判断依据
This commit is contained in:
@@ -78,6 +78,7 @@ class AdminStudySettingsBody(BaseModel):
|
||||
port: int | None = None
|
||||
username: str = ""
|
||||
password: str | None = None
|
||||
hours_source: str | None = None
|
||||
|
||||
|
||||
def require_admin(request: Request, db: Session = Depends(get_db)) -> str:
|
||||
@@ -208,6 +209,7 @@ def put_users_study_settings(
|
||||
port=body.port,
|
||||
username=body.username,
|
||||
password=body.password,
|
||||
hours_source=body.hours_source,
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -102,6 +102,8 @@ def list_users(db: Session) -> list[dict]:
|
||||
"hours_month": account.hours_month or "",
|
||||
"study_active": work_running(account.employee_id),
|
||||
"state": str(live.get("state") or ""),
|
||||
"message": str(live.get("message") or ""),
|
||||
"hours_met": control["hours_met"],
|
||||
}
|
||||
)
|
||||
return rows
|
||||
@@ -364,7 +366,10 @@ def set_study_action(db: Session, employee_ids: list[str], action: str) -> dict:
|
||||
db.commit()
|
||||
|
||||
if kind == "start":
|
||||
from euniv.autostudy import clear_study_hold
|
||||
|
||||
for account in accounts:
|
||||
clear_study_hold(account.employee_id)
|
||||
sync_work(account.employee_id)
|
||||
else:
|
||||
for account in accounts:
|
||||
@@ -387,8 +392,14 @@ def set_study_settings(
|
||||
port: object = None,
|
||||
username: str = "",
|
||||
password: str | None = None,
|
||||
hours_source: str | None = None,
|
||||
) -> dict:
|
||||
accounts = _accounts_by_ids(db, employee_ids)
|
||||
chosen_source = None
|
||||
if hours_source is not None:
|
||||
chosen_source = str(hours_source).strip().lower()
|
||||
if chosen_source not in {"api", "history"}:
|
||||
raise HTTPException(status_code=400, detail="学时判断须为官方统计或历史统计")
|
||||
if monthly_target is not None:
|
||||
if not isinstance(monthly_target, int) or isinstance(monthly_target, bool) or not 0 <= monthly_target <= 9999:
|
||||
raise HTTPException(status_code=400, detail="每月学时目标须为 0 到 9999 的整数")
|
||||
@@ -403,6 +414,8 @@ def set_study_settings(
|
||||
account.study_schedule_enabled = bool(schedule_enabled)
|
||||
if workers is not None:
|
||||
apply_workers(account, workers)
|
||||
if chosen_source is not None:
|
||||
account.hours_source = chosen_source
|
||||
if scheme is not None:
|
||||
apply(account, scheme, host, port, username, password)
|
||||
except (StudyWindowError, CourseWorkersError, ProxyError) as exc:
|
||||
|
||||
Reference in New Issue
Block a user