feat(outreach): 설정 화면 세로 2단(메일 | DM) + 메일 본문 서식 편집기, {이름} 빨강 굵게
- 설정 = 왼쪽 메일(제목·(광고)·보내는 이름·본문 편집기·끝 문구·사진), 오른쪽 인스타 DM, 위 저장 막대
- 메일 본문 = Quill 2.0.3 편집기(글자 크기·굵게·기울임·밑줄·취소선·색·배경·정렬·목록·링크·서식 지우기·되돌리기),
vendor/quill 에 자체 호스팅
- 본문 HTML 저장(fmt=html) — 서버 sanitize_html 로 허용 태그·스타일만, 예전 글은 text_to_html 로 자동 변환
- {이름} 은 두 편집기에서 빨강 굵게(화면에서만, 메일에는 남지 않음), 글자마다 서식이 달라도 이름으로 바꿈
- DM 편집기: 서식 없음, 글자 수, [메일 본문 글 가져오기]
- 테스트: 정리기·예전 글 변환·웹 흐름, 설정 화면 브라우저 테스트 추가
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+50
-5
@@ -64,11 +64,46 @@ class RenderTests(unittest.TestCase):
|
||||
h = store.html_body(self.T, "<script>x</script>", ["c1@dbx", "c2@dbx"])
|
||||
self.assertIn("<script>x</script>님", h)
|
||||
self.assertNotIn("<script>", h)
|
||||
self.assertIn("<b>미라네주방</b>", h)
|
||||
self.assertIn("<strong>미라네주방</strong>", h)
|
||||
self.assertIn('<a href="https://miras.co.kr/"', h)
|
||||
self.assertEqual(h.count('src="cid:'), 2)
|
||||
self.assertEqual(store.dm_link("mira.kitchen"), "https://ig.me/m/mira.kitchen")
|
||||
|
||||
def test_legacy_text_body_becomes_html(self):
|
||||
# 예전 저장 글·기본 문구(fmt 없음) = 줄마다 문단, 빈 줄 유지, **굵게**·주소 변환 — 글로 되돌리면 별표만 빠진 원래 글
|
||||
self.assertEqual(self.T["fmt"], "html")
|
||||
self.assertEqual(self.T["body"], '<p>안녕하세요, {이름}님.</p><p><strong>미라네주방</strong>입니다.</p>'
|
||||
'<p><a href="https://miras.co.kr/">https://miras.co.kr/</a></p>')
|
||||
d = store.normalize_template(None)
|
||||
self.assertEqual(store.html_to_text(d["body"]), store.DEFAULT_TEMPLATE["body"].replace("**", "").rstrip())
|
||||
self.assertEqual(store.normalize_template({"body": d["body"], "fmt": "html"})["body"], d["body"]) # 다시 정리해도 같음
|
||||
|
||||
def test_editor_html_sanitized(self):
|
||||
# 설정 편집기(Quill getSemanticHTML) HTML — 서식은 남기고 위험한 것은 뺀다, → 띄어쓰기, 빈 문단 = <br>
|
||||
raw = ('<p>안녕하세요, <span class="otr-nametag-on">{이름}</span>님.</p><p></p>'
|
||||
'<p style="text-align: center;"><span style="color: rgb(230, 0, 0); font-size: 20px; position: fixed;">빨강</span>'
|
||||
'<script>alert(1)</script><img src=x onerror="alert(1)"><iframe src="//x"></iframe></p>'
|
||||
'<ul><li><strong>하나</strong></li><li><em><u><s>둘</s></u></em></li></ul>'
|
||||
'<p><a href="javascript:alert(1)" onclick="x">나쁜</a> <a href="https://a.com/?x=1&y=2" target="_blank">좋은</a>'
|
||||
'<span style="background-color: url(x)">배경</span>{<strong>이</strong>름}<div>안</div></p>')
|
||||
t = store.normalize_template({"body": raw, "fmt": "html"})
|
||||
self.assertEqual(t["body"],
|
||||
'<p>안녕하세요, <span>{이름}</span>님.</p><p><br></p>'
|
||||
'<p style="text-align: center"><span style="color: rgb(230, 0, 0); font-size: 20px">빨강</span></p>'
|
||||
'<ul><li><strong>하나</strong></li><li><em><u><s>둘</s></u></em></li></ul>'
|
||||
'<p><a>나쁜</a> <a href="https://a.com/?x=1&y=2">좋은</a><span>배경</span>{<strong>이</strong>름}안</p>')
|
||||
self.assertEqual(store.html_to_text(t["body"]), "안녕하세요, {이름}님.\n\n빨강\n- 하나\n- 둘\n나쁜 좋은배경{이름}안")
|
||||
self.assertTrue(store.needs_name(t))
|
||||
h = store.html_body(t, "<김>")
|
||||
self.assertIn("안녕하세요, <span><김></span>님.", h)
|
||||
self.assertIn("배경</span><김><strong></strong>안", h) # 글자마다 서식이 달라도 {이름} 을 바꾼다
|
||||
self.assertIn('<p style="margin:0;text-align: center">', h) # 메일 프로그램 문단 여백 0
|
||||
for bad in ("<script", "onerror", "javascript:", "<iframe", "position", "url(", "<img src=x", "class="):
|
||||
self.assertNotIn(bad, h)
|
||||
# 서식 포함 너무 긴 본문 = 저장 안 됨(정리 후 길이)
|
||||
self.assertGreater(len(store.normalize_template({"body": "<p>" + "가" * (store.BODY_MAX + 10) + "</p>", "fmt": "html"})["body"]),
|
||||
store.BODY_MAX)
|
||||
|
||||
def test_dm_body(self):
|
||||
# DM 문구가 비면 메일 글(본문 + 끝 문구), 있으면 그것만 — 별표만 빼고 {이름}, 끝 문구·제목 없이
|
||||
self.assertEqual(store.dm_text(self.T, "김철수"), store.plain_text(self.T, "김철수"))
|
||||
@@ -196,7 +231,7 @@ class Store:
|
||||
return {**self.t, "updated_by": "", "updated_at": "", "is_default": self.saved is None}
|
||||
def save_template(self, value, by): # db.save_template 과 같은 검사
|
||||
t = ostore.normalize_template(value)
|
||||
if not t["subject"] or not t["body"].strip(): raise ValueError("메일 제목·본문을 쓰세요.")
|
||||
if not t["subject"] or not ostore.html_to_text(t["body"]).strip(): raise ValueError("메일 제목·본문을 쓰세요.")
|
||||
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 []
|
||||
@@ -288,7 +323,9 @@ def body(c):
|
||||
assert "안내문 발송" in t and "누적매출 300억" in t and "Gmail 연결" in t and "고른 메일 보내기" in t
|
||||
# 설정 — 기본 문구, 저장, (광고)
|
||||
s = c.get("/outreach/settings").text
|
||||
assert "기본 문구(아직 저장 안 함)" in s and "주방의 본질을 지키며" in s and "정보통신망법" in s
|
||||
cur = lambda s: __import__("json").loads(s.split('id="otr-current-data">')[1].split("</script>")[0]) # noqa: E731
|
||||
assert "기본 문구(아직 저장 안 함)" in s and "정보통신망법" in s and 'id="otr-body-editor"' in s and "/static/vendor/quill/quill.js" in s
|
||||
assert cur(s)["body"].startswith("<p>안녕하세요, {이름}님.</p><p>주방의 본질을 지키며"), cur(s)
|
||||
r = c.post("/outreach/settings", data={"subject": "{이름}님 제안", "body": "안녕하세요 {이름}님", "sender_name": "미라네주방",
|
||||
"footer": "수신 거부: 회신", "ad_label": "1"})
|
||||
assert r.status_code == 303 and st.saved == "me@miras.co.kr" and st.t["ad_label"] is True
|
||||
@@ -311,7 +348,7 @@ def body(c):
|
||||
# 이름 고치기
|
||||
assert c.put(f"/outreach/api/recipients/{nobody['id']}", json={"name": "노바디"}).json()["row"]["needs_name"] is False
|
||||
# 인스타 DM 문구 — 저장하면 DM 줄 글·미리보기가 그 문구로(메일은 그대로)
|
||||
assert "인스타 DM 문구" in s and 'name="dm_body"' in s
|
||||
assert "인스타 DM 문구" in s and 'name="dm_body"' in s and 'id="otr-dm-editor"' in s
|
||||
r = c.post("/outreach/settings", data={"subject": "{이름}님 제안", "body": "안녕하세요 {이름}님", "footer": "수신 거부: 회신",
|
||||
"dm_body": "{이름}님, **DM** 문구입니다"})
|
||||
assert r.status_code == 303 and st.t["dm_body"] == "{이름}님, **DM** 문구입니다"
|
||||
@@ -319,7 +356,15 @@ def body(c):
|
||||
assert mira2["dm_text"] == "미라님, DM 문구입니다", mira2
|
||||
assert c.get(f"/outreach/api/recipients/{mira['id']}/preview").json()["text"] == "미라님, DM 문구입니다"
|
||||
assert "수신 거부: 회신" in c.get(f"/outreach/api/recipients/{kim['id']}/preview").json()["text"]
|
||||
assert "**DM** 문구입니다" in c.get("/outreach/settings").text
|
||||
assert cur(c.get("/outreach/settings").text)["dm_body"] == "{이름}님, **DM** 문구입니다"
|
||||
# 서식 편집기 본문(fmt=html) — 서버가 정리해 저장, 메일 미리보기에 서식·이름
|
||||
r = c.post("/outreach/settings", data={"subject": "{이름}님 제안", "fmt": "html", "dm_body": "",
|
||||
"body": '<p>안녕 <span style="color: rgb(230, 0, 0)" onclick="x">{이름}</span>님</p><script>x</script>'})
|
||||
assert r.status_code == 303 and st.t["body"] == '<p>안녕 <span style="color: rgb(230, 0, 0)">{이름}</span>님</p>', st.t["body"]
|
||||
pv = c.get(f"/outreach/api/recipients/{kim['id']}/preview").json()
|
||||
assert '<span style="color: rgb(230, 0, 0)">김철수</span>님' in pv["html"] and pv["text"].startswith("안녕 김철수님"), pv
|
||||
assert c.get("/outreach/").text.count("안녕 {이름}님") == 1 # 리스트 화면 '보낼 내용' = 글로
|
||||
assert c.post("/outreach/settings", data={"subject": "x", "fmt": "html", "body": "<p></p><p><br></p>"}).status_code == 400
|
||||
# 메일 보내기 — Gmail 없음 = 409(재연결 안내)
|
||||
r = c.post("/outreach/api/send", json={"ids": [kim["id"]]})
|
||||
assert r.status_code == 409 and r.json()["reconnect"] is True
|
||||
|
||||
Reference in New Issue
Block a user