restrict v5

This commit is contained in:
tamakyi
2026-10-18 21:59:12 +08:00
parent 52f0712eda
commit d14d26df17
4 changed files with 31 additions and 4 deletions
+6 -2
View File
@@ -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
}