feat(안내문 발송): DM 수동 보내기 — 이름 지우기·본문 편집·저장한 본문 목록

- 이름 목록: × 한 명씩 빼기·[전체 삭제], 이름 넣기는 목록에 더함
- 본문: 바로 고침(plaintext-only), {이름} 자리 = 분홍 칩, 이름 누르면 고친 글 + 이름 복사
- 저장한 본문(본문 오른쪽): 설정 DM 문구 + 저장한 것, 고르기·[저장]·[새 본문으로 저장]·× 지우기
- outreach_db 마이그레이션 002 outreach_dm_bodies + POST/PUT/DELETE /outreach/api/dm-bodies
  (002 미적용이면 목록 안내만, API 503)
- 캐시 버전 20261030c, 단위·API·실제 PG·브라우저 테스트

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-30 16:51:10 +09:00
parent 456dfe376f
commit 48cd7f0878
16 changed files with 454 additions and 63 deletions
+49 -1
View File
@@ -235,6 +235,17 @@ class Store:
self.t = t; self.saved = by; return self.get_template()
def list_images(self, with_data=False): return []
def list_logs(self, limit=200): return []
dm_bodies = []
def list_dm_bodies(self): return [dict(b) for b in reversed(self.dm_bodies)]
def save_dm_body(self, body, by, body_id=None):
title, text = ostore.dm_saved_body(body)
if body_id is None:
self.seq += 1; self.dm_bodies.append({"id": self.seq, "title": title, "body": text, "created_by": by, "updated_by": by, "updated_at": ""})
return self.seq
b = next((x for x in self.dm_bodies if x["id"] == body_id), None)
if b is None: raise KeyError(body_id)
b.update(title=title, body=text, updated_by=by); return body_id
def delete_dm_body(self, body_id): self.dm_bodies = [b for b in self.dm_bodies if b["id"] != body_id]
def list_recipients(self): return [dict(r) for r in self.rows]
def get_recipient(self, rid): return next((dict(r) for r in self.rows if r["id"] == rid), None)
def add_recipients(self, rows, by):
@@ -360,7 +371,17 @@ def body(c):
# DM 수동 보내기 탭(2026-10-30) — {이름} 을 그대로 둔 DM 문구(별표 뺌)를 화면 데이터로
d = c.get("/outreach/dm").text
dm_data = __import__("json").loads(d.split('id="otr-data">')[1].split("</script>")[0])
assert 'id="otr-dm-names"' in d and "DM 수동 보내기" in d and dm_data == {"dm_template": "{이름}님, DM 문구입니다"}, dm_data
assert 'id="otr-dm-names"' in d and "DM 수동 보내기" in d and dm_data == {"dm_template": "{이름}님, DM 문구입니다",
"dm_bodies": [], "dm_max": 1000}, dm_data
# 저장한 본문 — 새로 저장(제목 = 첫 줄)·고치기·없는 것 404·빈 글/너무 김 400·지우기
r = c.post("/outreach/api/dm-bodies", json={"body": "\\n 첫 줄 제목\\n{이름}님 안녕하세요"})
assert r.status_code == 200 and r.json()["items"][0]["title"] == "첫 줄 제목", r.text
bid = r.json()["id"]
assert c.put(f"/outreach/api/dm-bodies/{bid}", json={"body": "바꾼 제목\\n본문"}).json()["items"][0]["body"] == "바꾼 제목\\n본문"
assert c.put("/outreach/api/dm-bodies/99999", json={"body": "x"}).status_code == 404
assert c.post("/outreach/api/dm-bodies", json={"body": " "}).status_code == 400
assert c.post("/outreach/api/dm-bodies", json={"body": "가" * 1001}).status_code == 400
assert c.delete(f"/outreach/api/dm-bodies/{bid}").json()["items"] == []
# 서식 편집기 본문(fmt=html) — 서버가 정리해 저장, 메일 미리보기에 서식·이름
r = c.post("/outreach/settings", data={"subject": "{이름}님 제안", "fmt": "html", "dm_body": "",
"body": '<p>안녕&nbsp;<span style="color: rgb(230, 0, 0)" onclick="x">{이름}</span>님</p><script>x</script>'})
@@ -431,6 +452,17 @@ run(body)
self.assertIn("OK", res.stdout)
class DmSavedBodyTests(unittest.TestCase):
def test_title_is_first_line_and_limits(self):
from app.modules.outreach import store as ostore
self.assertEqual(ostore.dm_saved_body("\r\n\n 안녕 {이름}님 \r\n둘째"), ("안녕 {이름}님", "안녕 {이름}님 \n둘째"))
self.assertEqual(ostore.dm_saved_body("가" * 50)[0], "가" * 40 + "…")
for bad in ("", " \n ", "가" * (ostore.DM_MAX + 1)):
with self.assertRaises(ValueError):
ostore.dm_saved_body(bad)
@unittest.skipUnless(DB_ENABLED, "OUTREACH_TEST_DB_URL(localhost) 미설정")
class OutreachDBTests(unittest.TestCase):
@classmethod
@@ -443,6 +475,22 @@ class OutreachDBTests(unittest.TestCase):
def tearDownClass(cls):
cls.st.close()
def test_dm_bodies(self):
st = self.st
tag = uuid.uuid4().hex[:6]
a = st.save_dm_body(f"제목{tag}\n{{이름}}님", by="Me@X.com")
b = st.save_dm_body(f"둘째{tag}", by="me@x.com")
items = [x for x in st.list_dm_bodies() if tag in x["title"]]
self.assertEqual([x["id"] for x in items], [b, a]) # 새로 고친 것부터
self.assertEqual((items[1]["body"], items[1]["created_by"]), (f"제목{tag}\n{{이름}}님", "me@x.com"))
st.save_dm_body(f"고침{tag}", by="me@x.com", body_id=a)
self.assertEqual([x["title"] for x in st.list_dm_bodies() if tag in x["title"]][0], f"고침{tag}")
with self.assertRaises(KeyError):
st.save_dm_body("x", by="me@x.com", body_id=-1)
st.delete_dm_body(a)
st.delete_dm_body(b)
self.assertFalse([x for x in st.list_dm_bodies() if tag in x["title"]])
def test_recipients_claim_finish_logs(self):
import threading