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
This commit is contained in:
Leni Kadali 2025-04-01 16:20:42 +03:00
parent b5103315ab
commit a7a9ed1c04
4 changed files with 19 additions and 2 deletions

View file

@ -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

View file

@ -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."
}

View file

@ -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)
}

View file

@ -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)