Skip to content

[缺陷] cla的协议变更后,自动给开发者发送邮件通知的行为,需要加审计日志-的开发实现-app-cla-server部分#504

Open
fly333sky wants to merge 1 commit into
reviewfrom
issue-1483-from-review
Open

[缺陷] cla的协议变更后,自动给开发者发送邮件通知的行为,需要加审计日志-的开发实现-app-cla-server部分#504
fly333sky wants to merge 1 commit into
reviewfrom
issue-1483-from-review

Conversation

@fly333sky

Copy link
Copy Markdown

背景

[缺陷] cla的协议变更后,自动给开发者发送邮件通知的行为,需要加审计日志(app-cla-server)· 开发流水线 · 开发预览阶段(代码已推 + 预览已部署 + UT 已补;门禁/对抗由 PR CI 异步跑)

改动内容

feat(app-cla-server): 为 CLA 协议变更邮件通知补充审计日志

改动概述

修复 backlog#1483:CLA 协议变更后自动给开发者/管理员发送邮件通知的行为此前无任何日志记录。
在 app-cla-server 的「watch 通知 → worker 发信」链路上补齐结构化审计日志,记录 4W(收件人/时间戳/link_id+社区/CLA 变更与邮件主题/发送结果),便于审计追溯与问题排查。不引入新依赖、不新增对外接口、不改发信数据流与重试/退避策略。

生产代码改动(子仓 app-cla-server)

  1. signing/watch/notify_corp_admin.go
    • handleSendEmail(企业 CLA → 通知 corp admin):在 SendSimpleMessage 之后新增意图审计日志 [audit] cla_notify_email: scene=corp, link_id, org, corp_signing_id, recipient, from, subject, new_cla_id, signed_cla_id, notify_count
    • handleSendIndividualEmail(个人 CLA → 通知签署者):新增意图审计日志 [audit] cla_notify_email: scene=individual, ...
  2. worker/worker.go
    • tryToSendEmail 返回值由无改为 bool(成功 true;重试 10 次耗尽或被 stop 为 false),原 10 次 ×1 分钟退避语义不变。
    • SendSimpleMessage 据返回值补结果审计日志:成功 logs.Info("[audit] email_result: outcome=sent, ..."),失败 logs.Error("[audit] email_result: outcome=failed, ..."),覆盖所有走 SendSimpleMessage 的邮件。
    • GenCLAPDFForCorporationAndSendIt 忽略新返回值,保持原行为(设计要求)。
    • 新增导出函数 SetEmailWorker(返回还原函数),用于测试注入假 worker。

单元测试(本轮新增)

  • worker/worker_test.go(新文件):
    • TestTryToSendEmailSuccess(action 成功→true、仅调用一次)
    • TestTryToSendEmailFailureReturnsFalse(action 持续失败→false,关闭 stop 避免等待 9 分钟)
    • TestSendSimpleMessageSuccess(注册假 emailservice 成功,覆盖 outcome=sent 分支)
    • TestSendSimpleMessageFailure(假 emailservice 失败 + Shutdown 关 stop,覆盖 outcome=failed 分支)
  • signing/watch/main_test.go(新文件):TestMain 切到模块根并 emailtmpl.Init(),供依赖模板渲染的用例使用。
  • signing/watch/notify_corp_admin_test.go(追加):
    • fakeEmailWorker(实现 worker.IEmailWorker,记录发信调用)
    • TestHandleSendEmailAuditLogCorp(注入假 worker,验证企业通知审计日志路径被走到、不 panic、收件人/主题正确)
    • TestHandleSendIndividualEmailAuditLogIndividual(同上,个人通知)

验证结果

  • go build ./... 通过;go vet ./worker/... ./signing/watch/... 通过。
  • go test -race ./worker/... 全绿;本次新增 watch 用例全绿(两条 [audit] cla_notify_email 日志均已实际输出)。
  • 增量函数覆盖率(改动函数):tryToSendEmail 86.7%、SendSimpleMessage 92.9%、handleSendEmail 86.7%、handleSendIndividualEmail 85.7%,均 ≥ 80%。

备注(非本次范围)

  • signing/watch/config_test.go::TestNotifyAdminConfigSetDefault 在本次改动前即已失败(git stash 验证:config 间隔默认值 86400 vs 测试期望 1200),属既有遗留、与本需求审计日志无关,按「不改无关」未处理。

相关 Issue

resolve https://github.com/opensourceways/backlog/issues/1483

AI 使用声明

当前 PR 是否有 AI 参与:

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Caution

The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased.

@opensourceways-bot

Copy link
Copy Markdown

Welcome To opensourceways Community

Hey @fly333sky , thanks for your contribution to the community.

Bot Usage Manual

I'm the Bot here serving you. You can find the instructions on how to interact with me at Here . That means you can comment below every pull request or issue to trigger Bot Commands.

Contact Guide

If you have any questions, please contact the SIG: infratructure ,
and any of the maintainers: @GeorgeCao-hw, @TangJia025, @pkking, @zhongjun2 ,
and any of the committers: @JavaPythonAIForBAT, @Zherphy, @tfhddd, @zhongjun2 .

@opensourceways-bot

Copy link
Copy Markdown

CLA Signature Pass

fly333sky, thanks for your pull request. All authors of the commits have signed the CLA. 👍

@opensourceways-bot

Copy link
Copy Markdown
检查项 状态
敏感信息扫描
漏洞扫描
Check代码检查
开源license合规扫描
开发阶段设计文档检查
流水线链接 点击跳转查看日志

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants