restrict v9

This commit is contained in:
tamakyi
2026-10-18 23:48:57 +08:00
parent 7a6417c33d
commit 7e0e1cba49
5 changed files with 38 additions and 3 deletions
+27
View File
@@ -364,3 +364,30 @@ admin6 当前处于 L2(到期次日),必要时 `unrestrict` 解除。
⚠️ 文案由我起草,**需用户过目**(尤其对外承诺的措辞)。
验证:`go build ./...` EXIT=0;`checktpl` OK;`TestReports`/`TestRestrictions` 全绿。
### 部署后验证:3 项通过,1 项 500 待查
- ✅ 处置期条幅:登录 admin6 的 `/user/questions` 出现「限制期」文案(1 处);
- ✅ 举报 badge:「被举报 1 次」;
- ✅ 闭环:`POST /set-private` → badge 归 0、公开页不再出现 73;
`set-public` 返回 200(不是 302)是**预期** —— L2 禁止设公开,不是 bug。73 现处于私密,需先 `unrestrict` 才能恢复。
- ❌ **`/rules` 返回 500**(其余公开页 `/`、`/about-me`、`/sponsor`、`/deactivated` 均 200)。
已在本地排除:模板语法 checktpl 通过、i18n 四语言键齐全(grep 确认在 map 内)、`t` 函数返回 string 不抛错。
**待用户提供服务端日志**(500 只回 22 字节 "Internal Server Error",无细节)。
顺带修掉一个**我引入的回归**:`templates/render_test.go` 的 `mockItem` 缺 `ReportCount`,
导致 `user/question-list` 渲染测试失败(`can't evaluate field ReportCount in type interface {}`)。
已补字段;同时把 `{{ if gt .ReportCount 0 }}` 改为 `{{ if .ReportCount }}`(更宽容,零值即假)。
`go test ./templates/` 恢复全绿。
### /rules 500 根因:模板没进 embed 清单
日志:`template: rendering error="html/template: \"rules\" is undefined"`。
**`templates/embed.go` 是显式文件清单**(并非我原先以为的整目录 embed)。新增的顶层
`rules.html` 没写进 `//go:embed ...` 那行 → 没被打包 → `ctx.Success("rules")` 找不到模板 → 500。
编译、checktpl、单测全部无感(测试不渲染该页),只有实际访问才炸。
已把 `rules.html` 加进清单,编译 EXIT=0、`go test ./templates/` 通过。
⚠️ 以后新增**顶层**模板必须改 embed 指令;子目录下的文件已被目录项覆盖。
MEMORY.md 里那条错误认知已纠正。
+6 -1
View File
@@ -151,7 +151,12 @@
落 `/login` 会让用户以为没生效;该路由必须注册在**公开区**(`reqUserSignIn` 之外)。
- **继续可登录的操作(改密码后重登)才用闪信 + `/login`**:顺序**先 `Session.Flush()` 再 `SetSuccessFlash()`**。
- i18n 键名:`deactivate.*` = 停用表单页;`deactivated.*` = 停用成功页。
- `templates/embed.go` 整目录 embed,**新增模板自动嵌入**,无需改指令。
- ⚠️ **`templates/embed.go` 是显式清单,不是整目录 embed**:
`//go:embed auth base mail question user chat vote home.html about-me.html sponsor.html rules.html change-logs.html pixel.html maintenance-mode.html`
新增**顶层**模板必须加进这行指令,否则 `ctx.Success("xxx")` 在运行时报
`html/template: "xxx" is undefined` → 500,而**编译期毫无提示**(测试也不渲染该页)。
子目录(`user/` `mail/` `question/` 等)已被目录项整体覆盖,新增其中的文件不用改指令。
2026-10-18 踩过一次:新增 `/rules` 页时漏加,线上只有该页 500。
## 仓库状态
+1 -1
View File
@@ -8,5 +8,5 @@ import (
"embed"
)
//go:embed auth base mail question user chat vote home.html about-me.html sponsor.html change-logs.html pixel.html maintenance-mode.html
//go:embed auth base mail question user chat vote home.html about-me.html sponsor.html rules.html change-logs.html pixel.html maintenance-mode.html
var FS embed.FS
+3
View File
@@ -339,6 +339,9 @@ func TestRenderUserQuestionList(t *testing.T) {
QuestionID uint
IsPinned bool
PinLink string
// ReportCount 对应线上的 receivedItem(箱主列表的「被举报 N 次」标记)。
// 这里漏掉会让 question-list 模板在 range 时取字段失败。
ReportCount int64
}
type mockConv struct {
Token string
+1 -1
View File
@@ -273,7 +273,7 @@
{{ if not .IsAnswered }}
<span class="uk-label qlist-pill" title="{{t $.LangCode "qlist.unanswered"}}"><span class="tb-short">{{t $.LangCode "qlist.unansweredShort"}}</span><span class="tb-text">{{t $.LangCode "qlist.unanswered"}}</span></span>
{{ end }}
{{ if gt .ReportCount 0 }}
{{ if .ReportCount }}
<span class="uk-label uk-label-danger qlist-pill" title="{{t $.LangCode "qlist.reported" .ReportCount}}"><span class="tb-short">{{t $.LangCode "qlist.reportedShort" .ReportCount}}</span><span class="tb-text">{{t $.LangCode "qlist.reported" .ReportCount}}</span></span>
{{ end }}
{{ if .IsRead }}