c7cc94a09c
- F01 쿠팡: HTTP 200 비JSON·data 목록 없음은 수집 실패(기간 교체 안 함), 정상 빈 목록과 구분 - F02 회의록 [적용]: 업무 INSERT 와 줄 연결을 한 연결·한 트랜잭션(_insert_task), 확인은 잠그기 전·알림/메일은 커밋 뒤, 줄 바뀜 409 - F03 업무 등록 표: persist 실패 전파, 미저장이면 [적용] 중단, 초안 유지·다시 저장·이탈 경고 - F04 인증정보 변경 시 내부 토큰 삭제 + 네이버·토스 토큰을 발급 인증정보 지문(SHA-256)에 묶음, GS샵 방식 캐시도 키 지문 기준 - F05 쪽 수 상한·커서 반복 = 실패(쿠팡은 구간을 하루까지 나눠 재시도), 네이버·카카오·토스·GS샵 동일 기준 - F06 [중지] 확인과 저장 시작을 같은 잠금(begin_saving), 저장 시작 뒤 중지 불가 - F07/F08 긴급 공지: 내용 version·고친 공지 다시 그리기·확인에 version(409), 확인은 행 잠금 트랜잭션에서 수신자·표시 시각·취소 검증 - F09 쇼핑몰 연결 테스트도 clear 처리·저장 안 한 시험은 상태 유지(광고 테스트와 같은 계약) - F10 DB 테스트 skip·가짜 app.main/time.sleep 파일 범위 fixture, 오래된 기대값 갱신, pytest.ini·requirements-dev·tests/js/package.json·docs/TESTING.md - 결과·후속 과제: docs/CODE_REVIEW_2026-10-15_RESULT.md (마이그레이션·환경변수 변경 없음) Python 440 passed/63 skipped(DB 없음), 503 passed(로컬 PostgreSQL), jsdom 7종·Edge 6종 통과 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
137 lines
7.3 KiB
JavaScript
137 lines
7.3 KiB
JavaScript
// 긴급 공지 — ERP 모든 화면(erp_base.html) 가운데에 띄운다(2026-10-12).
|
|
// · GET /notice/api/pending — 띄울 시각이 지났고 아직 [확인] 안 한 내 공지(오래된 것부터). 30초마다·창을 다시 볼 때.
|
|
// · [확인]을 누를 때까지 닫히지 않는다(Esc·바깥 클릭으로 안 닫힘). 여러 건이면 차례대로(1/3).
|
|
// · [확인] = POST /notice/api/{id}/ack — 실패하면 창을 그대로 두고 알린다. 다른 탭에서 확인하면 이 탭도 다음 확인 때 닫힌다.
|
|
// · 공지마다 내용 버전(version = 고친 시각) — 띄운 공지가 고쳐지면 다음 확인 때 바뀐 내용으로 다시 그리고 "수정됨"을 알린다.
|
|
// [확인]은 읽은 버전을 함께 보내, 그 사이 고쳐졌으면(409) 기록하지 않고 바뀐 내용을 다시 보여 준다(2026-10-15 검토 F07).
|
|
// · 본문 HTML 은 서버가 정리한 것(이미지는 /notice/images/{id} 만). 수신함 오른쪽 작업 창(iframe) 안에서는 돌지 않는다.
|
|
// · 024 미적용(503)·로그아웃(401)이면 조용히 멈춘다.
|
|
(function () {
|
|
"use strict";
|
|
if (window.top !== window) return; // iframe(수신함 작업 창 등) 안에서는 바깥 화면이 띄운다
|
|
const POLL_MS = 30000;
|
|
let queue = [], shown = null, box = null, timer = 0, busy = false, stopped = false;
|
|
|
|
function esc(s) {
|
|
return String(s == null ? "" : s).replace(/[&<>"']/g, function (c) {
|
|
return { "&": "&", "<": "<", ">": ">", '"': """, "'": "'" }[c];
|
|
});
|
|
}
|
|
function when(iso) {
|
|
const m = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2})/.exec(iso || "");
|
|
return m ? m[2] + "/" + m[3] + " " + m[4] + ":" + m[5] : "";
|
|
}
|
|
function who(email) {
|
|
const id = String(email || "").split("@")[0];
|
|
return id ? id.charAt(0).toUpperCase() + id.slice(1) : "";
|
|
}
|
|
function schedule() { clearTimeout(timer); if (!stopped) timer = setTimeout(poll, POLL_MS); }
|
|
|
|
async function poll() {
|
|
if (busy || stopped) return;
|
|
if (document.hidden) { schedule(); return; }
|
|
busy = true;
|
|
try {
|
|
const res = await fetch("/notice/api/pending", { headers: { Accept: "application/json" }, credentials: "same-origin" });
|
|
if (res.status === 401 || res.status === 403 || res.status === 503 || res.status === 404) { stopped = true; return; }
|
|
if (!res.ok) return;
|
|
const data = await res.json();
|
|
queue = Array.isArray(data.notices) ? data.notices : [];
|
|
// 다른 탭·다른 곳에서 확인했거나 취소된 공지는 닫는다. 같은 공지라도 내용이 고쳐졌으면(버전이 다르면) 다시 그린다
|
|
const cur = shown ? queue.find(function (n) { return n.id === shown.id; }) : null;
|
|
if (shown && !cur) close();
|
|
if (cur && (cur.version || "") !== (shown.version || "")) open(cur, true);
|
|
else if (!shown && queue.length) open(queue[0]);
|
|
else if (shown) paintCount();
|
|
} catch (_) {
|
|
// 네트워크 오류는 다음 주기에 다시
|
|
} finally {
|
|
busy = false;
|
|
schedule();
|
|
}
|
|
}
|
|
|
|
function paintCount() {
|
|
if (!box || !shown) return;
|
|
const i = queue.findIndex(function (n) { return n.id === shown.id; });
|
|
const c = box.querySelector(".erp-notice-count");
|
|
c.textContent = queue.length > 1 ? (i + 1) + " / " + queue.length : "";
|
|
c.hidden = queue.length <= 1;
|
|
}
|
|
function open(n, updated) {
|
|
shown = n;
|
|
if (!box) {
|
|
box = document.createElement("div");
|
|
box.className = "erp-notice-backdrop";
|
|
box.innerHTML =
|
|
'<div class="erp-notice-card" role="alertdialog" aria-modal="true" aria-labelledby="erp-notice-title">' +
|
|
'<div class="erp-notice-head"><span class="erp-notice-badge">긴급 공지</span><span class="erp-notice-count" hidden></span></div>' +
|
|
'<h2 class="erp-notice-title" id="erp-notice-title"></h2>' +
|
|
'<p class="erp-notice-updated" role="status" hidden>공지 내용이 수정되었습니다. 바뀐 내용을 확인한 뒤 [확인]을 눌러 주세요.</p>' +
|
|
'<div class="erp-notice-body"></div>' +
|
|
'<p class="erp-notice-error" role="alert" hidden></p>' +
|
|
'<div class="erp-notice-foot"><span class="erp-notice-meta"></span>' +
|
|
'<button type="button" class="erp-notice-ok">확인</button></div></div>';
|
|
document.body.appendChild(box); // 화면 배율(.erp-app zoom) 밖 — 늘 화면 정가운데
|
|
box.querySelector(".erp-notice-ok").addEventListener("click", ack);
|
|
// [확인] 전에는 닫지 않는다 — Esc 는 막고, 포커스는 창 안에
|
|
box.addEventListener("keydown", function (e) {
|
|
if (e.key === "Escape") { e.preventDefault(); e.stopPropagation(); }
|
|
if (e.key === "Tab") { e.preventDefault(); box.querySelector(".erp-notice-ok").focus(); }
|
|
});
|
|
}
|
|
box.querySelector(".erp-notice-title").textContent = n.title || "";
|
|
box.querySelector(".erp-notice-body").innerHTML = n.body_html || ""; // 서버가 정리한 HTML
|
|
box.querySelector(".erp-notice-meta").textContent =
|
|
[who(n.created_by), when(n.show_at)].filter(Boolean).join(" · ");
|
|
box.querySelector(".erp-notice-error").hidden = true;
|
|
box.querySelector(".erp-notice-updated").hidden = !updated;
|
|
box.querySelector(".erp-notice-body").scrollTop = 0;
|
|
box.hidden = false;
|
|
paintCount();
|
|
const ok = box.querySelector(".erp-notice-ok");
|
|
ok.disabled = false;
|
|
ok.focus();
|
|
}
|
|
function close() {
|
|
shown = null;
|
|
if (box) box.hidden = true;
|
|
}
|
|
async function ack() {
|
|
if (!shown) return;
|
|
const n = shown, ok = box.querySelector(".erp-notice-ok"), err = box.querySelector(".erp-notice-error");
|
|
ok.disabled = true;
|
|
err.hidden = true;
|
|
try {
|
|
const res = await fetch("/notice/api/" + n.id + "/ack", {
|
|
method: "POST", credentials: "same-origin",
|
|
headers: { "Content-Type": "application/json" }, body: JSON.stringify({ version: n.version || "" }),
|
|
});
|
|
if (res.status === 409) {
|
|
// 읽는 사이 공지가 고쳐졌다 — 기록하지 않았다. 바뀐 내용을 받아 다시 그린다(창은 그대로)
|
|
ok.disabled = false;
|
|
await poll();
|
|
if (shown && shown.id === n.id && (shown.version || "") === (n.version || "")) {
|
|
box.querySelector(".erp-notice-updated").hidden = false; // 다시 받지 못했어도 알린다
|
|
}
|
|
return;
|
|
}
|
|
if (!res.ok && res.status !== 404) throw new Error("HTTP " + res.status); // 404 = 취소·삭제·예약 — 닫는다
|
|
try { localStorage.setItem("erp_notice_ack", String(n.id) + ":" + Date.now()); } catch (_) {}
|
|
queue = queue.filter(function (x) { return x.id !== n.id; });
|
|
if (queue.length) open(queue[0]); else close();
|
|
} catch (e) {
|
|
err.textContent = "확인을 저장하지 못했습니다. 다시 눌러 주세요. (" + e.message + ")";
|
|
err.hidden = false;
|
|
ok.disabled = false;
|
|
ok.focus();
|
|
}
|
|
}
|
|
|
|
window.addEventListener("storage", function (e) { if (e.key === "erp_notice_ack") poll(); });
|
|
document.addEventListener("visibilitychange", function () { if (!document.hidden) poll(); });
|
|
if (window.__ERP_NOTICE_TEST__) window.__erpNotice = { poll: poll, state: function () { return { queue: queue, shown: shown, stopped: stopped }; } };
|
|
if (document.readyState === "loading") document.addEventListener("DOMContentLoaded", poll);
|
|
else poll();
|
|
})();
|