restrict v1
This commit is contained in:
@@ -164,6 +164,30 @@ func PublishAnswer(ctx context.Context, pageUser *db.User, question *db.Question
|
||||
|
||||
answer := f.Answer
|
||||
|
||||
// 站方处置:L3 起冻结发布,L2 收窄公开(回答强制转私密)。
|
||||
// 处置记录只能由运维经 CLI 写入,箱主无法自行解除 —— 与 feature_controls 的自主开关严格区分。
|
||||
restrictionLevel, _, err := db.Restrictions.ActiveLevel(ctx.Request().Context(), pageUser.ID)
|
||||
if err != nil {
|
||||
logrus.WithContext(ctx.Request().Context()).WithError(err).Error("Failed to query user restriction")
|
||||
ctx.SetInternalError()
|
||||
ctx.Success("question/item")
|
||||
return
|
||||
}
|
||||
if db.RestrictionAtLeast(restrictionLevel, db.RestrictionL3) {
|
||||
ctx.SetErrorFlash(i18n.T(ctx.Lang(), "question.errRestrictedPublish"))
|
||||
ctx.Success("question/item")
|
||||
return
|
||||
}
|
||||
// L2:先把该题置为私密再写入回答,任何时刻都不会出现「公开 + 已作答」的中间态。
|
||||
if db.RestrictionAtLeast(restrictionLevel, db.RestrictionL2) {
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
// 🚨 Content security check.
|
||||
// 统一守卫:按箱主「审核严格度」裁决是否放行(审核源不可用仍为 fail-closed,
|
||||
// 拒绝发布而非免审放行)。返回的 censorResponse 用于下方落审计字段。
|
||||
@@ -259,6 +283,20 @@ func SetPublic(ctx context.Context, pageUser *db.User, question *db.Question, ca
|
||||
return
|
||||
}
|
||||
|
||||
// 站方处置 L2 起禁止「设为公开」:L2 的语义就是收窄公开,放开等于自行解除处置。
|
||||
restrictionLevel, _, err := db.Restrictions.ActiveLevel(ctx.Request().Context(), pageUser.ID)
|
||||
if err != nil {
|
||||
logrus.WithContext(ctx.Request().Context()).WithError(err).Error("Failed to query user restriction")
|
||||
ctx.SetInternalError()
|
||||
ctx.Success("question/item")
|
||||
return
|
||||
}
|
||||
if db.RestrictionAtLeast(restrictionLevel, db.RestrictionL2) {
|
||||
ctx.SetErrorFlash(i18n.T(ctx.Lang(), "question.errRestrictedPublic"))
|
||||
ctx.Success("question/item")
|
||||
return
|
||||
}
|
||||
|
||||
if err := db.Questions.SetPublic(ctx.Request().Context(), question.ID); err != nil {
|
||||
logrus.WithContext(ctx.Request().Context()).WithError(err).Error("Failed to set question public")
|
||||
ctx.SetInternalError()
|
||||
|
||||
Reference in New Issue
Block a user