feat: harden auth for public deploy + gantt, duration units, docker packaging
Security (fail-secure for production): - Refuse to start without PPM_PASSWORD/PPM_PASSWORD_HASH unless PPM_ALLOW_NO_AUTH=1 (local dev only) - Add login rate limiting (5 failures / 60s per client), enforced inside SessionManager.login so it cannot be bypassed at the endpoint layer - compose defaults PPM_COOKIE_SECURE=true for HTTPS behind reverse proxy - Add .dockerignore to keep runtime data/out of the image Features: - Task timeline gantt on home page (week/month zoom, horizontal scroll, infinite-arrow for open-ended dates, CSS Grid layout) - Duration metrics gain a second/minute/hour unit for input & display (canonical storage stays integer seconds) - Per-metric progress bars on home page (no more merged average) - Backfill historical records via date picker in the today-record card - Admin panel: stats overview, JSON import/restore, full task list mgmt Fixes: - Nullable task startDate; summarize handles missing start date - Task dialog cancel/close no longer submits the form - Import validates whole backup first, rejects path traversal, rebuilds archives, and replaces stale files Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -52,3 +52,42 @@ def test_invalid_input_and_auth(auth_client):
|
||||
forbidden = auth_client.post("/api/tasks", json=payload())
|
||||
assert forbidden.status_code == 403
|
||||
|
||||
|
||||
def test_duration_unit_and_backfill(client):
|
||||
task = client.post("/api/tasks", json={
|
||||
"name": "时长任务", "startDate": "2026-08-01",
|
||||
"metrics": [{"name": "专注", "kind": "duration", "period": "day", "durationUnit": "minute", "target": 120}],
|
||||
}).json()
|
||||
assert task["metrics"][0]["durationUnit"] == "minute"
|
||||
metric_id = task["metrics"][0]["metricId"]
|
||||
saved = client.put(f"/api/tasks/{task['taskId']}/daily/2026-08-10", json={"expectedVersion": 0, "values": [{"metricId": metric_id, "value": 3600}]})
|
||||
assert saved.status_code == 200
|
||||
summary = client.get(f"/api/tasks/{task['taskId']}/summary?date=2026-08-10").json()
|
||||
metric = summary["tasks"][task["taskId"]]["metrics"][0]
|
||||
assert metric["value"] == 3600, "时长仍以整数秒存储"
|
||||
assert metric.get("durationUnit") == "minute"
|
||||
|
||||
|
||||
def test_invalid_duration_unit_rejected(client):
|
||||
bad = client.post("/api/tasks", json={"name": "非法单位", "startDate": "2026-08-01", "metrics": [{"name": "x", "kind": "duration", "period": "day", "durationUnit": "year"}]})
|
||||
assert bad.status_code == 422
|
||||
|
||||
|
||||
def test_task_without_dates(client):
|
||||
task = client.post("/api/tasks", json={"name": "无日期任务", "metrics": [{"name": "完成", "kind": "checkin", "period": "day"}]}).json()
|
||||
assert task["startDate"] is None and task["endDate"] is None
|
||||
# 无开始日期的 lifetime 统计不应报错
|
||||
assert client.get(f"/api/tasks/{task['taskId']}/summary").status_code == 200
|
||||
|
||||
|
||||
def test_admin_stats_and_import(client):
|
||||
task = client.post("/api/tasks", json=payload("导入任务")).json()
|
||||
metric_id = task["metrics"][0]["metricId"]
|
||||
client.put(f"/api/tasks/{task['taskId']}/daily/2026-08-20", json={"expectedVersion": 0, "values": [{"metricId": metric_id, "value": 1}]})
|
||||
stats = client.get("/api/admin/stats").json()
|
||||
assert stats["taskCount"] == 1 and stats["dailyFactCount"] == 1
|
||||
exported = client.get("/api/export").json()
|
||||
imported = client.post("/api/admin/import", json=exported)
|
||||
assert imported.status_code == 200 and imported.json()["imported"] == 1
|
||||
assert client.get("/api/admin/stats").json()["taskCount"] == 1
|
||||
|
||||
|
||||
Reference in New Issue
Block a user