feat(vacation): 휴가 옵션(승인자·승인 통보자) · 제출·승인·반려 메일(처리한 사람 본인 Gmail)
- /vacation/options(달력 [옵션], 수정 = ERP 관리자): 휴가 승인자(여러 명)·휴가 승인 통보자 — vacation_options(마이그레이션 001) - 승인·반려 = 관리자 + 옵션 승인자(지정 시 그 사람만), 비우면 예전처럼 vacation_approver 권한자 - 메일(notify.py, 응답 뒤 백그라운드): 제출 = 승인자+통보자, 승인·반려 = 승인자+통보자+신청자 보내는 사람 = 그 일을 한 사람 본인 Gmail(입출고와 같은 연결·같은 구글 콜백, _gmail_callback_vacation), 없거나 실패하면 회사 SMTP(이름·Reply-To = 그 사람, app/mail.py reply_to 추가) - vacation_mail_log → 상세 화면 "메일" 줄, 휴가 화면 셸 오른쪽 넘침(border-box) 수정 - 테스트: test_vacation_options_mail.py(규칙·내용·Gmail→SMTP·실제 앱 권한·콜백), test_vacation_db.py(실제 PG) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -27,6 +27,16 @@ from app.timezone import KST
|
||||
from .store import EDITABLE_STATUSES, STATUSES, VACATION_TYPES, compute_days, normalize_half
|
||||
|
||||
|
||||
def _email_list(value: Any) -> list[str]:
|
||||
"""이메일 목록 정리 — 소문자·공백 제거·@ 있는 것만·중복 제거(순서 유지)."""
|
||||
out: list[str] = []
|
||||
for v in value or []:
|
||||
e = str(v or "").strip().lower()
|
||||
if "@" in e and e not in out:
|
||||
out.append(e)
|
||||
return out
|
||||
|
||||
|
||||
class VacationDBStore:
|
||||
def __init__(self, dsn: str, *, min_size: int = 1, max_size: int = 5):
|
||||
self._pool = ConnectionPool(
|
||||
@@ -41,6 +51,74 @@ class VacationDBStore:
|
||||
def close(self) -> None:
|
||||
self._pool.close()
|
||||
|
||||
# ════════════════════════════════════════════════════════════
|
||||
# 옵션 · 메일 기록 (마이그레이션 001, 2026-10-27) — 테이블이 없으면 옵션 없음·기록 없음
|
||||
# ════════════════════════════════════════════════════════════
|
||||
OPTION_KEY = "approval"
|
||||
|
||||
def options_ready(self) -> bool:
|
||||
with self._pool.connection() as conn:
|
||||
row = conn.execute("SELECT to_regclass('public.vacation_options') AS r").fetchone()
|
||||
return bool(row and row["r"])
|
||||
|
||||
def get_options(self) -> dict[str, Any]:
|
||||
"""{"approvers": [이메일], "notifiers": [이메일], "updated_by", "updated_at", "ready": 001 적용 여부}."""
|
||||
out: dict[str, Any] = {"approvers": [], "notifiers": [], "updated_by": "", "updated_at": "", "ready": False}
|
||||
if not self.options_ready():
|
||||
return out
|
||||
out["ready"] = True
|
||||
with self._pool.connection() as conn:
|
||||
row = conn.execute("SELECT value, updated_by, updated_at FROM vacation_options WHERE key = %s",
|
||||
(self.OPTION_KEY,)).fetchone()
|
||||
if row:
|
||||
value = row["value"] if isinstance(row["value"], dict) else {}
|
||||
out["approvers"] = _email_list(value.get("approvers"))
|
||||
out["notifiers"] = _email_list(value.get("notifiers"))
|
||||
out["updated_by"] = row["updated_by"] or ""
|
||||
if isinstance(row["updated_at"], datetime):
|
||||
out["updated_at"] = row["updated_at"].astimezone(KST).isoformat(timespec="seconds")
|
||||
return out
|
||||
|
||||
def save_options(self, *, approvers: list[str], notifiers: list[str], by: str) -> dict[str, Any]:
|
||||
if not self.options_ready():
|
||||
raise RuntimeError("휴가 옵션은 vacation_db_001 마이그레이션 뒤에 저장할 수 있습니다.")
|
||||
from psycopg.types.json import Jsonb # noqa: WPS433
|
||||
|
||||
value = {"approvers": _email_list(approvers), "notifiers": _email_list(notifiers)}
|
||||
with self._pool.connection() as conn:
|
||||
conn.execute(
|
||||
"INSERT INTO vacation_options (key, value, updated_by, updated_at) VALUES (%s, %s, %s, now()) "
|
||||
"ON CONFLICT (key) DO UPDATE SET value = EXCLUDED.value, updated_by = EXCLUDED.updated_by, updated_at = now()",
|
||||
(self.OPTION_KEY, Jsonb(value), (by or "").lower().strip()),
|
||||
)
|
||||
return self.get_options()
|
||||
|
||||
def add_mail_log(self, *, request_id: str, event: str, sender: str, via: str, recipients: list[str],
|
||||
subject: str, ok: bool, error: str = "") -> None:
|
||||
if not self.options_ready():
|
||||
return
|
||||
with self._pool.connection() as conn:
|
||||
conn.execute(
|
||||
"INSERT INTO vacation_mail_log (request_id, event, sender, via, recipients, subject, ok, error) "
|
||||
"VALUES (%s, %s, %s, %s, %s, %s, %s, %s)",
|
||||
(request_id, event, (sender or "").lower(), via, ", ".join(recipients)[:2000], (subject or "")[:300],
|
||||
bool(ok), (error or "")[:500]),
|
||||
)
|
||||
|
||||
def list_mail_log(self, *, request_id: str) -> list[dict[str, Any]]:
|
||||
if not self.options_ready():
|
||||
return []
|
||||
with self._pool.connection() as conn:
|
||||
rows = conn.execute(
|
||||
"SELECT * FROM vacation_mail_log WHERE request_id = %s ORDER BY sent_at, id", (request_id,)).fetchall()
|
||||
out = []
|
||||
for r in rows:
|
||||
d = dict(r)
|
||||
if isinstance(d.get("sent_at"), datetime):
|
||||
d["sent_at"] = d["sent_at"].astimezone(KST).isoformat(timespec="seconds")
|
||||
out.append(d)
|
||||
return out
|
||||
|
||||
# ════════════════════════════════════════════════════════════
|
||||
# 공휴일 (vacation_holidays) — holiday provider
|
||||
# ════════════════════════════════════════════════════════════
|
||||
|
||||
Reference in New Issue
Block a user