Skip to content

Commit

Permalink
Add reports to user page when viewed by staff
Browse files Browse the repository at this point in the history
  • Loading branch information
snufkin authored and Spine committed Aug 2, 2024
1 parent 705fdf1 commit 3e2f8f8
Show file tree
Hide file tree
Showing 6 changed files with 106 additions and 1 deletion.
13 changes: 13 additions & 0 deletions app/Manager/Report.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,19 @@ public function findById(int $reportId): ?\Gazelle\Report {
return (new \Gazelle\Report($id))->setUserManager($this->userMan);
}

public function findByReportedUser(\Gazelle\User $user): array {
self::$db->prepared_query("
SELECT ID
FROM reports
WHERE Type = 'user'
AND ThingID = ?
ORDER BY ID DESC
", $user->id()
);
$reportList = self::$db->collect(0, false);
return array_map(fn($id) => $this->findById($id), $reportList);
}

public function decorate(
array $idList,
\Gazelle\Manager\Collage $collageMan,
Expand Down
12 changes: 12 additions & 0 deletions public/static/functions/reports.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,15 @@ function resolve(id, claimer) {
}
return false;
}

document.addEventListener('DOMContentLoaded', () => {
let reports = document.querySelectorAll(".user-report-reason");
reports.forEach((report) => {
if (report.scrollWidth > report.offsetWidth) {
report.addEventListener('click', () => {
report.classList.toggle('user-report-truncate');
});
report.title = "Click to expand";
}
});
});
11 changes: 11 additions & 0 deletions sass/global.scss
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,17 @@ tr.torrent .bookmark > a::after {
.reportinfo_table {
table-layout: fixed;
}

.user-reports {
table-layout: fixed;
}

.user-report-truncate {
text-overflow: ellipsis;
overflow: hidden;
white-space: nowrap;
}

/* Wrap release info for consistent DOM and to limit table expansion. */
.no_overflow {
width: 100%;
Expand Down
12 changes: 11 additions & 1 deletion sections/user/user.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ function check_paranoia_here(?string $Setting): int|false {

View::show_header($Username, [
'js' => 'jquery.imagesloaded,jquery.wookmark,user,bbcode,requests,lastfm,comments,info_paster'
. ($Viewer->permitted('users_view_ips') ? ',resolve-ip' : ''),
. ($Viewer->permitted('users_view_ips') ? ',resolve-ip' : '')
. ($Viewer->permitted('users_mod') ? ',reports' : ''),
'css' => 'tiles'
]);
echo $Twig->render('user/header.twig', [
Expand Down Expand Up @@ -381,6 +382,15 @@ function check_paranoia_here(?string $Setting): int|false {
]);
}

if ($Viewer->permitted('users_mod')) {
$reports = (new Gazelle\Manager\Report($userMan))->findByReportedUser($User);
if ($reports) {
echo $Twig->render('admin/user-reports-list.twig', [
'list' => $reports
]);
}
}

// Displays a table of forum warnings viewable only to Forum Moderators
if ($Viewer->permitted('users_warn')) {
$ForumWarnings = $User->forumWarning();
Expand Down
43 changes: 43 additions & 0 deletions templates/admin/user-reports-list.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<div class="box" id="user-reports-box">
<div class="head">
User Reports&nbsp;
{{- dom.click('#toggle-user-reports', "$('#user-reports').gtoggle(); return false;") -}}
<a href="#" id="toggle-user-reports" class="brackets">Toggle</a>
</div>
<table width="100%" id="user-reports" class="user-reports">
{%- for report in list -%}
<tr>
<td width="15%" id="report-{{ report.id }}-created">
<a href='{{ report.location }}'>{{ report.created|time_diff(1) }}</a>
</td>
<td width="65%" id="report-{{ report.id }}-reason" class="user-report-reason user-report-truncate">
{%- if report.status == "Resolved" -%}
<s>
{%- endif -%}
{{-report.reason-}}
{%- if report.status == "Resolved" -%}
</s>
{%- endif -%}
</td>
<td width="10%" id="report-{{ report.id }}-status">
{%- if report.status == "New" -%}
<b>
{%- endif -%}
{{- report.status -}}
{%- if report.status == "New" -%}
</b>
{%- endif -%}
</td>
<td id="report-{{ report.id }}-staff">
{%- if report.resolver -%}
{{- report.resolver.id|user_url -}}
{%- elseif report.claimer -%}
{{- report.claimer.id|user_url -}}
{%- else -%}
unclaimed
{%- endif -%}
</td>
</tr>
{% endfor %}
</table>
</div>
16 changes: 16 additions & 0 deletions tests/phpunit/render/RenderUserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,15 @@

class RenderUserTest extends TestCase {
protected array $userList;
protected array $userReports;

public function tearDown(): void {
foreach ($this->userList as $user) {
$user->remove();
}
foreach ($this->userReports as $report) {
$report->remove();
}
}

public function testProfile(): void {
Expand Down Expand Up @@ -72,5 +76,17 @@ public function testProfile(): void {
$this->assertStringContainsString('<div class="box box_info box_userinfo_community">', $stats, 'user-header-stats-header');
$this->assertStringContainsString('<li id="comm_collstart">', $stats, 'user-header-stats-id-collages');
$this->assertStringNotContainsString('<li id="comm_downloaded">', $stats, 'user-header-stats-id-downloaded');

// Test reports displayed on profile
$reportMan = new Gazelle\Manager\Report(new \Gazelle\Manager\User());
$this->userReports[0] = $reportMan->create($this->userList['admin'], $this->userList['user']->id(), "user", randomString(6));
$this->userReports[1] = $reportMan->create($this->userList['admin'], $this->userList['user']->id(), "user", randomString(500));
$reports = Gazelle\Util\Twig::factory()->render('admin/user-reports-list.twig', [
'list' => $reportMan->findByReportedUser($this->userList['user'])
]);
$this->assertStringContainsString('<div class="box" id="user-reports-box">', $reports, 'user-reports-box');
$this->assertStringContainsString('-reason" class="user-report-reason user-report-truncate">', $reports, 'user-reports-reason');
$this->assertStringContainsString($this->userReports[0]->reason(), $reports, 'user-reports0-reason-text');
$this->assertStringContainsString($this->userReports[1]->reason(), $reports, 'user-reports1-reason-text');
}
}

0 comments on commit 3e2f8f8

Please sign in to comment.