restrict v8
This commit is contained in:
@@ -6,6 +6,8 @@ package question
|
||||
|
||||
import (
|
||||
stdctx "context"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
@@ -47,6 +49,46 @@ func allowAbuseAlert(userID uint) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// questionReportNoticeThreshold 单条内容被举报多少人次时提醒箱主自查。
|
||||
//
|
||||
// 取 3:一两个人可能是私人恩怨,三个人以上通常是内容本身有问题。
|
||||
const questionReportNoticeThreshold = 3
|
||||
|
||||
// notifyQuestionOwner 在单条内容的待处理举报数**恰好**达到阈值时提醒箱主。
|
||||
//
|
||||
// 用「恰好等于」而不是「大于等于」:前者只发一次,后者会从第 3 条起每条举报都发一封信。
|
||||
// 箱主关闭邮件通知(Notify=none)时不发 —— 后台的「被举报 N 次」标记仍然可见,
|
||||
// 治理提醒不该以无视用户通知偏好为代价。
|
||||
func notifyQuestionOwner(pageUser *db.User, question *db.Question) {
|
||||
if pageUser.Email == "" || pageUser.Notify == db.NotifyTypeNone {
|
||||
return
|
||||
}
|
||||
|
||||
shared.SafeGo(func() {
|
||||
ctx := stdctx.Background()
|
||||
|
||||
count, err := db.Reports.CountByQuestion(ctx, question.ID)
|
||||
if err != nil {
|
||||
logrus.WithError(err).Error("Failed to count reports for question")
|
||||
return
|
||||
}
|
||||
if count != questionReportNoticeThreshold {
|
||||
return
|
||||
}
|
||||
|
||||
link := strings.TrimRight(conf.App.ExternalURL, "/") + "/_/" + pageUser.Domain + "/" + strconv.FormatUint(uint64(question.ID), 10)
|
||||
if err := mail.SendQuestionReportedMail(pageUser.Email, pageUser.Domain, question.ID, count, link); err != nil {
|
||||
logrus.WithError(err).Error("Failed to send question reported mail")
|
||||
return
|
||||
}
|
||||
logrus.WithFields(logrus.Fields{
|
||||
"user_id": pageUser.ID,
|
||||
"question_id": question.ID,
|
||||
"count": count,
|
||||
}).Warn("Question owner notified about reports")
|
||||
})
|
||||
}
|
||||
|
||||
// notifyAbuseIfNeeded 在举报写入后判断是否达到告警阈值,异步发送汇总邮件。
|
||||
//
|
||||
// 只发「该看一眼」的信号,不做任何自动处置:举报数达标不等于内容违规,
|
||||
@@ -82,10 +124,10 @@ func notifyAbuseIfNeeded(pageUser *db.User) {
|
||||
return
|
||||
}
|
||||
logrus.WithFields(logrus.Fields{
|
||||
"user_id": pageUser.ID,
|
||||
"domain": pageUser.Domain,
|
||||
"count24": count24,
|
||||
"count7d": count7d,
|
||||
"user_id": pageUser.ID,
|
||||
"domain": pageUser.Domain,
|
||||
"count24": count24,
|
||||
"count7d": count7d,
|
||||
}).Warn("Abuse alert mail sent")
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user