fix(공통): 로그인 후 보던 화면으로 복귀 + 깨진 users.json 덮어쓰기 방지

- app/store.py login_redirect(): 로그인 전 화면 주소를 /login?next= 로 넘긴다(GET 만 —
  폼 POST 주소로 돌아가면 405). 경비·쿠팡·휴가·말레이시아·배송·카페24·실적 11곳이
  next 없이 /login 으로 보내던 것과 프로젝트·입출고·안내문 발송의 복사본 4벌을 이 함수로.
- UserStore._read: JSONDecodeError 를 빈 목록으로 삼키지 않는다 — 다음 로그인이 전체
  사용자·권한을 그 한 명으로 덮어쓰던 것을 막는다.
- tests/test_login_redirect.py

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-30 10:45:58 +09:00
parent c9b4fa36fe
commit 007a16eb9c
12 changed files with 108 additions and 40 deletions
+13 -1
View File
@@ -12,6 +12,9 @@ import tempfile
import threading
from pathlib import Path
from typing import Any, Iterable
from urllib.parse import quote
from fastapi.responses import RedirectResponse
from .timezone import now_kst_iso
@@ -67,7 +70,7 @@ class UserStore:
try:
with self._path.open("r", encoding="utf-8") as f:
data = json.load(f)
except (FileNotFoundError, json.JSONDecodeError):
except FileNotFoundError: # 깨진 JSON 은 잡지 않는다 — 빈 목록으로 읽으면 다음 로그인이 전체 사용자를 덮어쓴다
data = {"users": {}}
if "users" not in data or not isinstance(data["users"], dict):
data["users"] = {}
@@ -265,3 +268,12 @@ def is_approver(user_rec: dict[str, Any] | None, kind: str) -> bool:
def allowed_modules(user_rec: dict[str, Any] | None) -> set[str]:
return {m for m in MODULE_KEYS if has_module(user_rec, m)}
def login_redirect(request: Any) -> RedirectResponse:
"""로그인 화면으로 — 로그인 뒤 지금 보던 화면(경로+쿼리)으로 돌아온다(모든 모듈 화면 공통).
GET 만 next 를 붙인다(폼 POST 주소로 돌아가면 GET 이라 405 가 난다)."""
if request.method != "GET":
return RedirectResponse(url="/login", status_code=303)
here = request.url.path + ("?" + request.url.query if request.url.query else "")
return RedirectResponse(url="/login?next=" + quote(here, safe=""), status_code=303)