refactor: config_views 单入口 + 0语义统一 + FakeAI 收敛(清理单#1#2#3)
- #3 六个消费视图 resolver 收拢 app/platform/config_views(单一定义点): resolve_email/push/ai_settings ← 各服务文件, resolve_contact_flags/ context_seed_map ← conversation, name_to_region_extras ← manager __init__ 内联取值(or None 语义原样)——函数体逐字搬入,服务层 import 之, 旧定义删;Phase 3 编辑器/试金石与该模块对接 - #2 限流 0 语义统一: conn_limiter.try_acquire 的 limit 与 chat_rest 的 rate_limit_per_hour 取值同款——0 或负 = 回退出厂默认(与姊妹键一致), 原 conn_limiter 0=全拒改为回退;chat_rest 取值抽 _resolve_rate_limit 纯函数供锚定 - #1 FakeAI 收敛进 conftest(超集: extract/evaluate/eval_calls),四份拷贝 删(test_lead_email_trigger/test_cc_integration/test_channel_hygiene/ test_lead_push_wiring——计划记三份,grep 实有四份;push_wiring 经 evaluate 参数注入原本地固定返回值,断言零改动) 全量 558 passed(554 + 新增 4: 单入口/内联等价/两处 0 语义) Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
@@ -5,8 +5,9 @@ from email.mime.text import MIMEText
|
||||
|
||||
import aiosmtplib
|
||||
|
||||
from app.engine.config import settings
|
||||
from app.engine.services.cc_completion import cc_state_for, outbound_e164, outbound_number
|
||||
# Task 10: 发信参数 resolver 收拢至 config_views(单一定义点)
|
||||
from app.platform.config_views import resolve_email_settings
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -16,33 +17,6 @@ TAG_LABELS = {
|
||||
}
|
||||
CONTACT_LABELS = {"phone": "手机", "whatsapp": "WhatsApp", "email": "邮箱", "wechat": "微信"}
|
||||
|
||||
# 平台默认发件人显示名(Task 9 前的硬编码值, 租户未配 sender_name 时沿用)
|
||||
_DEFAULT_SENDER_NAME = "HESUPIPE"
|
||||
|
||||
|
||||
def resolve_email_settings(config_data: dict | None) -> dict:
|
||||
"""租户 config.email → 发信参数(Task 9 接线; env settings 回退)。
|
||||
|
||||
回退规则(语义钉在 test_config_merge: 显式 None = 清空/未设置):
|
||||
- smtp 缺省或显式 None → 整段用 env SMTP_*;
|
||||
- smtp 给了 dict → 段内逐键回退(缺键/空串 → env 对应值, 租户可只改
|
||||
密码/只换 host);
|
||||
- sender_name 空 → 平台默认(_DEFAULT_SENDER_NAME);
|
||||
- notify_emails 空列表 → env NOTIFY_EMAIL 单元素。
|
||||
"""
|
||||
email = ((config_data or {}).get("email")) or {}
|
||||
smtp = email.get("smtp") or {}
|
||||
notify = [e for e in (email.get("notify_emails") or []) if e]
|
||||
return {
|
||||
"host": smtp.get("host") or settings.SMTP_HOST,
|
||||
"port": smtp.get("port") or settings.SMTP_PORT,
|
||||
"user": smtp.get("user") or settings.SMTP_USER,
|
||||
"password": smtp.get("password") or settings.SMTP_PASS,
|
||||
"sender_name": email.get("sender_name") or _DEFAULT_SENDER_NAME,
|
||||
"notify_emails": notify or (
|
||||
[settings.NOTIFY_EMAIL] if settings.NOTIFY_EMAIL else []),
|
||||
}
|
||||
|
||||
|
||||
def _esc(v) -> str:
|
||||
return html.escape(str(v)) if v else ""
|
||||
|
||||
Reference in New Issue
Block a user