mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-09-15 18:56:59 +00:00
Address review comments
This addresses the review comments from the PR, namely: * Give the new configuration a name that makes it easy for an admin looking at the configuration file what the setting enables. * Register the task that removes resolved reports ONLY when the moderation setting is enabled * Make sure we're using the timeout setting when it is passed to the RemoveResolvedReports function * Consider reports with either ignored or handled status as resolved Follow up commit will handle deleting the shadow copies of the reports being removed
This commit is contained in:
parent
7d885406cf
commit
33ac0de263
4 changed files with 35 additions and 12 deletions
|
@ -1581,8 +1581,8 @@ LEVEL = Info
|
|||
;; If enabled it will be possible for users to report abusive content (new actions are added in the UI and /report_abuse route will be enabled) and a new Moderation section will be added to Admin settings where the reports can be reviewed.
|
||||
;ENABLED = false
|
||||
|
||||
;; Timeout for removing resolved reports
|
||||
;REMOVE_RESOLVED_REPORTS_TIMEOUT = 0
|
||||
;; Time to keep resolved abuse reports.
|
||||
;KEEP_RESOLVED_REPORTS_FOR = 0
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
|
|
@ -8,6 +8,7 @@ import (
|
|||
"database/sql"
|
||||
"errors"
|
||||
"slices"
|
||||
"time"
|
||||
|
||||
"forgejo.org/models/db"
|
||||
"forgejo.org/modules/log"
|
||||
|
@ -154,6 +155,25 @@ func ReportAbuse(ctx context.Context, report *AbuseReport) error {
|
|||
return err
|
||||
}
|
||||
|
||||
// GetResolvedReports gets all resolved reports
|
||||
func GetResolvedReports(ctx context.Context, timeout time.Duration) ([]*AbuseReport, error) {
|
||||
cond := builder.And(
|
||||
builder.Or(
|
||||
builder.Eq{"`status`": ReportStatusTypeHandled},
|
||||
builder.Eq{"`status`": ReportStatusTypeIgnored},
|
||||
),
|
||||
)
|
||||
|
||||
if timeout > 0 {
|
||||
cond = cond.And(builder.Lt{"created_unix": time.Now().Add(-timeout).Unix()})
|
||||
}
|
||||
|
||||
abuse_reports := make([]*AbuseReport, 0, 30)
|
||||
return abuse_reports, db.GetEngine(ctx).
|
||||
Where(cond).
|
||||
Find(&abuse_reports)
|
||||
}
|
||||
|
||||
/*
|
||||
// MarkAsHandled will change the status to 'Handled' for all reports linked to the same item (user, repository, issue or comment).
|
||||
func MarkAsHandled(ctx context.Context, contentType ReportedContentType, contentID int64) error {
|
||||
|
|
|
@ -229,18 +229,18 @@ func registerRebuildIssueIndexer() {
|
|||
func registerRemoveResolvedReports() {
|
||||
type ReportConfig struct {
|
||||
BaseConfig
|
||||
Timeout time.Duration
|
||||
ConfiguredTimeOut time.Duration
|
||||
}
|
||||
RegisterTaskFatal("remove_resolved_reports", &ReportConfig{
|
||||
BaseConfig: BaseConfig{
|
||||
Enabled: false,
|
||||
RunAtStart: false,
|
||||
Schedule: "@every 72h",
|
||||
Schedule: "@every 24h",
|
||||
},
|
||||
Timeout: time.Duration(setting.Moderation.RemoveResolvedReportsTimeout) * time.Second,
|
||||
ConfiguredTimeOut: time.Duration(setting.Moderation.RemoveResolvedReportsTimeout) * time.Second,
|
||||
}, func(ctx context.Context, _ *user_model.User, config Config) error {
|
||||
reportConfig := config.(*ReportConfig)
|
||||
return moderation_service.RemoveResolvedReports(ctx, reportConfig.Timeout)
|
||||
return moderation_service.RemoveResolvedReports(ctx, reportConfig.ConfiguredTimeOut)
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -259,5 +259,7 @@ func initExtendedTasks() {
|
|||
registerDeleteOldSystemNotices()
|
||||
registerGCLFS()
|
||||
registerRebuildIssueIndexer()
|
||||
registerRemoveResolvedReports()
|
||||
if setting.Moderation.Enabled {
|
||||
registerRemoveResolvedReports()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -134,18 +134,19 @@ func CanReport(ctx context.Context, doer *user.User, contentType moderation.Repo
|
|||
func RemoveResolvedReports(ctx context.Context, timeout time.Duration) error {
|
||||
log.Trace("Doing: RemoveResolvedReports")
|
||||
|
||||
status := moderation.ReportStatusTypeHandled
|
||||
resolvedReports, err := db.GetEngine(ctx).Table("abuse_report").Where("status = ?", status).Exist()
|
||||
resolved_reports, err := moderation.GetResolvedReports(ctx, timeout)
|
||||
if err != nil {
|
||||
return err
|
||||
} else if resolvedReports {
|
||||
_, err := db.GetEngine(ctx).Table("abuse_report").Where("status = ?", status).Delete()
|
||||
}
|
||||
|
||||
for _, report := range resolved_reports {
|
||||
_, err := db.GetEngine(ctx).ID(report.ID).Delete(&moderation.AbuseReport{})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
log.Trace("Finished: RemoveResolvedReports")
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue