修复后台评论加载问题,非admin也可加载对自己文章的未审核评论。

This commit is contained in:
2026-08-26 17:59:03 +08:00
parent 20395a79a2
commit cfe5cf53aa
6 changed files with 24 additions and 24 deletions
+8 -8
View File
@@ -35,9 +35,13 @@ func GetComments(c *gin.Context) {
})
// 非管理员只能查看自己文章上的评论(后台)或已审核的评论(前台)
if !isAdmin(c) {
// 前台访问:只显示已审核的评论
db = db.Where("status = ?", "approved")
if isAdmin(c) {
// 管理员可以查看所有评论
if status != "" {
db = db.Where("status = ?", status)
}
} else {
if userID, exists := c.Get("userID"); exists {
// 如果是后台接口调用,限制为自己的文章
if postID == "" && postSlug == "" {
@@ -45,11 +49,7 @@ func GetComments(c *gin.Context) {
database.DB.Model(&models.Post{}).Select("id").Where("author_id = ?", userID))
}
}
} else {
// 管理员可以查看所有状态的评论(通过 status 参数过滤)
if status != "" {
db = db.Where("status = ?", status)
}
}
// 按文章 ID 或 slug 过滤