fix(vote): 站方处置覆盖投票链路
提问链路上 ActiveLevel 有 7 处调用,投票链路 0 处。于是 L4(整页停用)处置某人后:
/_/domain 已经 302 到 /restricted,但 /vote/{token} 照常渲染、照常收票;被处置者
还能发新投票;探索页的「热门/全部投票」也不做处置过滤 —— 同一张页面里
「箱主消失了、他的投票还在曝光」。这是运营口径不一致,不是越权。
补齐三处,与提问链路对齐:
- vote.Page L4 → 302 /restricted(同箱主页;查询失败 fail-open,与 Pager 一致)
- vote.Submit L4 → 拒绝(页面进不去不代表直接构造 POST 也拦得住)
- VotePublish L2 起拒绝(L2 已是「收窄公开」,不该再新增公开内容)
- 探索页投票列表改用 Restrictions.ActiveLevels 批量过滤(与 GetShowInHome 同口径,
一次查询避免 N+1),功能开关过滤逻辑保持不变
新增字典 key vote.err.restrictedPublish(四语言)。
验证(本地实例):
- L4 后 /vote/{token} 302 → /restricted;撤销后恢复 200
- 探索页该投票出现次数 0(处置中)→ 2(撤销后)
- 草稿投票在 L2 下发布后状态停留 draft,撤销后同一请求变为 published
This commit is contained in:
@@ -915,6 +915,21 @@ func VotePublish(ctx context.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
// 站方处置:L2 起不得再发布新的公开内容(与「设公开」同口径)。
|
||||
// 此前投票链路完全没有处置校验:被处置的箱主仍能发新投票并进探索页曝露。
|
||||
level, _, err := db.Restrictions.ActiveLevel(ctx.Request().Context(), ctx.User.ID)
|
||||
if err != nil {
|
||||
logrus.WithContext(ctx.Request().Context()).WithError(err).Error("Failed to query user restriction")
|
||||
ctx.SetInternalErrorFlash()
|
||||
ctx.Redirect("/user/questions#votes")
|
||||
return
|
||||
}
|
||||
if db.RestrictionAtLeast(level, db.RestrictionL2) {
|
||||
ctx.SetErrorFlash(i18n.T(ctx.Lang(), "vote.err.restrictedPublish"))
|
||||
ctx.Redirect("/user/questions#votes")
|
||||
return
|
||||
}
|
||||
|
||||
if err := validateForPublish(ctx, vote); err != nil {
|
||||
ctx.SetErrorFlash(err.Error())
|
||||
ctx.Redirect("/user/questions#votes")
|
||||
|
||||
Reference in New Issue
Block a user