Skip to content

Commit 3cf7dc4

Browse files
committed
draft of admin page
1 parent 8ca4c95 commit 3cf7dc4

File tree

6 files changed

+122
-0
lines changed

6 files changed

+122
-0
lines changed

models/user/spam_report.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
package user
55

66
import (
7+
"context"
8+
"fmt"
9+
710
"code.gitea.io/gitea/models/db"
811
"code.gitea.io/gitea/modules/timeutil"
912
)
@@ -32,3 +35,27 @@ func (*SpamReport) TableName() string {
3235
func init() {
3336
db.RegisterModel(new(SpamReport))
3437
}
38+
39+
type ListSpamReportResults struct {
40+
ID int64
41+
Status int
42+
UserName string
43+
ReporterName string
44+
}
45+
46+
func ListSpamReports(ctx context.Context, opts *db.ListOptions) ([]*ListSpamReportResults, int64, error) {
47+
opts.SetDefaultValues()
48+
count, err := db.GetEngine(ctx).Count(new(SpamReport))
49+
if err != nil {
50+
return nil, 0, fmt.Errorf("Count: %w", err)
51+
}
52+
spamReports := make([]*ListSpamReportResults, 0, opts.PageSize)
53+
err = db.GetEngine(ctx).Table("user_spamreport").
54+
Select("user_spamreport.id, user_spamreport.status, user.name as user_name, reporter.name as reporter_name").
55+
Join("LEFT", "`user`", "`user`.id = user_spamreport.user_id").
56+
Join("LEFT", "`user` as reporter", "`reporter`.id = user_spamreport.reporter_id").
57+
Limit(opts.PageSize, (opts.Page-1)*opts.PageSize).
58+
Find(&spamReports)
59+
60+
return spamReports, count, err
61+
}

options/locale/locale_en-US.ini

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2894,6 +2894,7 @@ first_page = First
28942894
last_page = Last
28952895
total = Total: %d
28962896
settings = Admin Settings
2897+
spamreports = Spam Reports
28972898
28982899
dashboard.new_version_hint = Gitea %s is now available, you are running %s. Check <a target="_blank" rel="noreferrer" href="%s">the blog</a> for more details.
28992900
dashboard.statistic = Summary
@@ -3057,6 +3058,11 @@ emails.delete_desc = Are you sure you want to delete this email address?
30573058
emails.deletion_success = The email address has been deleted.
30583059
emails.delete_primary_email_error = You can not delete the primary email.
30593060
3061+
spamreports.spamreport_manage_panel = Spam Report Management
3062+
spamreports.user = Reported for spam
3063+
spamreports.reporter = Reporter
3064+
spamreports.status = Report Status
3065+
30603066
orgs.org_manage_panel = Organization Management
30613067
orgs.name = Name
30623068
orgs.teams = Teams

routers/web/admin/spamreports.go

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// Copyright 2025 The Gitea Authors.
2+
// SPDX-License-Identifier: MIT
3+
4+
package admin
5+
6+
import (
7+
"net/http"
8+
9+
"code.gitea.io/gitea/models/db"
10+
user_model "code.gitea.io/gitea/models/user"
11+
"code.gitea.io/gitea/modules/base"
12+
"code.gitea.io/gitea/modules/setting"
13+
"code.gitea.io/gitea/services/context"
14+
)
15+
16+
const (
17+
tplSpamReports base.TplName = "admin/spamreports/list"
18+
)
19+
20+
// Emails show all emails
21+
func SpamReports(ctx *context.Context) {
22+
ctx.Data["Title"] = ctx.Tr("admin.spamreports")
23+
ctx.Data["PageIsSpamReports"] = true
24+
25+
opts := &db.ListOptions{
26+
PageSize: setting.UI.Admin.UserPagingNum,
27+
Page: ctx.FormInt("page"),
28+
}
29+
30+
if opts.Page <= 1 {
31+
opts.Page = 1
32+
}
33+
34+
var (
35+
count int64
36+
err error
37+
)
38+
spamReports, count, err := user_model.ListSpamReports(ctx, opts)
39+
if err != nil {
40+
ctx.ServerError("SpamReports", err)
41+
return
42+
}
43+
44+
ctx.Data["Total"] = count
45+
ctx.Data["SpamReports"] = spamReports
46+
47+
pager := context.NewPagination(int(count), opts.PageSize, opts.Page, 5)
48+
pager.SetDefaultParams(ctx)
49+
ctx.Data["Page"] = pager
50+
51+
ctx.HTML(http.StatusOK, tplSpamReports)
52+
}

routers/web/web.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -750,6 +750,10 @@ func registerRoutes(m *web.Router) {
750750
m.Post("/delete", admin.DeleteEmail)
751751
})
752752

753+
m.Group("/spamreports", func() {
754+
m.Get("", admin.SpamReports)
755+
})
756+
753757
m.Group("/orgs", func() {
754758
m.Get("", admin.Organizations)
755759
})

templates/admin/navbar.tmpl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@
2828
<a class="{{if .PageIsAdminEmails}}active {{end}}item" href="{{AppSubUrl}}/-/admin/emails">
2929
{{ctx.Locale.Tr "admin.emails"}}
3030
</a>
31+
<a class="{{if .PageIsSpamReports}}active {{end}}item" href="{{AppSubUrl}}/-/admin/spamreports">
32+
{{ctx.Locale.Tr "admin.spamreports"}}
33+
</a>
3134
</div>
3235
</details>
3336
<details class="item toggleable-item" {{if or .PageIsAdminRepositories (and .EnablePackages .PageIsAdminPackages)}}open{{end}}>
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{{template "admin/layout_head" (dict "ctxData" . "pageClass" "admin user")}}
2+
<div class="admin-setting-content">
3+
<h4 class="ui top attached header">
4+
{{ctx.Locale.Tr "admin.spamreports.spamreport_manage_panel"}} ({{ctx.Locale.Tr "admin.total" .Total}})
5+
</h4>
6+
<div class="ui attached table segment">
7+
<table class="ui very basic striped table unstackable">
8+
<thead>
9+
<tr>
10+
<th>{{ctx.Locale.Tr "admin.spamreports.user"}}</th>
11+
<th>{{ctx.Locale.Tr "admin.spamreports.reporter"}}</th>
12+
<th>{{ctx.Locale.Tr "admin.spamreports.status"}}</th>
13+
</tr>
14+
</thead>
15+
<tbody>
16+
{{range .SpamReports}}
17+
<tr>
18+
<td><a href="{{AppSubUrl}}/{{.UserName | PathEscape}}">{{.UserName}}</a></td>
19+
<td><a href="{{AppSubUrl}}/{{.ReporterName | PathEscape}}">{{.ReporterName}}</a></td>
20+
<td>{{.Status}}</td>
21+
</tr>
22+
{{end}}
23+
</tbody>
24+
</table>
25+
</div>
26+
27+
{{template "base/paginate" .}}
28+
</div>
29+
30+
{{template "admin/layout_footer" .}}

0 commit comments

Comments
 (0)