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.
|
;; 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
|
;ENABLED = false
|
||||||
|
|
||||||
;; Timeout for removing resolved reports
|
;; Time to keep resolved abuse reports.
|
||||||
;REMOVE_RESOLVED_REPORTS_TIMEOUT = 0
|
;KEEP_RESOLVED_REPORTS_FOR = 0
|
||||||
|
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
|
|
@ -8,6 +8,7 @@ import (
|
||||||
"database/sql"
|
"database/sql"
|
||||||
"errors"
|
"errors"
|
||||||
"slices"
|
"slices"
|
||||||
|
"time"
|
||||||
|
|
||||||
"forgejo.org/models/db"
|
"forgejo.org/models/db"
|
||||||
"forgejo.org/modules/log"
|
"forgejo.org/modules/log"
|
||||||
|
@ -154,6 +155,25 @@ func ReportAbuse(ctx context.Context, report *AbuseReport) error {
|
||||||
return err
|
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).
|
// 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 {
|
func MarkAsHandled(ctx context.Context, contentType ReportedContentType, contentID int64) error {
|
||||||
|
|
|
@ -229,18 +229,18 @@ func registerRebuildIssueIndexer() {
|
||||||
func registerRemoveResolvedReports() {
|
func registerRemoveResolvedReports() {
|
||||||
type ReportConfig struct {
|
type ReportConfig struct {
|
||||||
BaseConfig
|
BaseConfig
|
||||||
Timeout time.Duration
|
ConfiguredTimeOut time.Duration
|
||||||
}
|
}
|
||||||
RegisterTaskFatal("remove_resolved_reports", &ReportConfig{
|
RegisterTaskFatal("remove_resolved_reports", &ReportConfig{
|
||||||
BaseConfig: BaseConfig{
|
BaseConfig: BaseConfig{
|
||||||
Enabled: false,
|
Enabled: false,
|
||||||
RunAtStart: 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 {
|
}, func(ctx context.Context, _ *user_model.User, config Config) error {
|
||||||
reportConfig := config.(*ReportConfig)
|
reportConfig := config.(*ReportConfig)
|
||||||
return moderation_service.RemoveResolvedReports(ctx, reportConfig.Timeout)
|
return moderation_service.RemoveResolvedReports(ctx, reportConfig.ConfiguredTimeOut)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -259,5 +259,7 @@ func initExtendedTasks() {
|
||||||
registerDeleteOldSystemNotices()
|
registerDeleteOldSystemNotices()
|
||||||
registerGCLFS()
|
registerGCLFS()
|
||||||
registerRebuildIssueIndexer()
|
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 {
|
func RemoveResolvedReports(ctx context.Context, timeout time.Duration) error {
|
||||||
log.Trace("Doing: RemoveResolvedReports")
|
log.Trace("Doing: RemoveResolvedReports")
|
||||||
|
|
||||||
status := moderation.ReportStatusTypeHandled
|
resolved_reports, err := moderation.GetResolvedReports(ctx, timeout)
|
||||||
resolvedReports, err := db.GetEngine(ctx).Table("abuse_report").Where("status = ?", status).Exist()
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Trace("Finished: RemoveResolvedReports")
|
log.Trace("Finished: RemoveResolvedReports")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue