feat(vacation): 설정 화면·공휴일 설정 삭제 · 옵션 수정 = 관리자·승인자·통보자

- [설정] 버튼·설정 화면·공휴일 추가/삭제 삭제(예전 /vacation/settings 는 옵션으로), 쓰지 않는 CSS·db 공휴일 CRUD 정리
- 쉬는 날 = 국경일·대체공휴일 표(KR_HOLIDAYS)만 — vacation_holidays 는 남아 있지만 읽지 않음
- 옵션(승인자·통보자·잔여 연차) 수정 = ERP 관리자(수퍼 포함) + 지금 승인자 + 승인 통보자(_can_edit_options), 예전엔 관리자만
- 테스트: 실제 PG(국경일 표만), 실제 앱(통보자·승인자 수정 가능·그 밖 403, 설정 주소 없음·버튼 없음)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-26 15:16:40 +09:00
parent 6191118ac7
commit a12a862c47
13 changed files with 100 additions and 326 deletions
+33 -100
View File
@@ -3,7 +3,7 @@
- 경로: /vacation
- 권한: 로그인 + `vacation` 모듈 권한 (관리자는 항상 통과). 서버 측 검사.
승인/반려 = admin + (휴가 옵션에 승인자를 지정했으면 그 사람들, 아니면 `vacation_approver` 권한자) — 2026-10-27.
- 휴가 옵션(`/vacation/options`, 수정은 admin): 승인자·승인 통보자. 제출·승인·반려 메일은 `notify.py`
- 휴가 옵션(`/vacation/options`, 수정 = admin·승인자·통보자): 승인자·승인 통보자·잔여 연차. 공휴일 = 국경일 표(설정 화면 없음). 제출·승인·반려 메일은 `notify.py`
(처리한 사람 본인 Gmail — 입출고와 같은 Gmail 연결, 없으면 회사 SMTP).
- 데이터: VacationDBStore (vacation_db / PostgreSQL) 전용.
VACATION_DB_URL 미설정 시 store 가 None 이며, 각 페이지는 "설정 필요" 안내를 보여준다.
@@ -84,6 +84,23 @@ def _is_approver(request: Request, user: dict[str, Any]) -> bool:
return has_module(user, "vacation_approver")
def _can_edit_options(request: Request, user: dict[str, Any], opts: dict[str, Any] | None = None,
users: list[dict[str, Any]] | None = None) -> bool:
"""휴가 옵션(승인자·통보자·잔여 연차) 수정 — ERP 관리자(수퍼관리자 포함) + 지금 승인자(옵션 지정, 없으면 휴가 승인 권한자)
+ 승인 통보자(2026-10-27, 예전엔 관리자만)."""
from app.store import is_admin # noqa: WPS433
from . import notify # noqa: WPS433
if is_admin(user):
return True
opts = opts if opts is not None else _options(request)
email = str(user.get("email") or "").strip().lower()
if email in (opts.get("notifiers") or []):
return True
return email in notify.approver_emails(opts, users if users is not None else _vacation_users())
def _vacation_users() -> list[dict[str, Any]]:
"""휴가 모듈을 쓰는 등록 사용자(옵션 후보·메일 이름) — 이름 순."""
from app.main import user_store # noqa: WPS433
@@ -204,7 +221,7 @@ def _build_calendar(
range_start = weeks_dates[0][0]
range_end = weeks_dates[-1][-1]
# 쉬는 날 = 국경일·대체공휴일 + 휴가 설정 공휴일(db.holiday_map) — 빨강 + 날짜 밑 이름(2026-10-27)
# 쉬는 날 = 대한민국 국경일·대체공휴일(db.holiday_map) — 빨강 + 날짜 밑 이름(2026-10-27)
holiday_names = store.holiday_map(
date_from=range_start.isoformat(), date_to=range_end.isoformat()
)
@@ -344,7 +361,7 @@ def _form_context(request: Request, user: dict[str, Any]) -> dict[str, Any]:
def _red_holidays(request: Request) -> dict[str, str]:
"""날짜 팝업 공휴일(빨강·이름) — 국경일·대체공휴일 + 휴가 설정 공휴일, 작년~내년. 일수 계산과 같은 표(db.holiday_map)."""
"""날짜 팝업 공휴일(빨강·이름) — 국경일·대체공휴일, 작년~내년. 일수 계산과 같은 표(db.holiday_map)."""
st = _store(request)
if st is None:
return {}
@@ -461,104 +478,20 @@ def pending_page(request: Request) -> HTMLResponse:
)
@router.get("/settings", response_class=HTMLResponse)
def settings_page(request: Request) -> HTMLResponse:
from app.main import build_erp_nav, render_template # noqa: WPS433
from app.store import is_admin # noqa: WPS433
guard = _guard(request)
if not isinstance(guard, tuple):
return guard
store, user = guard
if not is_admin(user):
return render_template(
request,
"denied.html",
{"reason": "휴가 설정은 관리자만 접근할 수 있습니다.", "is_admin": False},
status_code=403,
)
today = today_kst()
try:
year = int(request.query_params.get("year") or today.year)
except ValueError:
year = today.year
return render_template(
request,
"vacation/settings.html",
{
"user": user,
"is_admin": True,
"is_approver": True,
"nav_items": build_erp_nav(user, active="vacation"),
"page_title": "휴가 — 설정",
"page_subtitle": "공휴일 관리 (잔여 연차는 옵션)",
"year": year,
"holidays": store.list_holidays(year=year),
},
)
@router.post("/settings/holidays")
def holiday_upsert(
request: Request,
holiday_date: str = Form(...),
name: str = Form(...),
kind: str = Form("public"),
is_red: str = Form(""),
user: dict[str, Any] = Depends(_require_user),
) -> RedirectResponse:
from app.store import is_admin # noqa: WPS433
if not is_admin(user):
raise HTTPException(status_code=403, detail="관리자만 가능합니다.")
store = _store(request)
if store is None:
raise HTTPException(status_code=503, detail="vacation_db 미설정")
try:
store.upsert_holiday(
holiday_date=holiday_date,
name=name,
kind=kind,
is_red=is_red in ("1", "true", "on", "True"),
)
except ValueError as exc:
raise HTTPException(status_code=400, detail=str(exc))
year = holiday_date[:4]
return RedirectResponse(url=f"/vacation/settings?year={year}", status_code=303)
@router.post("/settings/holidays/{holiday_id:int}/delete")
def holiday_delete(
request: Request,
holiday_id: int,
year: str = Form(""),
user: dict[str, Any] = Depends(_require_user),
) -> RedirectResponse:
from app.store import is_admin # noqa: WPS433
if not is_admin(user):
raise HTTPException(status_code=403, detail="관리자만 가능합니다.")
store = _store(request)
if store is None:
raise HTTPException(status_code=503, detail="vacation_db 미설정")
try:
store.delete_holiday(holiday_id=holiday_id)
except KeyError:
raise HTTPException(status_code=404, detail="공휴일을 찾을 수 없습니다.")
suffix = f"?year={year}" if year else ""
return RedirectResponse(url=f"/vacation/settings{suffix}", status_code=303)
@router.get("/settings")
def settings_page(request: Request) -> RedirectResponse:
"""예전 설정 화면(공휴일·잔여 연차) — 2026-10-27 없앴다(공휴일 = 국경일 표, 잔여 연차 = 옵션). 예전 주소는 옵션으로."""
return RedirectResponse(url="/vacation/options", status_code=303)
@router.post("/options/balances")
async def balances_save(request: Request) -> RedirectResponse:
"""잔여 연차 한꺼번에(옵션, ERP 관리자) — 참여자 줄마다 email·total·memo. 연차 칸을 비운 줄은 그대로 둔다(새로 만들지 않음)."""
"""잔여 연차 한꺼번에(옵션 — ERP 관리자·휴가 승인자·승인 통보자) — 참여자 줄마다 email·total·memo. 연차 칸을 비운 줄은 그대로 둔다(새로 만들지 않음)."""
from urllib.parse import urlencode # noqa: WPS433
from app.store import is_admin # noqa: WPS433
user = _require_user(request)
if not is_admin(user):
raise HTTPException(status_code=403, detail="잔여 연차는 ERP 관리자만 등록할 수 있습니다.")
if not _can_edit_options(request, user):
raise HTTPException(status_code=403, detail="잔여 연차는 ERP 관리자·휴가 승인자·승인 통보자만 등록할 수 있습니다.")
store = _store(request)
if store is None:
raise HTTPException(status_code=503, detail="vacation_db 미설정")
@@ -705,7 +638,7 @@ def health() -> dict[str, str]:
# ────────────────────────────────────────────────────────────
# 휴가 옵션(2026-10-27) — 승인자·승인 통보자(수정 = ERP 관리자), 내 Gmail 연결(누구나 — 내가 보내는 휴가 메일)
# 휴가 옵션(2026-10-27) — 승인자·승인 통보자·잔여 연차(수정 = ERP 관리자·승인자·통보자), 내 Gmail 연결(누구나 — 내가 보내는 휴가 메일)
# ────────────────────────────────────────────────────────────
def _gmail_state(request: Request, user: dict[str, Any]) -> dict[str, Any]:
from app import mail as smtp # noqa: WPS433
@@ -735,6 +668,7 @@ def options_page(request: Request) -> HTMLResponse:
store, user = guard
opts = _options(request)
users = _vacation_users()
can_edit = _can_edit_options(request, user, opts, users)
today = today_kst()
try:
bal_year = int(request.query_params.get("year") or today.year)
@@ -757,7 +691,8 @@ def options_page(request: Request) -> HTMLResponse:
"gmail": _gmail_state(request, user),
"msg": request.query_params.get("msg", ""),
"bal_year": bal_year,
"bal_rows": _balance_rows(store, bal_year) if is_admin(user) else [],
"can_edit": can_edit,
"bal_rows": _balance_rows(store, bal_year) if can_edit else [],
},
)
@@ -771,10 +706,8 @@ def options_save(
) -> RedirectResponse:
from urllib.parse import urlencode # noqa: WPS433
from app.store import is_admin # noqa: WPS433
if not is_admin(user):
raise HTTPException(status_code=403, detail="휴가 옵션은 ERP 관리자만 바꿀 수 있습니다.")
if not _can_edit_options(request, user):
raise HTTPException(status_code=403, detail="휴가 옵션은 ERP 관리자·휴가 승인자·승인 통보자만 바꿀 수 있습니다.")
store = _store(request)
if store is None:
raise HTTPException(status_code=503, detail="vacation_db 미설정")