Commit Graph
10 Commits
Author SHA1 Message Date
dsh d78ed8e2fe refactor: 文章新建/编辑表单收敛为单一模板 article_form,删除两套重复模板
- 新增 templates/partials/article_form.html(define article_form):
  按 .FormIsMy 分支渲染——管理员变体(标签/置顶勾选/草稿发布双按钮/
  /api/admin/articles)与作者变体(状态下拉/保存取消//api/my/articles)
- renderArticleForm / renderMyArticleForm 均渲染 article_form,各自
  设置 FormIsMy=false/true;JS 统一(API_BASE/redirectBase/editor/
  错误提示均单份)
- 删除 templates/admin/article_create.html 与
  templates/user/my_article_form.html(约 360 行 → 一份 ~230 行)
- 新增 TestArticleFormTemplateVariants 断言两个变体渲染差异;
  测试环境注册两个工作区的新建页路由
2026-08-28 20:02:46 +08:00
dsh 134943e4fb feat: 普通用户文章页补齐附件区(上传/列表/插入正文/设封面/删除)
- 新增共享部分模板 templates/partials/article_attachments.html
  (附件区标记:文件名/大小/操作列 + 上传按钮)
- 新增共享 static/js/article-attachments.js:上传(multipart→files 表
  type=attachments)、编辑页回填、插入正文、图片一键设封面、删除;
  uploadURL/listURL/editor/i18n 文案均由页面注入
- 管理员页改用共享 partial+JS(行为不变);同时修复既有 bug:
  表单提交闭包引用未声明的 articleID(作用域错误导致保存静默失败)
- 普通用户页加入附件区,走 /api/my/articles/attachments(新建页
  session_token / 编辑页 article_id),支持一键设封面/插入正文
2026-08-28 20:02:46 +08:00
dsh 6216b9af13 feat: 文章新建/编辑页编辑器支持本地图片上传并插入正文
- 两套页面(admin + 普通用户)EasyMDE 的 image 按钮改为“上传图片”:
  选择本地图片 → 走既有附件接口(files 表 type=attachments,新建页
  session_token / 编辑页 article_id)→ 在正文光标处插入 ![](url)
- templates/layouts/base.html:新增共享 window.blogUploadImage 上传助手
- templates/user/my_article_form.html:新建页 session_token 输入框加 id
  (编辑器上传需要读取);补齐原本缺失的上传能力
- i18n:新增 article_image_upload / article_image_not_image(中英)
- 服务端依既有上传策略校验(扩展名/MIME/魔数/大小),客户端限 image/*
2026-08-28 20:02:46 +08:00
kevin 6220de9c84 fix: 编辑/新建文章页 Font Awesome 改用本地 vendored 资源
easyMDE 会注入失效的 maxcdn.bootstrapcdn.com 样式链接导致工具栏图标加载失败。
按 SECURITY_TODO #9 无外部 CDN 政策,本地化 Font Awesome 4.7.0(css+fonts),
并在两处 EasyMDE 配置中禁用 autoDownloadFontAwesome。
2026-08-28 16:26:06 +08:00
dsh 7e6dd0cc02 fix: SECURITY_TODO #31 普通作者不可置顶全站文章
任意注册作者可经 /api/my/articles 提交 is_top=true 把文章钉在全站
首页最顶端(publishedArticleOrder 为 is_top DESC 优先),属影响公共
展示位的横向越权(确认非设计意图,予收紧)。

- handlers/article.go: 拆出共享实现 articleCreate/articleUpdate,
  增加 allowIsTop 开关;admin 路径保持 true
- handlers/my_articles.go: 作者创建强制 is_top=false;编辑保留库中
  现有值(管理员授权的置顶不因作者编辑而丢失,作者也无法自行取消)
- templates/user/my_article_form.html: 移除置顶复选框
- 测试: TestMyArticlesCannotPin(作者 create/update is_top=true →
  落库 false;admin 路径可置顶;作者编辑不丢置顶)
2026-08-27 21:46:27 +08:00
kevin 5b227b71ef feat: 文章 CRUD 接口 JSON 化——/api/admin|my/articles
- article.go:articleForm 加 json tags,新增 parseArticleFormJSON(绑定+
  去白);ArticleCreate/ArticleUpdate/ArticleDelete 增加 redirectPath 参数,
  校验失败改 APIError 400、DB 错误 500,成功 {ok,redirect}(原 renderForm
  分支移除);id 改用 parseUintParam 数值化
- my_articles.go:MyArticleCreate 复用 ArticleCreate(db, /my/articles);
  MyArticleUpdate/MyArticleDelete 保留 author_id 所有权约束(404
  article_not_found);my 更新不触碰标签(表单无该字段,与旧行为一致)
- main.go:admin/my 文章旧 POST 路由移除,改 POST/PUT/DELETE
  /api/admin/articles[/:id] 与 /api/my/articles[/:id]
- 模板:article_create.html/my_article_form.html 表单改 blogAPI 提交
  (easyMDE.value() 同步正文、editor e.submitter 分流草稿/发布),错误内联
  articleError/myArticleError;article_list.html/my_articles.html 删除改
  blogDelete 委托(base.html 新公共函数,DELETE + reload 保筛选状态)
- main_test 冒烟补文章 CRUD 断言;go build/vet/test 全绿
2026-08-27 19:40:02 +08:00
kevin 38cd09f723 fix: 安全加固,修复 P0/P1 安全漏洞
P0(高危):
- 新增全局 CSRF 中间件(同步器令牌),覆盖全部 30 个表单与 AJAX 请求
- 修复附件上传/列表/删除越权(IDOR),增加 admin/上传者/文章作者所有权校验
- 登录/注册成功后会话轮换,修复会话固定
- 会话密钥改用 crypto/rand 生成,配置缺失 secret 时拒绝启动

P1(中危):
- session 与 comment_uid cookie 增加 Secure/SameSite 标志
- 新增安全响应头:CSP、X-Content-Type-Options、X-Frame-Options、HSTS 等
- 新增 web.trusted_proxies 配置,修复 X-Forwarded-For 伪造
- 修复浏览量记录 goroutine 访问已回收 gin.Context 的数据竞争

补充 17 个安全回归测试(middleware/handlers),go test -race 全绿
2026-08-19 12:33:09 +08:00
dsh 83866f6de2 feat: enhance frontend Markdown rendering
- Add shared BlogMD renderer (static/js/markdown.js): marked + DOMPurify
  + highlight.js pipeline with GFM support, heading id slugger with
  CJK-aware anchors, syntax highlighting, per-block copy button and
  language badge, lazy images with lightbox, external links opened
  safely in new tabs, tables wrapped for small screens.
- Add .md-body typography styles (static/css/markdown.css) so articles,
  comments and editor previews render with proper headings, tables,
  lists, blockquotes and code blocks (previously the prose classes had
  no effect because the Tailwind typography plugin is not loaded).
- Fix marked options that were set after parsing and removed from
  marked v4+ (mangle/headerIds no-ops).
- Pin CDN versions (marked 15.0.12, dompurify 3.4.13, highlight.js
  11.12.0) instead of floating 'latest' URLs.
- Wire EasyMDE preview/side-by-side to BlogMD in admin and user
  article editors; use BlogMD for comment bodies on the article page,
  admin comment list and comment preview.
- Serve /static in main.go and deploy it in install_linux.sh.
2026-08-18 06:05:53 -04:00
kevinandClaude Fable 5 b0ca76e8dc feat: add custom publish time and last updated time display
- Add custom publish time field to article create/edit forms
  - Support datetime-local input for manual time setting
  - Auto-set on first publish if left blank
  - Works for both admin and user article forms

- Display last updated time on article detail page
  - Show both published time and last updated time
  - Auto-maintained by GORM on each update
  - Format: YYYY-MM-DD HH:MM

- Add i18n support for new fields
  - article_published_at: Published Time / 发布时间
  - article_published_at_hint: Leave blank to auto-set on publish / 留空则在发布时自动设置
  - article_last_updated: Last Updated / 最后更新

- Update handlers and templates
  - handlers/article.go: Add parsePublishedAt/formatPublishedAt functions
  - handlers/home.go: Add formatUpdateTime function
  - handlers/my_articles.go: Support custom publish time in user articles
  - templates: Add datetime-local inputs and time display

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-06-22 20:20:19 +08:00
kevinandClaude Fable 5 d64c839b10 feat: add role-based access control and user article management
- Add AdminRequired middleware to all /admin routes for proper authorization
- Restrict admin panel, comments, users, settings to admin role only
- Create separate /my/articles routes for regular users to manage their own articles
- Add MyArticlesPage handler for users to view/edit/delete their own content
- Update navigation menus with role-based visibility
- Admin dropdown shows only 'Admin Panel' link, other features in dashboard
- Regular users see 'My Articles' link in profile dropdown
- Add i18n translations for 'my_articles' and 'comment_manage' keys
- Fix permission boundary issues where author role could access admin settings

Security improvements:
- Platform settings now require admin role
- Comment moderation requires admin role
- User management requires admin role
- Regular users can only manage their own articles

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-06-22 18:49:33 +08:00