feat: 就地通过评审,并为已过审用户提供默认可关的免审发布

帖/评管理入口可直接通过;站点默认信任已有 published 内容的用户后续直发。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-09-16 05:37:57 +08:00
parent b0170a99fd
commit f3145b24ff
14 changed files with 330 additions and 40 deletions

View File

@@ -280,6 +280,26 @@ func (s *ModerationService) RejectComment(actor *Actor, id uint) error {
})
}
// UserHasApprovedContent 用户是否已有至少一篇已发布帖子或一条已发布评论(即曾通过审核或免审直发)
func (s *ModerationService) UserHasApprovedContent(userID uint) (bool, error) {
var n int64
if err := s.db.Model(&model.Post{}).
Where("user_id = ? AND status = ?", userID, model.ContentStatusPublished).
Limit(1).Count(&n).Error; err != nil {
return false, err
}
if n > 0 {
return true, nil
}
n = 0
if err := s.db.Model(&model.Comment{}).
Where("user_id = ? AND status = ?", userID, model.ContentStatusPublished).
Limit(1).Count(&n).Error; err != nil {
return false, err
}
return n > 0, nil
}
func keys(m map[uint]bool) []uint {
out := make([]uint, 0, len(m))
for k := range m {

View File

@@ -13,6 +13,8 @@ import (
const (
// SettingKeyAccent 站点主题色(浅色基准,#rrggbb);为空表示使用内置默认色
SettingKeyAccent = "theme_accent"
// SettingKeyTrustReviewedPublish 已过审用户后续发帖/评论免审;缺行视为开启(默认开)
SettingKeyTrustReviewedPublish = "trust_reviewed_publish"
)
// ErrInvalidAccent 主题色格式非法
@@ -55,3 +57,33 @@ func (s *SettingService) SetAccent(hex string) error {
st := model.SiteSetting{Key: SettingKeyAccent, Value: hex}
return s.db.Save(&st).Error
}
// TrustReviewedPublish 是否对「已有过审内容」的用户免审。
// KV 缺行 / 空值视为开启(默认开);仅显式写入 false/0/off/no 为关闭。
// 不用 GORM bool default:true,避免零值省略陷阱。
func (s *SettingService) TrustReviewedPublish() (bool, error) {
var st model.SiteSetting
err := s.db.Where("key = ?", SettingKeyTrustReviewedPublish).First(&st).Error
if errors.Is(err, gorm.ErrRecordNotFound) {
return true, nil
}
if err != nil {
return true, err
}
v := strings.TrimSpace(strings.ToLower(st.Value))
switch v {
case "false", "0", "off", "no":
return false, nil
default:
return true, nil
}
}
// SetTrustReviewedPublish 持久化免审开关;开启时删除键以保持「缺行=默认开」语义
func (s *SettingService) SetTrustReviewedPublish(on bool) error {
if on {
return s.db.Where("key = ?", SettingKeyTrustReviewedPublish).Delete(&model.SiteSetting{}).Error
}
st := model.SiteSetting{Key: SettingKeyTrustReviewedPublish, Value: "false"}
return s.db.Save(&st).Error
}