mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2026-05-12 22:10:25 +00:00
fix: make sure the details page is still rendered correctly even if the poster of reported comment was deleted (#10199)
When opening the report details page of a reported comment who's poster was meanwhile deleted, the title was wrongly saying that _Reported content with type 4 and id ... no longer exists_ (on the overview page the title was correctly showing the content reference). This PR fixes the issue and adds some tests for this case. Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/10199 Reviewed-by: Gusted <gusted@noreply.codeberg.org> Co-authored-by: floss4good <floss4good@disroot.org> Co-committed-by: floss4good <floss4good@disroot.org>
This commit is contained in:
parent
de3f376882
commit
a93fa287f4
5 changed files with 38 additions and 4 deletions
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
-
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue