From a7a9ed1c0478119bbbc98211799b0d079bfefb5d Mon Sep 17 00:00:00 2001 From: Leni Kadali Date: Tue, 1 Apr 2025 16:20:42 +0300 Subject: [PATCH] Initial commit for combining multiple reports Initial commit for combining multiple reports of content in the database. Handles when a different user is reporting content that has already been reported and has a shadow copy made --- models/moderation/abuse_report.go | 10 ++++++++++ options/locale_next/locale_en-US.json | 1 + routers/web/moderation/report.go | 6 ++++++ services/moderation/reporting.go | 4 ++-- 4 files changed, 19 insertions(+), 2 deletions(-) diff --git a/models/moderation/abuse_report.go b/models/moderation/abuse_report.go index 0a4edb10e8..c8b0356a8f 100644 --- a/models/moderation/abuse_report.go +++ b/models/moderation/abuse_report.go @@ -134,6 +134,16 @@ func AlreadyReportedByAndOpen(ctx context.Context, doerID int64, contentType Rep return reported } +// AlreadyReported returns if the content with contentID and contentType has already been reported and the report is still open. +func AlreadyReported(ctx context.Context, contentType ReportedContentType, contentID int64) bool { + reported, _ := db.GetEngine(ctx).Exist(&AbuseReport{ + Status: ReportStatusTypeOpen, + ContentType: contentType, + ContentID: contentID, + }) + return reported +} + func ReportAbuse(ctx context.Context, report *AbuseReport) error { if report.ContentType == ReportedContentTypeUser && report.ReporterID == report.ContentID { return ErrSelfReporting diff --git a/options/locale_next/locale_en-US.json b/options/locale_next/locale_en-US.json index b8e26cde0e..5dbb354513 100644 --- a/options/locale_next/locale_en-US.json +++ b/options/locale_next/locale_en-US.json @@ -33,6 +33,7 @@ "moderation.report_remarks": "Remarks", "moderation.report_remarks.placeholder": "Please provide some details regarding the abuse you are reporting.", "moderation.submit_report": "Submit report", + "moderation.reported_already": "This has already been reported.", "moderation.reporting_failed": "Something went wrong while trying to submit the new abuse report: %v", "moderation.reported_thank_you": "Thank you for your report. An administrator will look into it shortly." } diff --git a/routers/web/moderation/report.go b/routers/web/moderation/report.go index 39ca9e8824..045ce00ff1 100644 --- a/routers/web/moderation/report.go +++ b/routers/web/moderation/report.go @@ -54,6 +54,12 @@ func NewReport(ctx *context.Context) { return } + if moderation.AlreadyReported(ctx, contentType, contentID) { + setMinimalContextData(ctx) + ctx.RenderWithErr(ctx.Tr("moderation.reported_already"), tplSubmitAbuseReport, nil) + return + } + setContextDataAndRender(ctx, contentType, contentID) } diff --git a/services/moderation/reporting.go b/services/moderation/reporting.go index 6159f04cfc..34758988c2 100644 --- a/services/moderation/reporting.go +++ b/services/moderation/reporting.go @@ -29,10 +29,10 @@ var ( // to 'TypeIssues', respectively 'TypePullRequests' unit for the repository where the content belongs. // When reporting users or organizations doer should be able to view the reported entity. func CanReport(ctx context.Context, doer *user.User, contentType moderation.ReportedContentType, contentID int64) (bool, error) { - var hasAccess bool = false + hasAccess := false var issueID int64 = 0 var repoID int64 = 0 - var unitType unit.Type = unit.TypeInvalid // used when checking access for issues, pull requests or comments + unitType := unit.TypeInvalid // used when checking access for issues, pull requests or comments if contentType == moderation.ReportedContentTypeUser { reported_user, err := user.GetUserByID(ctx, contentID)