Skip to content

Commit 6a2c2be

Browse files
author
Oleg Komarov
committed
cron task process_spam_reports
1 parent 4cb00a8 commit 6a2c2be

File tree

5 files changed

+45
-0
lines changed

5 files changed

+45
-0
lines changed

models/user/spamreport.go

+7
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,13 @@ func ListSpamReports(ctx context.Context, opts *ListSpamReportsOptions) ([]*List
8989
return spamReports, count, err
9090
}
9191

92+
func GetPendingSpamReportIDs(ctx context.Context) ([]int64, error) {
93+
var ids []int64
94+
err := db.GetEngine(ctx).Table("user_spamreport").
95+
Select("id").Where("status = ?", SpamReportStatusTypePending).Find(&ids)
96+
return ids, err
97+
}
98+
9299
type SpamReportStatusCounts struct {
93100
Count int64
94101
Status SpamReportStatusType

options/locale/locale_en-US.ini

+1
Original file line numberDiff line numberDiff line change
@@ -2982,6 +2982,7 @@ dashboard.sync_branch.started = Branches Sync started
29822982
dashboard.sync_tag.started = Tags Sync started
29832983
dashboard.rebuild_issue_indexer = Rebuild issue indexer
29842984
dashboard.sync_repo_licenses = Sync repo licenses
2985+
dashboard.process_spam_reports = Process spam reports
29852986
29862987
users.user_manage_panel = User Account Management
29872988
users.new_account = Create User Account

routers/web/admin/spamreports.go

+3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
package admin
77

88
import (
9+
"fmt"
910
"net/http"
1011
"strconv"
1112

@@ -56,6 +57,8 @@ func SpamReports(ctx *context.Context) {
5657

5758
ctx.Data["Total"] = count
5859
ctx.Data["SpamReports"] = spamReports
60+
ids, _ := user_model.GetPendingSpamReportIDs(ctx)
61+
fmt.Printf("%v", ids)
5962

6063
pager := context.NewPagination(int(count), opts.PageSize, opts.Page, 5)
6164
pager.SetDefaultParams(ctx)

services/cron/cron.go

+2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ func NewContext(original context.Context) {
3131
initBasicTasks()
3232
initExtendedTasks()
3333
initActionsTasks()
34+
// BLENDER: spam reporting
35+
initSpamReportTasks()
3436

3537
lock.Lock()
3638
for _, task := range tasks {

services/cron/tasks_spamreport.go

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Copyright 2025 The Gitea Authors. All rights reserved.
2+
// SPDX-License-Identifier: MIT
3+
4+
// BLENDER: spam reporting
5+
6+
package cron
7+
8+
import (
9+
"context"
10+
"fmt"
11+
12+
user_model "code.gitea.io/gitea/models/user"
13+
user_service "code.gitea.io/gitea/services/user"
14+
)
15+
16+
func registerProcessSpamReports() {
17+
RegisterTaskFatal("process_spam_reports", &BaseConfig{
18+
Enabled: true,
19+
RunAtStart: true,
20+
Schedule: "@every 5m",
21+
}, func(ctx context.Context, doer *user_model.User, _ Config) error {
22+
ids, err := user_model.GetPendingSpamReportIDs(ctx)
23+
if err != nil {
24+
return fmt.Errorf("failed to GetPendingSpamReportIDs: %w", err)
25+
}
26+
return user_service.ProcessSpamReports(ctx, doer, ids)
27+
})
28+
}
29+
30+
func initSpamReportTasks() {
31+
registerProcessSpamReports()
32+
}

0 commit comments

Comments
 (0)