fix v13
This commit is contained in:
+16
-14
@@ -185,26 +185,20 @@ func PublishAnswer(ctx context.Context, pageUser *db.User, question *db.Question
|
||||
// 🚨 Content security check.
|
||||
// 统一守卫:按箱主「审核严格度」裁决是否放行(审核源不可用仍为 fail-closed,
|
||||
// 拒绝发布而非免审放行)。返回的 censorResponse 用于下方落审计字段。
|
||||
censorResponse, err := moderation.Check(ctx.Request().Context(), moderation.EffectiveStrictness(ctx.Request().Context(), pageUser.ID, pageUser.ModerationStrictness), ctx.Lang(), answer)
|
||||
// 已经查过处置级别,直接用,避免 EffectiveStrictness 再打一次同样的库。
|
||||
censorResponse, err := moderation.Check(ctx.Request().Context(), moderation.EffectiveStrictnessFor(restrictionLevel, pageUser.ModerationStrictness), ctx.Lang(), answer)
|
||||
if err != nil {
|
||||
ctx.SetError(err, f)
|
||||
ctx.Success("question/item")
|
||||
return
|
||||
}
|
||||
|
||||
// L2 收窄公开:审核通过后再把该题置为私密,然后写入回答。
|
||||
// L2 收窄公开:审核通过后写回答,并在同一条 UPDATE 里把题目置为私密。
|
||||
// 顺序不能提前到审核之前 —— 审核失败(违规或审核源不可用,fail-closed)会直接返回,
|
||||
// 那时题目已经被改成私密,等于箱主一次失败的编辑让原有公开内容凭空消失。
|
||||
// 放在这里仍然满足「任何时刻都不出现公开 + 已作答」:此刻它还是一条未作答的私密题。
|
||||
// 也不能拆成「先 SetPrivate 再 AnswerByID」:两条语句之间有「公开 + 已作答」窗口,
|
||||
// 且第二条失败会留下「私密 + 无回答」(内容凭空消失)。见 AnswerByIDPrivate 注释。
|
||||
forcedPrivate := db.RestrictionAtLeast(restrictionLevel, db.RestrictionL2)
|
||||
if forcedPrivate {
|
||||
if err := db.Questions.SetPrivate(ctx.Request().Context(), question.ID); err != nil {
|
||||
logrus.WithContext(ctx.Request().Context()).WithError(err).Error("Failed to force question private")
|
||||
ctx.SetInternalError()
|
||||
ctx.Success("question/item")
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
if len(f.Images) > 0 {
|
||||
image := f.Images[0]
|
||||
@@ -226,8 +220,14 @@ func PublishAnswer(ctx context.Context, pageUser *db.User, question *db.Question
|
||||
}
|
||||
}
|
||||
|
||||
if err := db.Questions.AnswerByID(ctx.Request().Context(), question.ID, f.Answer); err != nil {
|
||||
logrus.WithContext(ctx.Request().Context()).WithError(err).Error("Failed to answer question")
|
||||
var answerErr error
|
||||
if forcedPrivate {
|
||||
answerErr = db.Questions.AnswerByIDPrivate(ctx.Request().Context(), question.ID, f.Answer)
|
||||
} else {
|
||||
answerErr = db.Questions.AnswerByID(ctx.Request().Context(), question.ID, f.Answer)
|
||||
}
|
||||
if answerErr != nil {
|
||||
logrus.WithContext(ctx.Request().Context()).WithError(answerErr).Error("Failed to answer question")
|
||||
ctx.SetInternalError(f)
|
||||
ctx.Success("question/item")
|
||||
return
|
||||
@@ -241,7 +241,9 @@ func PublishAnswer(ctx context.Context, pageUser *db.User, question *db.Question
|
||||
}
|
||||
|
||||
shared.SafeGo(func() {
|
||||
if question.ReceiveReplyEmail != "" && question.Answer == "" { // We only send the email when the question has not been answered.
|
||||
// L2 下题目刚被强制转为私密:提问者没有访问权限,带 token 的链接点开也是 302。
|
||||
// 这时发「你的提问有回答」只会让人以为内容丢了,因此跳过通知。
|
||||
if question.ReceiveReplyEmail != "" && question.Answer == "" && !forcedPrivate { // We only send the email when the question has not been answered.
|
||||
// Send notification to questioner.
|
||||
if err := mail.SendNewAnswerMail(question.ReceiveReplyEmail, pageUser.Domain, question.ID, question.Content, f.Answer, question.Token); err != nil {
|
||||
logrus.WithContext(stdctx.Background()).WithError(err).Error("Failed to send receive reply mail to questioner")
|
||||
|
||||
Reference in New Issue
Block a user