restrict v5
This commit is contained in:
@@ -167,7 +167,8 @@ func AnswerFollowUp(ctx context.Context, pageUser *db.User, question *db.Questio
|
||||
return
|
||||
}
|
||||
if db.RestrictionAtLeast(restrictionLevel, db.RestrictionL2) {
|
||||
ctx.SetErrorFlash(i18n.T(ctx.Lang(), "question.errRestrictedPublish"))
|
||||
// 同请求渲染,用 SetError(SetErrorFlash 要等下一次请求才显示)。
|
||||
ctx.SetError(errors.New(i18n.T(ctx.Lang(), "question.errRestrictedPublish")), f)
|
||||
ctx.Success("question/item")
|
||||
return
|
||||
}
|
||||
@@ -176,7 +177,8 @@ func AnswerFollowUp(ctx context.Context, pageUser *db.User, question *db.Questio
|
||||
|
||||
// 内容安全检测:统一守卫,箱主本人回复同样按自己的审核严格度裁决。
|
||||
if _, err := moderation.Check(ctx.Request().Context(), moderation.StrictnessFor(pageUser.ModerationStrictness), ctx.Lang(), f.Answer); err != nil {
|
||||
ctx.SetErrorFlash(err.Error())
|
||||
// 同请求渲染,用 SetError;原先的 SetErrorFlash 在这里不会显示出来(既有缺陷)。
|
||||
ctx.SetError(err, f)
|
||||
ctx.Success("question/item")
|
||||
return
|
||||
}
|
||||
|
||||
@@ -174,7 +174,10 @@ func PublishAnswer(ctx context.Context, pageUser *db.User, question *db.Question
|
||||
return
|
||||
}
|
||||
if db.RestrictionAtLeast(restrictionLevel, db.RestrictionL3) {
|
||||
ctx.SetErrorFlash(i18n.T(ctx.Lang(), "question.errRestrictedPublish"))
|
||||
// 这里是**同请求渲染**(Success 直接出页面,没有重定向),必须用 SetError 写
|
||||
// Data["Error"];SetErrorFlash 依赖下一次请求读取,用在这里提示会静默丢失
|
||||
// (线上实测:箱主点提交后页面毫无反应,以为没生效)。
|
||||
ctx.SetError(errors.New(i18n.T(ctx.Lang(), "question.errRestrictedPublish")), f)
|
||||
ctx.Success("question/item")
|
||||
return
|
||||
}
|
||||
@@ -303,7 +306,8 @@ func SetPublic(ctx context.Context, pageUser *db.User, question *db.Question, ca
|
||||
return
|
||||
}
|
||||
if db.RestrictionAtLeast(restrictionLevel, db.RestrictionL2) {
|
||||
ctx.SetErrorFlash(i18n.T(ctx.Lang(), "question.errRestrictedPublic"))
|
||||
// 同请求渲染,用 SetError(原因见 PublishAnswer 的 L3 分支)。
|
||||
ctx.SetError(errors.New(i18n.T(ctx.Lang(), "question.errRestrictedPublic")))
|
||||
ctx.Success("question/item")
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user