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:
@@ -577,6 +577,7 @@ async def gmail_connect(request: Request, next: str = "/inout/") -> Any: # noqa
|
||||
except gmail.GmailError as exc:
|
||||
return _redirect(_safe_next(next), str(exc))
|
||||
request.session["_inout_gmail_next"] = _safe_next(next)
|
||||
request.session.pop("_gmail_origin", None) # 휴가 옵션에서 시작한 연결 표시가 남아 있으면 지움
|
||||
return await client.authorize_redirect(
|
||||
request, public_url_for(request, "inout_gmail_callback"),
|
||||
access_type="offline", prompt="consent", include_granted_scopes="true",
|
||||
@@ -585,6 +586,8 @@ async def gmail_connect(request: Request, next: str = "/inout/") -> Any: # noqa
|
||||
|
||||
@router.get("/gmail/callback", name="inout_gmail_callback")
|
||||
async def gmail_callback(request: Request) -> Any:
|
||||
if request.session.get("_gmail_origin") == "vacation":
|
||||
return await _gmail_callback_vacation(request)
|
||||
got = _ctx(request)
|
||||
if not isinstance(got, tuple):
|
||||
return got
|
||||
@@ -608,6 +611,43 @@ async def gmail_callback(request: Request) -> Any:
|
||||
return _redirect(nxt, "Gmail 을 연결했습니다 — 이제 [메일 발송]으로 보낼 수 있습니다.")
|
||||
|
||||
|
||||
async def _gmail_callback_vacation(request: Request) -> Any:
|
||||
"""휴가 옵션 [Gmail 연결](2026-10-27) — 같은 구글 리디렉션 주소를 함께 쓰므로 여기로 돌아온다(구글 클라우드 설정 추가 없음).
|
||||
입출고 담당 권한 대신 휴가 모듈 권한을 보고, 토큰은 입출고와 같은 inout_gmail_tokens 에(한 사람 = 연결 하나, 두 모듈이 같이 씀)."""
|
||||
from urllib.parse import quote # noqa: WPS433
|
||||
|
||||
from authlib.integrations.starlette_client import OAuthError # noqa: WPS433
|
||||
|
||||
from app.main import get_current_user_record # noqa: WPS433
|
||||
from app.store import has_module # noqa: WPS433
|
||||
|
||||
from . import gmail # noqa: WPS433
|
||||
|
||||
request.session.pop("_gmail_origin", None)
|
||||
nxt = str(request.session.pop("_vacation_gmail_next", "") or "")
|
||||
if not nxt.startswith("/vacation/") or "//" in nxt or "\\" in nxt:
|
||||
nxt = "/vacation/options"
|
||||
user = get_current_user_record(request)
|
||||
if user is None:
|
||||
return RedirectResponse(url="/login?next=" + quote(nxt, safe=""), status_code=303)
|
||||
if not has_module(user, "vacation"):
|
||||
raise HTTPException(status_code=403, detail="휴가 관리 모듈 권한이 없습니다.")
|
||||
st = _store(request)
|
||||
if st is None:
|
||||
return _redirect(nxt, "Gmail 연결 저장소(입출고 DB)가 설정되지 않아 연결할 수 없습니다.")
|
||||
email = user.get("email", "")
|
||||
try:
|
||||
token = await gmail.oauth_client().authorize_access_token(request)
|
||||
refresh, scopes = gmail.check_grant(token, expected_email=email)
|
||||
st.save_gmail_token(email, refresh_token_enc=gmail.encrypt_token(email, refresh), scopes=scopes)
|
||||
except OAuthError as exc:
|
||||
msg = "Gmail 연결을 취소했습니다." if exc.error == "access_denied" else f"Gmail 연결 실패({exc.error})"
|
||||
return _redirect(nxt, msg)
|
||||
except (gmail.GmailError, ValueError) as exc:
|
||||
return _redirect(nxt, str(exc))
|
||||
return _redirect(nxt, "Gmail 을 연결했습니다 — 이제 휴가 메일이 내 Gmail 로 나갑니다.")
|
||||
|
||||
|
||||
@router.post("/gmail/disconnect")
|
||||
def gmail_disconnect(request: Request) -> JSONResponse:
|
||||
user = _user(request)
|
||||
|
||||
Reference in New Issue
Block a user