diff --git a/routers/web/admin/reports.go b/routers/web/admin/reports.go index ac43d1296f..2df66a3803 100644 --- a/routers/web/admin/reports.go +++ b/routers/web/admin/reports.go @@ -139,7 +139,7 @@ func setReportedContentDetails(ctx *context.Context, report *moderation.AbuseRep if err = comment.Issue.LoadRepo(ctx); err != nil { return err } - if err = comment.LoadPoster(ctx); err != nil { + if err = comment.LoadPoster(ctx); err != nil && !user.IsErrUserNotExist(err) { return err } if comment.Poster != nil { diff --git a/tests/integration/admin_moderation_test.go b/tests/integration/admin_moderation_test.go index de0daebe86..da7beeaabe 100644 --- a/tests/integration/admin_moderation_test.go +++ b/tests/integration/admin_moderation_test.go @@ -87,9 +87,9 @@ func TestAdminModerationViewReports(t *testing.T) { htmlDoc := NewHTMLParser(t, resp.Body) // Check how many reports are being displayed. - // Reports linked to the same content (type and id) should be grouped; therefore we should see only 6 instead of 9. + // Reports linked to the same content (type and id) should be grouped; therefore we should see only 8 instead of 11. reports := htmlDoc.Find(".admin-setting-content .flex-list .flex-item.report") - assert.Equal(t, 7, reports.Length()) + assert.Equal(t, 8, reports.Length()) // Check details for shown reports. testReportDetails(t, htmlDoc, "1", "octicon-person", "@SPAM-services", "/SPAM-services", "Illegal content", "1") @@ -102,6 +102,8 @@ func TestAdminModerationViewReports(t *testing.T) { testReportDetails(t, htmlDoc, "8", "octicon-issue-opened", "contributor/first#1", "/contributor/first/issues/1", "Other violations of platform rules", "1") // #10 is for a Ghost user testReportDetails(t, htmlDoc, "10", "octicon-person", "Reported content with type 1 and id 9999 no longer exists", "", "Other violations of platform rules", "1") + // #11 if for a comment who's poster was deleted + testReportDetails(t, htmlDoc, "11", "octicon-comment", "contributor/first/issues/1#issuecomment-1003", "/contributor/first/issues/1#issuecomment-1003", "Spam", "1") t.Run("reports details page", func(t *testing.T) { defer tests.PrintCurrentTest(t)() @@ -121,6 +123,19 @@ func TestAdminModerationViewReports(t *testing.T) { // Check how many reports are being displayed for user 1002. reports = htmlDoc.Find(".admin-setting-content .flex-list .flex-item") assert.Equal(t, 3, reports.Length()) + + // Poster of comment 1003 was deleted; make sure the details page is still rendered correctly. + req = NewRequest(t, "GET", "/admin/moderation/reports/type/4/id/1003") + resp = session.MakeRequest(t, req, http.StatusOK) + htmlDoc = NewHTMLParser(t, resp.Body) + + // Check the title (content reference) and corresponding URL. + title = htmlDoc.Find(".admin-setting-content .flex-item-main .flex-item-title a") + assert.Equal(t, 1, title.Length()) + assert.Equal(t, "/contributor/first/issues/1#issuecomment-1003", title.Text()) + href, exists = title.Attr("href") + assert.True(t, exists) + assert.Equal(t, "/contributor/first/issues/1#issuecomment-1003", href) }) }) }) diff --git a/tests/integration/fixtures/TestAdminModerationViewReports/abuse_report.yml b/tests/integration/fixtures/TestAdminModerationViewReports/abuse_report.yml index 8bc3c0834b..14d7b76155 100644 --- a/tests/integration/fixtures/TestAdminModerationViewReports/abuse_report.yml +++ b/tests/integration/fixtures/TestAdminModerationViewReports/abuse_report.yml @@ -109,3 +109,14 @@ remarks: Check this spammer as soon as possible, before they delete their account. shadow_copy_id: null created_unix: 1121424150 # 2005-07-15 10:42:30 + +- + id: 11 + status: 1 + reporter_id: 1001 # @contributor + content_type: 4 # Comment + content_id: 1003 # contributor/first/issues/1#issuecomment-1003 + category: 2 # Spam + remarks: This user just posted a spammy comment on my issue. + shadow_copy_id: null + created_unix: 1752697820 # 2025-07-16 20:30:20 diff --git a/tests/integration/fixtures/TestAdminModerationViewReports/comment.yml b/tests/integration/fixtures/TestAdminModerationViewReports/comment.yml index a7ee83d53e..0998f58fd4 100644 --- a/tests/integration/fixtures/TestAdminModerationViewReports/comment.yml +++ b/tests/integration/fixtures/TestAdminModerationViewReports/comment.yml @@ -19,3 +19,11 @@ ref_comment_id: 1001 ref_action: 0 ref_is_pull: false + +- + id: 1003 + type: 0 # Standard comment + poster_id: 9999 # Ghost user + issue_id: 1001 # contributor/first#1 + content: Check my [website](https://test.net) for the best deals. + created_unix: 1752697810 # 2025-07-16 20:30:10 diff --git a/tests/integration/fixtures/TestAdminModerationViewReports/issue.yml b/tests/integration/fixtures/TestAdminModerationViewReports/issue.yml index 74af88b3b6..507b7b156f 100644 --- a/tests/integration/fixtures/TestAdminModerationViewReports/issue.yml +++ b/tests/integration/fixtures/TestAdminModerationViewReports/issue.yml @@ -7,7 +7,7 @@ content: so here we go is_closed: false is_pull: false - num_comments: 1 + num_comments: 2 created_unix: 1121422320 # 2005-07-15 10:12:00 -