mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-08-19 17:01:12 +00:00
- Implementation of milestone 5. from **Task F. Moderation features: Reporting** (part of [amendment of the workplan](https://codeberg.org/forgejo/sustainability/src/branch/main/2022-12-01-nlnet/2025-02-07-extended-workplan.md#task-f-moderation-features-reporting) for NLnet 2022-12-035): `5. Forgejo admins can see a list of reports` There is a lot of room for improvements, but it was decided to start with a basic version so that feedback can be collected from real-life usages (based on which the UI might change a lot). - Also covers milestone 2. from same **Task F. Moderation features: Reporting**: `2. Reports from multiple users are combined in the database and don't create additional reports.` But instead of combining the reports when stored, they are grouped when retrieved (it was concluded _that it might be preferable to take care of the deduplication while implementing the admin interface_; see https://codeberg.org/forgejo/forgejo/pulls/7939#issuecomment-4841754 for more details). --- Follow-up of !6977 ### See also: - forgejo/design#30 --- This adds a new _Moderation reports_ section (/admin/moderation/reports) within the _Site administration_ page, where administrators can see an overview with the submitted abuse reports that are still open (not yet handled in any way). When multiple reports exist for the same content (submitted by distinct users) only the first one will be shown in the list and a counter can be seen on the right side (indicating the number of open reports for the same content type and ID). Clicking on the counter or the icon from the right side will open the details page where a list with all the reports (when multiple) linked to the reported content is available, as well as any shadow copy saved for the current report(s). The new section is available only when moderation in enabled ([moderation] ENABLED config is set as true within app.ini). Discussions regarding the UI/UX started with https://codeberg.org/forgejo/design/issues/30#issuecomment-2908849 Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/7905 Reviewed-by: Otto <otto@codeberg.org> Reviewed-by: jerger <jerger@noreply.codeberg.org> Co-authored-by: floss4good <floss4good@disroot.org> Co-committed-by: floss4good <floss4good@disroot.org>
157 lines
4.5 KiB
Go
157 lines
4.5 KiB
Go
// Copyright 2025 The Forgejo Authors. All rights reserved.
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
package admin
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
|
|
"forgejo.org/models/issues"
|
|
"forgejo.org/models/moderation"
|
|
repo_model "forgejo.org/models/repo"
|
|
"forgejo.org/models/user"
|
|
"forgejo.org/modules/base"
|
|
"forgejo.org/services/context"
|
|
moderation_service "forgejo.org/services/moderation"
|
|
)
|
|
|
|
const (
|
|
tplModerationReports base.TplName = "admin/moderation/reports"
|
|
tplModerationReportDetails base.TplName = "admin/moderation/report_details"
|
|
)
|
|
|
|
// AbuseReports renders the reports overview page from admin moderation section.
|
|
func AbuseReports(ctx *context.Context) {
|
|
ctx.Data["Title"] = ctx.Tr("admin.moderation.reports")
|
|
ctx.Data["PageIsAdminModerationReports"] = true
|
|
|
|
reports, err := moderation.GetOpenReports(ctx)
|
|
if err != nil {
|
|
ctx.ServerError("Failed to load abuse reports", err)
|
|
return
|
|
}
|
|
|
|
ctx.Data["Reports"] = reports
|
|
ctx.Data["AbuseCategories"] = moderation.AbuseCategoriesTranslationKeys
|
|
ctx.Data["GhostUserName"] = user.GhostUserName
|
|
|
|
ctx.HTML(http.StatusOK, tplModerationReports)
|
|
}
|
|
|
|
// AbuseReportDetails renders a report details page opened from the reports overview from admin moderation section.
|
|
func AbuseReportDetails(ctx *context.Context) {
|
|
ctx.Data["Title"] = ctx.Tr("admin.moderation.reports")
|
|
ctx.Data["PageIsAdminModerationReports"] = true
|
|
|
|
ctx.Data["Type"] = ctx.ParamsInt64(":type")
|
|
ctx.Data["ID"] = ctx.ParamsInt64(":id")
|
|
|
|
contentType := moderation.ReportedContentType(ctx.ParamsInt64(":type"))
|
|
|
|
if !contentType.IsValid() {
|
|
ctx.Flash.Error("Invalid content type")
|
|
return
|
|
}
|
|
|
|
reports, err := moderation.GetOpenReportsByTypeAndContentID(ctx, contentType, ctx.ParamsInt64(":id"))
|
|
if err != nil {
|
|
ctx.ServerError("Failed to load reports", err)
|
|
return
|
|
}
|
|
if len(reports) == 0 {
|
|
// something is wrong
|
|
ctx.HTML(http.StatusOK, tplModerationReportDetails)
|
|
return
|
|
}
|
|
|
|
ctx.Data["Reports"] = reports
|
|
ctx.Data["AbuseCategories"] = moderation.AbuseCategoriesTranslationKeys
|
|
ctx.Data["GhostUserName"] = user.GhostUserName
|
|
|
|
ctx.Data["GetShadowCopyMap"] = moderation_service.GetShadowCopyMap
|
|
|
|
if err = setReportedContentDetails(ctx, reports[0]); err != nil {
|
|
if user.IsErrUserNotExist(err) || issues.IsErrCommentNotExist(err) || issues.IsErrIssueNotExist(err) || repo_model.IsErrRepoNotExist(err) {
|
|
ctx.Data["ContentReference"] = ctx.Tr("admin.moderation.deleted_content_ref", reports[0].ContentType, reports[0].ContentID)
|
|
} else {
|
|
ctx.ServerError("Failed to load reported content details", err)
|
|
return
|
|
}
|
|
}
|
|
|
|
ctx.HTML(http.StatusOK, tplModerationReportDetails)
|
|
}
|
|
|
|
// setReportedContentDetails adds some values into context data for the given report
|
|
// (icon name, a reference, the URL and in case of issues and comments also the poster name).
|
|
func setReportedContentDetails(ctx *context.Context, report *moderation.AbuseReportDetailed) error {
|
|
contentReference := ""
|
|
var contentURL string
|
|
var poster string
|
|
contentType := report.ContentType
|
|
contentID := report.ContentID
|
|
|
|
ctx.Data["ContentTypeIconName"] = report.ContentTypeIconName()
|
|
|
|
switch contentType {
|
|
case moderation.ReportedContentTypeUser:
|
|
reportedUser, err := user.GetUserByID(ctx, contentID)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
contentReference = reportedUser.Name
|
|
contentURL = reportedUser.HomeLink()
|
|
case moderation.ReportedContentTypeRepository:
|
|
repo, err := repo_model.GetRepositoryByID(ctx, contentID)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
contentReference = repo.FullName()
|
|
contentURL = repo.Link()
|
|
case moderation.ReportedContentTypeIssue:
|
|
issue, err := issues.GetIssueByID(ctx, contentID)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if err = issue.LoadRepo(ctx); err != nil {
|
|
return err
|
|
}
|
|
if err = issue.LoadPoster(ctx); err != nil {
|
|
return err
|
|
}
|
|
if issue.Poster != nil {
|
|
poster = issue.Poster.Name
|
|
}
|
|
|
|
contentReference = fmt.Sprintf("%s#%d", issue.Repo.FullName(), issue.Index)
|
|
contentURL = issue.Link()
|
|
case moderation.ReportedContentTypeComment:
|
|
comment, err := issues.GetCommentByID(ctx, contentID)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if err = comment.LoadIssue(ctx); err != nil {
|
|
return err
|
|
}
|
|
if err = comment.Issue.LoadRepo(ctx); err != nil {
|
|
return err
|
|
}
|
|
if err = comment.LoadPoster(ctx); err != nil {
|
|
return err
|
|
}
|
|
if comment.Poster != nil {
|
|
poster = comment.Poster.Name
|
|
}
|
|
|
|
contentURL = comment.Link(ctx)
|
|
contentReference = contentURL
|
|
}
|
|
|
|
ctx.Data["ContentReference"] = contentReference
|
|
ctx.Data["ContentURL"] = contentURL
|
|
ctx.Data["Poster"] = poster
|
|
return nil
|
|
}
|