forgejo/templates/admin/moderation/reports.tmpl
floss4good d5fa12ded1 feat: add admin moderation actions for abuse reports and for reported abusive content (#8716)
- Implementation of milestone 6. 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):
  `6. Forgejo admins can perform common actions on the listed reports (content deletion, locking of user account)`

---

Follow-up of !7905 (and !6977)

---

This adds some action buttons within the _Moderation reports_ section (/admin/moderation/reports) within the _Site administration_ page, so that administrators can:
- mark a report as Handled or as Ignored (without performing any action on the reported content);
- mark a user account as suspended (set `prohibit_login` = true);
- delete (and purge) a user / organization and mark the linked reports as Handled;
- delete a repository and mark the linked reports as Handled;
- delete an issue / pull request and mark the linked reports as Handled;
- delete a comment and mark the linked reports as Handled;

The buttons were added on the sight side of each report from the overview, below the existing counter (that show how many times the content was reported and opens the details page). Only the buttons for updating the status of the report are directly visible - as `✓` and `✗` icons with some tooltips - while the content actions are hidden under a `⋯` dropdown.
The implementation was done using HTMX so that the page is not refreshed after each action.

Some discussions regarding the UI/UX started with https://codeberg.org/forgejo/design/issues/30#issuecomment-5958634

### Manual testing
- First make sure that moderation in enabled ([moderation] ENABLED config is set as true within app.ini).
- Report multiple users, organizations, repositories, issues, pull requests and comments.
- Go to _Moderation reports_ overview section section and make sure the buttons are visible;
  - The `✓` and `✗` should be available for each shown report;
  - The horizontal dropdown menu (`⋯`) should not be visible for reports linked to already deleted content.
- The actions available within the dropdown menu should correspond to the reported content type (e.g. 'Suspend account' and 'Delete account' for users/organizations, 'Delete repository' for repositories, etc.).
- When an action is successful a flash message should be displayed above the overview.
- Warnings should be displayed (as flash messages) when trying to suspend or delete your account (in case someone reported you) or an organization.
- An info (flash message) should be displayed when trying to suspend a user that is already suspended.
- Mark a report as Handled / Ignored and observe that a success flash message confirms the action and the report is removed from the list without reloading the page;
  - Refresh the page to make sure the report will not be loaded again (also check in the DB that the status was updated and the resolved timestamp is correctly set).
- Suspend a user account and make sure the report remains in the list (it is not resolved);
  - Make sure the above user gets the 'Suspended account' notice after login.
- Delete a user account and observe that a success flash message confirms the action and the report is removed from the list without reloading the page;
  - Make sure that all owned organizations and repositories as well as all the issues, PRs and comments posted in other repositories were deleted;
  - Make sure the linked abuse reports are marked as Handled (and resolved timestamp is set).
- Delete an organization and make sure that owned repositories were also deleted.
- Similarly, delete a repository / issue / PR / comment and check that the contents are not available any more and the linked reports are resolved.

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/8716
Reviewed-by: Gusted <gusted@noreply.codeberg.org>
Co-authored-by: floss4good <floss4good@disroot.org>
Co-committed-by: floss4good <floss4good@disroot.org>
2025-12-03 20:07:32 +01:00

124 lines
5.2 KiB
Go HTML Template

{{template "admin/layout_head" (dict "ctxData" . "pageClass" "admin")}}
<div class="admin-setting-content">
<h4 class="ui top attached header">
{{ctx.Locale.Tr "admin.moderation.reports"}}
</h4>
<div class="ui attached segment">
{{if .Reports}}
<div class="flex-list">
<div class="flex-item tw-items-center">
<div class="flex-item-leading">
<span class="inline">Type</span>
</div>
<div class="flex-item-main">
<span class="inline">Summary</span>
</div>
<div class="flex-item-trailing">
<span>{{ctx.Locale.Tr "admin.moderation.reports"}}</span>
</div>
</div>
{{range .Reports}}
{{$reportDivID := print "report-" .ID}}
{{$reportDivSelector := print "#" $reportDivID}}
<div class="flex-item report" id="{{$reportDivID}}">
<div class="flex-item-leading">
{{svg .ContentTypeIconName 24}}
</div>
<div class="flex-item-main">
<div class="flex-item-title">
{{if .ContentReference}}
<a href="{{AppSubUrl}}/{{.ContentURL}}">{{.ContentReference}}</a>
{{else}}
<em>{{ctx.Locale.Tr "admin.moderation.deleted_content_ref" .ContentType .ContentID}}</em>
{{end}}
</div>
<div class="flex-items-inline">
<span class="item tw-mr-2">
{{svg "octicon-calendar"}}
{{DateUtils.TimeSince .CreatedUnix}}
</span>
<span class="item tw-mr-2">
{{svg "octicon-report"}}
{{if .ReporterName}}<a href="{{AppSubUrl}}/{{.ReporterName}}">{{.ReporterName}}</a>{{else}}{{$.GhostUserName}}{{end}}
</span>
<span class="item ui label">
{{svg "octicon-tag" 12}}
{{ctx.Locale.Tr (index $.AbuseCategories .Category)}}
</span>
</div>
<div class="flex-item-body">
<span class="text truncate">{{ctx.Locale.Tr "moderation.report_remarks"}}: <em>{{.Remarks}}</em></span>
</div>
</div>
{{$postURL := print AppSubUrl "/admin/abuse_reports/act"}}
<div class="flex-item-trailing">
<div class="flex-item-main tw-max-w-12 sm:tw-max-w-40">
<a class="flex-item-trailing tw-p-1" href="{{AppSubUrl}}/admin/moderation/reports/type/{{.ContentType}}/id/{{.ContentID}}">
<span class="tw-text-16 tw-font-semibold">{{.ReportedTimes}}</span>{{svg "octicon-report" "tw-ml-2"}}
</a>
<div class="button-sequence right tw-items-center"
hx-target="{{$reportDivSelector}}" hx-indicator="{{$reportDivSelector}}"
hx-vals='{"content_type": {{.ContentType}}, "content_id": {{.ContentID}}}'>
<button class="item tw-p-1 ui button" data-tooltip-content="{{ctx.Locale.Tr "moderation.report.mark_as_handled"}}"
hx-post="{{$postURL}}" hx-vals='{"report_action": {{$.MarkAsHandled}}}'>
{{svg "octicon-check"}}
</button>
<button class="item tw-p-1 ui button" data-tooltip-content="{{ctx.Locale.Tr "moderation.report.mark_as_ignored"}}"
hx-post="{{$postURL}}" hx-vals='{"report_action": {{$.MarkAsIgnored}}}'>
{{svg "octicon-x"}}
</button>
{{if .ContentReference}} {{/* the reference is missing when the content was already deleted */}}
<details class="item dropdown dir-rtl">
<summary class="tw-p-1" data-tooltip-content="{{ctx.Locale.Tr "profile.actions.tooltip"}}">{{svg "octicon-kebab-horizontal"}}</summary>
<ul
hx-target="{{$reportDivSelector}}" hx-indicator="{{$reportDivSelector}}"
hx-vals='{"content_type": {{.ContentType}}, "content_id": {{.ContentID}}}'>
{{if .ReportedContentIsUser}}
<li>
<a hx-post="{{$postURL}}" hx-vals='{"content_action": {{$.ActionSuspendAccount}}}' hx-swap="none" class="item">
{{svg "octicon-x"}}{{ctx.Locale.Tr "moderation.action.account.suspend"}}
</a>
</li>
<li>
<a hx-post="{{$postURL}}" hx-vals='{"content_action": {{$.ActionDeleteAccount}}, "report_action": {{$.MarkAsHandled}}}' class="item">
{{svg "octicon-trash"}}{{ctx.Locale.Tr "moderation.action.account.delete"}}
</a>
</li>
{{else if .ReportedContentIsRepo}}
<li>
<a hx-post="{{$postURL}}" hx-vals='{"content_action": {{$.ActionDeleteRepo}}, "report_action": {{$.MarkAsHandled}}}' class="item">
{{svg "octicon-trash"}}{{ctx.Locale.Tr "moderation.action.repo.delete"}}
</a>
</li>
{{else if .ReportedContentIsIssue}}
<li>
<a hx-post="{{$postURL}}" hx-vals='{"content_action": {{$.ActionDeleteIssue}}, "report_action": {{$.MarkAsHandled}}}' class="item">
{{svg "octicon-trash"}}{{ctx.Locale.Tr "moderation.action.issue.delete"}}
</a>
</li>
{{else if .ReportedContentIsComment}}
<li>
<a hx-post="{{$postURL}}" hx-vals='{"content_action": {{$.ActionDeleteComment}}, "report_action": {{$.MarkAsHandled}}}' class="item">
{{svg "octicon-trash"}}{{ctx.Locale.Tr "moderation.action.comment.delete"}}
</a>
</li>
{{end}}
</ul>
</details>
{{end}}
</div>
</div>
</div>
</div>
{{end}}
</div>
{{else}}
<p class="tw-text-center">{{ctx.Locale.Tr "admin.moderation.no_open_reports"}}</p>
{{end}}
</div>
</div>
{{template "admin/layout_footer" .}}