From 3e2f8f8ef99f654047d86ea75da166e270b85ba9 Mon Sep 17 00:00:00 2001 From: snufkin Date: Wed, 31 Jul 2024 15:54:23 +0000 Subject: [PATCH] Add reports to user page when viewed by staff --- app/Manager/Report.php | 13 ++++++++ public/static/functions/reports.js | 12 +++++++ sass/global.scss | 11 +++++++ sections/user/user.php | 12 ++++++- templates/admin/user-reports-list.twig | 43 +++++++++++++++++++++++++ tests/phpunit/render/RenderUserTest.php | 16 +++++++++ 6 files changed, 106 insertions(+), 1 deletion(-) create mode 100644 templates/admin/user-reports-list.twig diff --git a/app/Manager/Report.php b/app/Manager/Report.php index 7bb135436..f293d7ab1 100644 --- a/app/Manager/Report.php +++ b/app/Manager/Report.php @@ -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, diff --git a/public/static/functions/reports.js b/public/static/functions/reports.js index 3e7a5d917..a467c6338 100644 --- a/public/static/functions/reports.js +++ b/public/static/functions/reports.js @@ -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"; + } + }); +}); diff --git a/sass/global.scss b/sass/global.scss index b9a4d6f3c..17a79d8ed 100644 --- a/sass/global.scss +++ b/sass/global.scss @@ -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%; diff --git a/sections/user/user.php b/sections/user/user.php index d43395975..cfc0fc3c8 100644 --- a/sections/user/user.php +++ b/sections/user/user.php @@ -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', [ @@ -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(); diff --git a/templates/admin/user-reports-list.twig b/templates/admin/user-reports-list.twig new file mode 100644 index 000000000..7f7f2460c --- /dev/null +++ b/templates/admin/user-reports-list.twig @@ -0,0 +1,43 @@ +
+
+ User Reports  + {{- dom.click('#toggle-user-reports', "$('#user-reports').gtoggle(); return false;") -}} + Toggle +
+ + {%- for report in list -%} + + + + + + + {% endfor %} +
+ {{ report.created|time_diff(1) }} + + {%- if report.status == "Resolved" -%} + + {%- endif -%} + {{-report.reason-}} + {%- if report.status == "Resolved" -%} + + {%- endif -%} + + {%- if report.status == "New" -%} + + {%- endif -%} + {{- report.status -}} + {%- if report.status == "New" -%} + + {%- endif -%} + + {%- if report.resolver -%} + {{- report.resolver.id|user_url -}} + {%- elseif report.claimer -%} + {{- report.claimer.id|user_url -}} + {%- else -%} + unclaimed + {%- endif -%} +
+
diff --git a/tests/phpunit/render/RenderUserTest.php b/tests/phpunit/render/RenderUserTest.php index f9bcfd093..5d1f93bdb 100644 --- a/tests/phpunit/render/RenderUserTest.php +++ b/tests/phpunit/render/RenderUserTest.php @@ -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 { @@ -72,5 +76,17 @@ public function testProfile(): void { $this->assertStringContainsString('
', $stats, 'user-header-stats-header'); $this->assertStringContainsString('
  • ', $stats, 'user-header-stats-id-collages'); $this->assertStringNotContainsString('
  • ', $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('
    ', $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'); } }