From 60a55934467f4d8277763f37180538d427bf8180 Mon Sep 17 00:00:00 2001 From: ghost Date: Fri, 13 Oct 2023 18:28:27 +0300 Subject: [PATCH] implement approved/sensitive access behavior --- src/Controller/ActivityController.php | 392 +++++++++++++++--- src/Controller/TorrentController.php | 68 ++- src/Controller/UserController.php | 4 + .../activity/event/torrent/add.html.twig | 21 +- .../event/torrent/approve/add.html.twig | 21 +- .../event/torrent/approve/delete.html.twig | 21 +- .../event/torrent/download/file/add.html.twig | 21 +- .../torrent/download/magnet/add.html.twig | 21 +- .../event/torrent/locales/add.html.twig | 21 +- .../torrent/locales/approve/add.html.twig | 21 +- .../torrent/locales/approve/delete.html.twig | 21 +- .../event/torrent/locales/delete.html.twig | 21 +- .../event/torrent/sensitive/add.html.twig | 21 +- .../torrent/sensitive/approve/add.html.twig | 21 +- .../sensitive/approve/delete.html.twig | 21 +- .../event/torrent/sensitive/delete.html.twig | 21 +- .../activity/event/torrent/star/add.html.twig | 21 +- .../event/torrent/star/delete.html.twig | 21 +- templates/default/activity/list.html.twig | 2 +- templates/default/torrent/info.html.twig | 2 +- templates/default/torrent/list.html.twig | 18 +- templates/default/user/info.html.twig | 2 +- 22 files changed, 681 insertions(+), 122 deletions(-) diff --git a/src/Controller/ActivityController.php b/src/Controller/ActivityController.php index c543492..038e1b8 100644 --- a/src/Controller/ActivityController.php +++ b/src/Controller/ActivityController.php @@ -43,6 +43,9 @@ class ActivityController extends AbstractController return $this->render( 'default/activity/list.html.twig', [ + 'session' => [ + 'user' => $user + ], 'activities' => $activityService->findLastActivities( // @TODO locale/sensitive filters $user->getEvents(), $this->getParameter('app.pagination'), @@ -59,7 +62,8 @@ class ActivityController extends AbstractController } public function event( - $activity, + \App\Entity\User $user, + \App\Entity\Activity $activity, ActivityService $activityService, UserService $userService, TorrentService $torrentService, @@ -347,6 +351,12 @@ class ActivityController extends AbstractController // Torrent case $activity::EVENT_TORRENT_ADD: + // Init torrent + if (!$torrent = $torrentService->getTorrent($activity->getTorrentId())) + { + throw $this->createNotFoundException(); + } + return $this->render( 'default/activity/event/torrent/add.html.twig', [ @@ -362,10 +372,22 @@ class ActivityController extends AbstractController ], 'torrent' => [ - 'id' => $activity->getTorrentId(), - 'name' => $torrentService->readTorrentFileByTorrentId( - $activity->getTorrentId() + 'id' => $torrent->getId(), + 'sensitive' => $torrent->isSensitive(), + 'approved' => $torrent->isApproved(), + 'name' => $torrentService->readTorrentFileByTorrentId( + $torrent->getId() )->getName() + ], + 'session' => + [ + 'user' => + [ + 'id' => $user->getId(), + 'sensitive' => $user->isSensitive(), + 'moderator' => $user->isModerator(), + 'owner' => $user->getId() === $torrent->getUserId(), + ] ] ] ); @@ -374,6 +396,12 @@ class ActivityController extends AbstractController case $activity::EVENT_TORRENT_APPROVE_ADD: + // Init torrent + if (!$torrent = $torrentService->getTorrent($activity->getTorrentId())) + { + throw $this->createNotFoundException(); + } + return $this->render( 'default/activity/event/torrent/approve/add.html.twig', [ @@ -389,10 +417,22 @@ class ActivityController extends AbstractController ], 'torrent' => [ - 'id' => $activity->getTorrentId(), - 'name' => $torrentService->readTorrentFileByTorrentId( - $activity->getTorrentId() + 'id' => $torrent->getId(), + 'sensitive' => $torrent->isSensitive(), + 'approved' => $torrent->isApproved(), + 'name' => $torrentService->readTorrentFileByTorrentId( + $torrent->getId() )->getName() + ], + 'session' => + [ + 'user' => + [ + 'id' => $user->getId(), + 'sensitive' => $user->isSensitive(), + 'moderator' => $user->isModerator(), + 'owner' => $user->getId() === $torrent->getUserId(), + ] ] ] ); @@ -401,6 +441,12 @@ class ActivityController extends AbstractController case $activity::EVENT_TORRENT_APPROVE_DELETE: + // Init torrent + if (!$torrent = $torrentService->getTorrent($activity->getTorrentId())) + { + throw $this->createNotFoundException(); + } + return $this->render( 'default/activity/event/torrent/approve/delete.html.twig', [ @@ -416,10 +462,22 @@ class ActivityController extends AbstractController ], 'torrent' => [ - 'id' => $activity->getTorrentId(), - 'name' => $torrentService->readTorrentFileByTorrentId( - $activity->getTorrentId() + 'id' => $torrent->getId(), + 'sensitive' => $torrent->isSensitive(), + 'approved' => $torrent->isApproved(), + 'name' => $torrentService->readTorrentFileByTorrentId( + $torrent->getId() )->getName() + ], + 'session' => + [ + 'user' => + [ + 'id' => $user->getId(), + 'sensitive' => $user->isSensitive(), + 'moderator' => $user->isModerator(), + 'owner' => $user->getId() === $torrent->getUserId(), + ] ] ] ); @@ -429,6 +487,12 @@ class ActivityController extends AbstractController // Torrent Download case $activity::EVENT_TORRENT_DOWNLOAD_FILE_ADD: + // Init torrent + if (!$torrent = $torrentService->getTorrent($activity->getTorrentId())) + { + throw $this->createNotFoundException(); + } + return $this->render( 'default/activity/event/torrent/download/file/add.html.twig', [ @@ -444,10 +508,22 @@ class ActivityController extends AbstractController ], 'torrent' => [ - 'id' => $activity->getTorrentId(), - 'name' => $torrentService->readTorrentFileByTorrentId( - $activity->getTorrentId() + 'id' => $torrent->getId(), + 'sensitive' => $torrent->isSensitive(), + 'approved' => $torrent->isApproved(), + 'name' => $torrentService->readTorrentFileByTorrentId( + $torrent->getId() )->getName() + ], + 'session' => + [ + 'user' => + [ + 'id' => $user->getId(), + 'sensitive' => $user->isSensitive(), + 'moderator' => $user->isModerator(), + 'owner' => $user->getId() === $torrent->getUserId(), + ] ] ] ); @@ -456,6 +532,12 @@ class ActivityController extends AbstractController case $activity::EVENT_TORRENT_DOWNLOAD_MAGNET_ADD: + // Init torrent + if (!$torrent = $torrentService->getTorrent($activity->getTorrentId())) + { + throw $this->createNotFoundException(); + } + return $this->render( 'default/activity/event/torrent/download/magnet/add.html.twig', [ @@ -471,10 +553,22 @@ class ActivityController extends AbstractController ], 'torrent' => [ - 'id' => $activity->getTorrentId(), - 'name' => $torrentService->readTorrentFileByTorrentId( - $activity->getTorrentId() + 'id' => $torrent->getId(), + 'sensitive' => $torrent->isSensitive(), + 'approved' => $torrent->isApproved(), + 'name' => $torrentService->readTorrentFileByTorrentId( + $torrent->getId() )->getName() + ], + 'session' => + [ + 'user' => + [ + 'id' => $user->getId(), + 'sensitive' => $user->isSensitive(), + 'moderator' => $user->isModerator(), + 'owner' => $user->getId() === $torrent->getUserId(), + ] ] ] ); @@ -484,6 +578,12 @@ class ActivityController extends AbstractController /// Torrent Locales case $activity::EVENT_TORRENT_LOCALES_ADD: + // Init torrent + if (!$torrent = $torrentService->getTorrent($activity->getTorrentId())) + { + throw $this->createNotFoundException(); + } + return $this->render( 'default/activity/event/torrent/locales/add.html.twig', [ @@ -499,16 +599,28 @@ class ActivityController extends AbstractController ], 'torrent' => [ - 'id' => $activity->getTorrentId(), - 'name' => $torrentService->readTorrentFileByTorrentId( - $activity->getTorrentId() + 'id' => $torrent->getId(), + 'sensitive' => $torrent->isSensitive(), + 'approved' => $torrent->isApproved(), + 'name' => $torrentService->readTorrentFileByTorrentId( + $torrent->getId() )->getName(), - 'locales' => [ + 'locales' => [ 'id' => $activity->getData()['torrentLocalesId'], - 'exist' => $torrentService->getTorrentLocales( + 'exist' => $torrentService->getTorrentLocales( $activity->getData()['torrentLocalesId'] // could be deleted by moderator, remove links ) ] + ], + 'session' => + [ + 'user' => + [ + 'id' => $user->getId(), + 'sensitive' => $user->isSensitive(), + 'moderator' => $user->isModerator(), + 'owner' => $user->getId() === $torrent->getUserId(), + ] ] ] ); @@ -517,6 +629,12 @@ class ActivityController extends AbstractController case $activity::EVENT_TORRENT_LOCALES_DELETE: + // Init torrent + if (!$torrent = $torrentService->getTorrent($activity->getTorrentId())) + { + throw $this->createNotFoundException(); + } + return $this->render( 'default/activity/event/torrent/locales/delete.html.twig', [ @@ -532,16 +650,28 @@ class ActivityController extends AbstractController ], 'torrent' => [ - 'id' => $activity->getTorrentId(), - 'name' => $torrentService->readTorrentFileByTorrentId( - $activity->getTorrentId() + 'id' => $torrent->getId(), + 'sensitive' => $torrent->isSensitive(), + 'approved' => $torrent->isApproved(), + 'name' => $torrentService->readTorrentFileByTorrentId( + $torrent->getId() )->getName(), - 'locales' => [ - 'id' => $activity->getData()['torrentLocalesId'], + 'locales' => [ + 'id' => $activity->getData()['torrentLocalesId'], 'exist' => $torrentService->getTorrentLocales( $activity->getData()['torrentLocalesId'] // could be deleted by moderator, remove links ) ] + ], + 'session' => + [ + 'user' => + [ + 'id' => $user->getId(), + 'sensitive' => $user->isSensitive(), + 'moderator' => $user->isModerator(), + 'owner' => $user->getId() === $torrent->getUserId(), + ] ] ] ); @@ -550,6 +680,12 @@ class ActivityController extends AbstractController case $activity::EVENT_TORRENT_LOCALES_APPROVE_ADD: + // Init torrent + if (!$torrent = $torrentService->getTorrent($activity->getTorrentId())) + { + throw $this->createNotFoundException(); + } + return $this->render( 'default/activity/event/torrent/locales/approve/add.html.twig', [ @@ -565,16 +701,28 @@ class ActivityController extends AbstractController ], 'torrent' => [ - 'id' => $activity->getTorrentId(), - 'name' => $torrentService->readTorrentFileByTorrentId( - $activity->getTorrentId() + 'id' => $torrent->getId(), + 'sensitive' => $torrent->isSensitive(), + 'approved' => $torrent->isApproved(), + 'name' => $torrentService->readTorrentFileByTorrentId( + $torrent->getId() )->getName(), - 'locales' => [ - 'id' => $activity->getData()['torrentLocalesId'], + 'locales' => [ + 'id' => $activity->getData()['torrentLocalesId'], 'exist' => $torrentService->getTorrentLocales( $activity->getData()['torrentLocalesId'] // could be deleted by moderator, remove links ) ] + ], + 'session' => + [ + 'user' => + [ + 'id' => $user->getId(), + 'sensitive' => $user->isSensitive(), + 'moderator' => $user->isModerator(), + 'owner' => $user->getId() === $torrent->getUserId(), + ] ] ] ); @@ -583,6 +731,12 @@ class ActivityController extends AbstractController case $activity::EVENT_TORRENT_LOCALES_APPROVE_DELETE: + // Init torrent + if (!$torrent = $torrentService->getTorrent($activity->getTorrentId())) + { + throw $this->createNotFoundException(); + } + return $this->render( 'default/activity/event/torrent/locales/approve/delete.html.twig', [ @@ -598,16 +752,28 @@ class ActivityController extends AbstractController ], 'torrent' => [ - 'id' => $activity->getTorrentId(), - 'name' => $torrentService->readTorrentFileByTorrentId( - $activity->getTorrentId() + 'id' => $torrent->getId(), + 'sensitive' => $torrent->isSensitive(), + 'approved' => $torrent->isApproved(), + 'name' => $torrentService->readTorrentFileByTorrentId( + $torrent->getId() )->getName(), - 'locales' => [ - 'id' => $activity->getData()['torrentLocalesId'], + 'locales' => [ + 'id' => $activity->getData()['torrentLocalesId'], 'exist' => $torrentService->getTorrentLocales( $activity->getData()['torrentLocalesId'] // could be deleted by moderator, remove links ) ] + ], + 'session' => + [ + 'user' => + [ + 'id' => $user->getId(), + 'sensitive' => $user->isSensitive(), + 'moderator' => $user->isModerator(), + 'owner' => $user->getId() === $torrent->getUserId(), + ] ] ] ); @@ -617,6 +783,12 @@ class ActivityController extends AbstractController /// Torrent Sensitive case $activity::EVENT_TORRENT_SENSITIVE_ADD: + // Init torrent + if (!$torrent = $torrentService->getTorrent($activity->getTorrentId())) + { + throw $this->createNotFoundException(); + } + return $this->render( 'default/activity/event/torrent/sensitive/add.html.twig', [ @@ -632,16 +804,28 @@ class ActivityController extends AbstractController ], 'torrent' => [ - 'id' => $activity->getTorrentId(), - 'name' => $torrentService->readTorrentFileByTorrentId( - $activity->getTorrentId() + 'id' => $torrent->getId(), + 'sensitive' => $torrent->isSensitive(), + 'approved' => $torrent->isApproved(), + 'name' => $torrentService->readTorrentFileByTorrentId( + $torrent->getId() )->getName(), 'sensitive' => [ - 'id' => $activity->getData()['torrentSensitiveId'], + 'id' => $activity->getData()['torrentSensitiveId'], 'exist' => $torrentService->getTorrentSensitive( $activity->getData()['torrentSensitiveId'] // could be deleted by moderator, remove links ) ] + ], + 'session' => + [ + 'user' => + [ + 'id' => $user->getId(), + 'sensitive' => $user->isSensitive(), + 'moderator' => $user->isModerator(), + 'owner' => $user->getId() === $torrent->getUserId(), + ] ] ] ); @@ -650,6 +834,12 @@ class ActivityController extends AbstractController case $activity::EVENT_TORRENT_SENSITIVE_DELETE: + // Init torrent + if (!$torrent = $torrentService->getTorrent($activity->getTorrentId())) + { + throw $this->createNotFoundException(); + } + return $this->render( 'default/activity/event/torrent/sensitive/delete.html.twig', [ @@ -665,16 +855,28 @@ class ActivityController extends AbstractController ], 'torrent' => [ - 'id' => $activity->getTorrentId(), - 'name' => $torrentService->readTorrentFileByTorrentId( - $activity->getTorrentId() + 'id' => $torrent->getId(), + 'sensitive' => $torrent->isSensitive(), + 'approved' => $torrent->isApproved(), + 'name' => $torrentService->readTorrentFileByTorrentId( + $torrent->getId() )->getName(), 'sensitive' => [ - 'id' => $activity->getData()['torrentSensitiveId'], + 'id' => $activity->getData()['torrentSensitiveId'], 'exist' => $torrentService->getTorrentSensitive( $activity->getData()['torrentSensitiveId'] // could be deleted by moderator, remove links ) ] + ], + 'session' => + [ + 'user' => + [ + 'id' => $user->getId(), + 'sensitive' => $user->isSensitive(), + 'moderator' => $user->isModerator(), + 'owner' => $user->getId() === $torrent->getUserId(), + ] ] ] ); @@ -683,6 +885,12 @@ class ActivityController extends AbstractController case $activity::EVENT_TORRENT_SENSITIVE_APPROVE_ADD: + // Init torrent + if (!$torrent = $torrentService->getTorrent($activity->getTorrentId())) + { + throw $this->createNotFoundException(); + } + return $this->render( 'default/activity/event/torrent/sensitive/approve/add.html.twig', [ @@ -698,16 +906,28 @@ class ActivityController extends AbstractController ], 'torrent' => [ - 'id' => $activity->getTorrentId(), - 'name' => $torrentService->readTorrentFileByTorrentId( - $activity->getTorrentId() + 'id' => $torrent->getId(), + 'sensitive' => $torrent->isSensitive(), + 'approved' => $torrent->isApproved(), + 'name' => $torrentService->readTorrentFileByTorrentId( + $torrent->getId() )->getName(), 'sensitive' => [ - 'id' => $activity->getData()['torrentSensitiveId'], + 'id' => $activity->getData()['torrentSensitiveId'], 'exist' => $torrentService->getTorrentSensitive( $activity->getData()['torrentSensitiveId'] // could be deleted by moderator, remove links ) ] + ], + 'session' => + [ + 'user' => + [ + 'id' => $user->getId(), + 'sensitive' => $user->isSensitive(), + 'moderator' => $user->isModerator(), + 'owner' => $user->getId() === $torrent->getUserId(), + ] ] ] ); @@ -716,6 +936,12 @@ class ActivityController extends AbstractController case $activity::EVENT_TORRENT_SENSITIVE_APPROVE_DELETE: + // Init torrent + if (!$torrent = $torrentService->getTorrent($activity->getTorrentId())) + { + throw $this->createNotFoundException(); + } + return $this->render( 'default/activity/event/torrent/sensitive/approve/delete.html.twig', [ @@ -731,16 +957,28 @@ class ActivityController extends AbstractController ], 'torrent' => [ - 'id' => $activity->getTorrentId(), - 'name' => $torrentService->readTorrentFileByTorrentId( - $activity->getTorrentId() + 'id' => $torrent->getId(), + 'sensitive' => $torrent->isSensitive(), + 'approved' => $torrent->isApproved(), + 'name' => $torrentService->readTorrentFileByTorrentId( + $torrent->getId() )->getName(), 'sensitive' => [ - 'id' => $activity->getData()['torrentSensitiveId'], + 'id' => $activity->getData()['torrentSensitiveId'], 'exist' => $torrentService->getTorrentSensitive( $activity->getData()['torrentSensitiveId'] // could be deleted by moderator, remove links ) ] + ], + 'session' => + [ + 'user' => + [ + 'id' => $user->getId(), + 'sensitive' => $user->isSensitive(), + 'moderator' => $user->isModerator(), + 'owner' => $user->getId() === $torrent->getUserId(), + ] ] ] ); @@ -750,6 +988,12 @@ class ActivityController extends AbstractController /// Torrent star case $activity::EVENT_TORRENT_STAR_ADD: + // Init torrent + if (!$torrent = $torrentService->getTorrent($activity->getTorrentId())) + { + throw $this->createNotFoundException(); + } + return $this->render( 'default/activity/event/torrent/star/add.html.twig', [ @@ -765,10 +1009,22 @@ class ActivityController extends AbstractController ], 'torrent' => [ - 'id' => $activity->getTorrentId(), - 'name' => $torrentService->readTorrentFileByTorrentId( - $activity->getTorrentId() + 'id' => $torrent->getId(), + 'sensitive' => $torrent->isSensitive(), + 'approved' => $torrent->isApproved(), + 'name' => $torrentService->readTorrentFileByTorrentId( + $torrent->getId() )->getName() + ], + 'session' => + [ + 'user' => + [ + 'id' => $user->getId(), + 'sensitive' => $user->isSensitive(), + 'moderator' => $user->isModerator(), + 'owner' => $user->getId() === $torrent->getUserId(), + ] ] ] ); @@ -777,6 +1033,12 @@ class ActivityController extends AbstractController case $activity::EVENT_TORRENT_STAR_DELETE: + // Init torrent + if (!$torrent = $torrentService->getTorrent($activity->getTorrentId())) + { + throw $this->createNotFoundException(); + } + return $this->render( 'default/activity/event/torrent/star/delete.html.twig', [ @@ -792,18 +1054,28 @@ class ActivityController extends AbstractController ], 'torrent' => [ - 'id' => $activity->getTorrentId(), - 'name' => $torrentService->readTorrentFileByTorrentId( - $activity->getTorrentId() + 'id' => $torrent->getId(), + 'sensitive' => $torrent->isSensitive(), + 'approved' => $torrent->isApproved(), + 'name' => $torrentService->readTorrentFileByTorrentId( + $torrent->getId() )->getName() + ], + 'session' => + [ + 'user' => + [ + 'id' => $user->getId(), + 'sensitive' => $user->isSensitive(), + 'moderator' => $user->isModerator(), + 'owner' => $user->getId() === $torrent->getUserId(), + ] ] ] ); break; - // @TODO Page - default: return $this->render( diff --git a/src/Controller/TorrentController.php b/src/Controller/TorrentController.php index af59123..db4f340 100644 --- a/src/Controller/TorrentController.php +++ b/src/Controller/TorrentController.php @@ -55,6 +55,18 @@ class TorrentController extends AbstractController throw $this->createNotFoundException(); } + // Sensitive filter + if (!$user->isModerator() && $user->getId() != $torrent->getUserId() && $user->isSensitive()) + { + throw $this->createNotFoundException(); + } + + // Approved filter + if (!$user->isModerator() && $user->getId() != $torrent->getUserId() && !$torrent->isApproved()) + { + throw $this->createNotFoundException(); + } + // Get contributors $contributors = []; foreach ($torrentService->getTorrentContributors($torrent) as $userId) @@ -95,6 +107,10 @@ class TorrentController extends AbstractController // Render template return $this->render('default/torrent/info.html.twig', [ + 'session' => + [ + 'user' => $user + ], 'user' => [ 'id' => $user->getId(), @@ -215,16 +231,16 @@ class TorrentController extends AbstractController $total = $torrentService->findTorrentsTotal( $query, $user->getLocales(), - $user->isSensitive() ? false : null, // hide on sensitive mode enabled or show all - $user->isModerator() ? null : true, // show approved content only for regular users + !$user->isModerator() && $user->isSensitive() ? false : null, // hide on sensitive mode enabled or show all + !$user->isModerator() ? true : null, // show approved content only for regular users ); $torrents = []; foreach ($torrentService->findTorrents( $query, $user->getLocales(), - $user->isSensitive() ? false : null, // hide on sensitive mode enabled or show all - $user->isModerator() ? null : true, // show approved content only for regular users + !$user->isModerator() && $user->isSensitive() ? false : null, // hide on sensitive mode enabled or show all + !$user->isModerator() ? true : null, // show approved content only for regular users $this->getParameter('app.pagination'), ($page - 1) * $this->getParameter('app.pagination') ) as $torrent) @@ -247,8 +263,10 @@ class TorrentController extends AbstractController $torrents[] = [ - 'id' => $torrent->getId(), - 'added' => $torrent->getAdded(), + 'id' => $torrent->getId(), + 'added' => $torrent->getAdded(), + 'approved' => $torrent->isApproved(), + 'sensitive' => $torrent->isSensitive(), 'file' => [ 'name' => $file->getName(), @@ -341,8 +359,8 @@ class TorrentController extends AbstractController $total = $torrentService->findTorrentsTotal( [], $user->getLocales(), - $user->isSensitive() ? false : null, // hide on sensitive mode enabled or show all - $user->isModerator() ? null : true, // show approved content only for regular users + !$user->isModerator() && $user->isSensitive() ? false : null, // hide on sensitive mode enabled or show all + !$user->isModerator() ? true : null, // show approved content only for regular users ); // Create torrents list @@ -350,8 +368,8 @@ class TorrentController extends AbstractController foreach ($torrentService->findTorrents( [], $user->getLocales(), - $user->isSensitive() ? false : null, // hide on sensitive mode enabled or show all - $user->isModerator() ? null : true, // show approved content only for regular users + !$user->isModerator() && $user->isSensitive() ? false : null, // hide on sensitive mode enabled or show all + !$user->isModerator() ? true : null, // show approved content only for regular users $this->getParameter('app.pagination'), ($page - 1) * $this->getParameter('app.pagination') ) as $torrent) @@ -375,8 +393,10 @@ class TorrentController extends AbstractController $torrents[] = [ - 'id' => $torrent->getId(), - 'added' => $torrent->getAdded(), + 'id' => $torrent->getId(), + 'added' => $torrent->getAdded(), + 'approved' => $torrent->isApproved(), + 'sensitive' => $torrent->isSensitive(), 'file' => [ 'name' => $file->getName(), @@ -1480,6 +1500,18 @@ class TorrentController extends AbstractController ); } + // Sensitive filter + if (!$user->isModerator() && $user->getId() != $torrent->getUserId() && $user->isSensitive()) + { + throw $this->createNotFoundException(); + } + + // Approved filter + if (!$user->isModerator() && $user->getId() != $torrent->getUserId() && !$torrent->isApproved()) + { + throw $this->createNotFoundException(); + } + // Register download $torrentService->addTorrentDownloadFile( $torrent->getId(), @@ -1588,6 +1620,18 @@ class TorrentController extends AbstractController ); } + // Sensitive filter + if (!$user->isModerator() && $user->getId() != $torrent->getUserId() && $user->isSensitive()) + { + throw $this->createNotFoundException(); + } + + // Approved filter + if (!$user->isModerator() && $user->getId() != $torrent->getUserId() && !$torrent->isApproved()) + { + throw $this->createNotFoundException(); + } + // Register download $torrentService->addTorrentDownloadMagnet( $torrent->getId(), diff --git a/src/Controller/UserController.php b/src/Controller/UserController.php index 97fde33..449e535 100644 --- a/src/Controller/UserController.php +++ b/src/Controller/UserController.php @@ -208,6 +208,10 @@ class UserController extends AbstractController return $this->render( 'default/user/info.html.twig', [ + 'session' => + [ + 'user' => $user + ], 'user' => [ 'id' => $userTarget->getId(), 'address' => $userTarget->getId() === $user->getId() ? $userTarget->getAddress() : false, diff --git a/templates/default/activity/event/torrent/add.html.twig b/templates/default/activity/event/torrent/add.html.twig index 2602f93..9640c35 100644 --- a/templates/default/activity/event/torrent/add.html.twig +++ b/templates/default/activity/event/torrent/add.html.twig @@ -6,9 +6,24 @@ {{ 'added torrent' | trans }} - - {{ torrent.name }} - + {% if session.user.moderator or session.user.owner %} + + {{ torrent.name }} + + {% if torrent.approved == false %} + #{{ torrent.id }} ({{ 'waiting for approve' | trans }}) + {% endif %} + {% else %} + {% if torrent.approved == false %} + #{{ torrent.id }} ({{ 'waiting for approve' | trans }}) + {% elseif torrent.sensitive == true %} + #{{ torrent.id }} ({{ 'sensitive' | trans }}) + {% else %} + + {{ torrent.name }} + + {% endif %} + {% endif %}
{{ added | format_ago }} diff --git a/templates/default/activity/event/torrent/approve/add.html.twig b/templates/default/activity/event/torrent/approve/add.html.twig index f1b227e..9c6e114 100644 --- a/templates/default/activity/event/torrent/approve/add.html.twig +++ b/templates/default/activity/event/torrent/approve/add.html.twig @@ -6,9 +6,24 @@ {{ 'approved torrent' | trans }} - - {{ torrent.name }} - + {% if session.user.moderator or session.user.owner %} + + {{ torrent.name }} + + {% if torrent.approved == false %} + #{{ torrent.id }} ({{ 'waiting for approve' | trans }}) + {% endif %} + {% else %} + {% if torrent.approved == false %} + #{{ torrent.id }} ({{ 'waiting for approve' | trans }}) + {% elseif torrent.sensitive == true %} + #{{ torrent.id }} ({{ 'sensitive' | trans }}) + {% else %} + + {{ torrent.name }} + + {% endif %} + {% endif %}
{{ added | format_ago }} diff --git a/templates/default/activity/event/torrent/approve/delete.html.twig b/templates/default/activity/event/torrent/approve/delete.html.twig index 6abaa30..07f0439 100644 --- a/templates/default/activity/event/torrent/approve/delete.html.twig +++ b/templates/default/activity/event/torrent/approve/delete.html.twig @@ -6,9 +6,24 @@ {{ 'disapproved torrent' | trans }} - - {{ torrent.name }} - + {% if session.user.moderator or session.user.owner %} + + {{ torrent.name }} + + {% if torrent.approved == false %} + #{{ torrent.id }} ({{ 'waiting for approve' | trans }}) + {% endif %} + {% else %} + {% if torrent.approved == false %} + #{{ torrent.id }} ({{ 'waiting for approve' | trans }}) + {% elseif torrent.sensitive == true %} + #{{ torrent.id }} ({{ 'sensitive' | trans }}) + {% else %} + + {{ torrent.name }} + + {% endif %} + {% endif %}
{{ added | format_ago }} diff --git a/templates/default/activity/event/torrent/download/file/add.html.twig b/templates/default/activity/event/torrent/download/file/add.html.twig index 40119f2..ab46476 100644 --- a/templates/default/activity/event/torrent/download/file/add.html.twig +++ b/templates/default/activity/event/torrent/download/file/add.html.twig @@ -6,9 +6,24 @@ {{ 'downloaded torrent file' | trans }} - - {{ torrent.name }} - + {% if session.user.moderator or session.user.owner %} + + {{ torrent.name }} + + {% if torrent.approved == false %} + #{{ torrent.id }} ({{ 'waiting for approve' | trans }}) + {% endif %} + {% else %} + {% if torrent.approved == false %} + #{{ torrent.id }} ({{ 'waiting for approve' | trans }}) + {% elseif torrent.sensitive == true %} + #{{ torrent.id }} ({{ 'sensitive' | trans }}) + {% else %} + + {{ torrent.name }} + + {% endif %} + {% endif %}
{{ added | format_ago }} diff --git a/templates/default/activity/event/torrent/download/magnet/add.html.twig b/templates/default/activity/event/torrent/download/magnet/add.html.twig index b5467aa..a746575 100644 --- a/templates/default/activity/event/torrent/download/magnet/add.html.twig +++ b/templates/default/activity/event/torrent/download/magnet/add.html.twig @@ -6,9 +6,24 @@ {{ 'downloaded magnet link' | trans }} - - {{ torrent.name }} - + {% if session.user.moderator or session.user.owner %} + + {{ torrent.name }} + + {% if torrent.approved == false %} + #{{ torrent.id }} ({{ 'waiting for approve' | trans }}) + {% endif %} + {% else %} + {% if torrent.approved == false %} + #{{ torrent.id }} ({{ 'waiting for approve' | trans }}) + {% elseif torrent.sensitive == true %} + #{{ torrent.id }} ({{ 'sensitive' | trans }}) + {% else %} + + {{ torrent.name }} + + {% endif %} + {% endif %}
{{ added | format_ago }} diff --git a/templates/default/activity/event/torrent/locales/add.html.twig b/templates/default/activity/event/torrent/locales/add.html.twig index c6d8e5c..d208179 100644 --- a/templates/default/activity/event/torrent/locales/add.html.twig +++ b/templates/default/activity/event/torrent/locales/add.html.twig @@ -14,9 +14,24 @@ #{{ torrent.locales.id }} {% endif %} {{ 'for torrent' | trans }} - - {{ torrent.name }} - + {% if session.user.moderator or session.user.owner %} + + {{ torrent.name }} + + {% if torrent.approved == false %} + #{{ torrent.id }} ({{ 'waiting for approve' | trans }}) + {% endif %} + {% else %} + {% if torrent.approved == false %} + #{{ torrent.id }} ({{ 'waiting for approve' | trans }}) + {% elseif torrent.sensitive == true %} + #{{ torrent.id }} ({{ 'sensitive' | trans }}) + {% else %} + + {{ torrent.name }} + + {% endif %} + {% endif %}
{{ added | format_ago }} diff --git a/templates/default/activity/event/torrent/locales/approve/add.html.twig b/templates/default/activity/event/torrent/locales/approve/add.html.twig index 355d982..16a54cc 100644 --- a/templates/default/activity/event/torrent/locales/approve/add.html.twig +++ b/templates/default/activity/event/torrent/locales/approve/add.html.twig @@ -12,9 +12,24 @@ #{{ torrent.locales.id }} {% endif %} {{ 'for torrent' | trans }} - - {{ torrent.name }} - + {% if session.user.moderator or session.user.owner %} + + {{ torrent.name }} + + {% if torrent.approved == false %} + #{{ torrent.id }} ({{ 'waiting for approve' | trans }}) + {% endif %} + {% else %} + {% if torrent.approved == false %} + #{{ torrent.id }} ({{ 'waiting for approve' | trans }}) + {% elseif torrent.sensitive == true %} + #{{ torrent.id }} ({{ 'sensitive' | trans }}) + {% else %} + + {{ torrent.name }} + + {% endif %} + {% endif %}
{{ added | format_ago }} diff --git a/templates/default/activity/event/torrent/locales/approve/delete.html.twig b/templates/default/activity/event/torrent/locales/approve/delete.html.twig index 8a936ed..5631b90 100644 --- a/templates/default/activity/event/torrent/locales/approve/delete.html.twig +++ b/templates/default/activity/event/torrent/locales/approve/delete.html.twig @@ -14,9 +14,24 @@ #{{ torrent.locales.id }} {% endif %} {{ 'for torrent' | trans }} - - {{ torrent.name }} - + {% if session.user.moderator or session.user.owner %} + + {{ torrent.name }} + + {% if torrent.approved == false %} + #{{ torrent.id }} ({{ 'waiting for approve' | trans }}) + {% endif %} + {% else %} + {% if torrent.approved == false %} + #{{ torrent.id }} ({{ 'waiting for approve' | trans }}) + {% elseif torrent.sensitive == true %} + #{{ torrent.id }} ({{ 'sensitive' | trans }}) + {% else %} + + {{ torrent.name }} + + {% endif %} + {% endif %}
{{ added | format_ago }} diff --git a/templates/default/activity/event/torrent/locales/delete.html.twig b/templates/default/activity/event/torrent/locales/delete.html.twig index 2a99463..41cc76e 100644 --- a/templates/default/activity/event/torrent/locales/delete.html.twig +++ b/templates/default/activity/event/torrent/locales/delete.html.twig @@ -12,9 +12,24 @@ #{{ torrent.locales.id }} {% endif %} {{ 'for torrent' | trans }} - - {{ torrent.name }} - + {% if session.user.moderator or session.user.owner %} + + {{ torrent.name }} + + {% if torrent.approved == false %} + #{{ torrent.id }} ({{ 'waiting for approve' | trans }}) + {% endif %} + {% else %} + {% if torrent.approved == false %} + #{{ torrent.id }} ({{ 'waiting for approve' | trans }}) + {% elseif torrent.sensitive == true %} + #{{ torrent.id }} ({{ 'sensitive' | trans }}) + {% else %} + + {{ torrent.name }} + + {% endif %} + {% endif %}
{{ added | format_ago }} diff --git a/templates/default/activity/event/torrent/sensitive/add.html.twig b/templates/default/activity/event/torrent/sensitive/add.html.twig index 7197391..c241edf 100644 --- a/templates/default/activity/event/torrent/sensitive/add.html.twig +++ b/templates/default/activity/event/torrent/sensitive/add.html.twig @@ -12,9 +12,24 @@ #{{ torrent.sensitive.id }} {% endif %} {{ 'for torrent' | trans }} - - {{ torrent.name }} - + {% if session.user.moderator or session.user.owner %} + + {{ torrent.name }} + + {% if torrent.approved == false %} + #{{ torrent.id }} ({{ 'waiting for approve' | trans }}) + {% endif %} + {% else %} + {% if torrent.approved == false %} + #{{ torrent.id }} ({{ 'waiting for approve' | trans }}) + {% elseif torrent.sensitive == true %} + #{{ torrent.id }} ({{ 'sensitive' | trans }}) + {% else %} + + {{ torrent.name }} + + {% endif %} + {% endif %}
{{ added | format_ago }} diff --git a/templates/default/activity/event/torrent/sensitive/approve/add.html.twig b/templates/default/activity/event/torrent/sensitive/approve/add.html.twig index eddd6f7..3c0af31 100644 --- a/templates/default/activity/event/torrent/sensitive/approve/add.html.twig +++ b/templates/default/activity/event/torrent/sensitive/approve/add.html.twig @@ -12,9 +12,24 @@ #{{ torrent.sensitive.id }} {% endif %} {{ 'for torrent' | trans }} - - {{ torrent.name }} - + {% if session.user.moderator or session.user.owner %} + + {{ torrent.name }} + + {% if torrent.approved == false %} + #{{ torrent.id }} ({{ 'waiting for approve' | trans }}) + {% endif %} + {% else %} + {% if torrent.approved == false %} + #{{ torrent.id }} ({{ 'waiting for approve' | trans }}) + {% elseif torrent.sensitive == true %} + #{{ torrent.id }} ({{ 'sensitive' | trans }}) + {% else %} + + {{ torrent.name }} + + {% endif %} + {% endif %}
{{ added | format_ago }} diff --git a/templates/default/activity/event/torrent/sensitive/approve/delete.html.twig b/templates/default/activity/event/torrent/sensitive/approve/delete.html.twig index 5ee6348..95729a4 100644 --- a/templates/default/activity/event/torrent/sensitive/approve/delete.html.twig +++ b/templates/default/activity/event/torrent/sensitive/approve/delete.html.twig @@ -12,9 +12,24 @@ #{{ torrent.sensitive.id }} {% endif %} {{ 'for torrent' | trans }} - - {{ torrent.name }} - + {% if session.user.moderator or session.user.owner %} + + {{ torrent.name }} + + {% if torrent.approved == false %} + #{{ torrent.id }} ({{ 'waiting for approve' | trans }}) + {% endif %} + {% else %} + {% if torrent.approved == false %} + #{{ torrent.id }} ({{ 'waiting for approve' | trans }}) + {% elseif torrent.sensitive == true %} + #{{ torrent.id }} ({{ 'sensitive' | trans }}) + {% else %} + + {{ torrent.name }} + + {% endif %} + {% endif %}
{{ added | format_ago }} diff --git a/templates/default/activity/event/torrent/sensitive/delete.html.twig b/templates/default/activity/event/torrent/sensitive/delete.html.twig index 47c0541..c6f449c 100644 --- a/templates/default/activity/event/torrent/sensitive/delete.html.twig +++ b/templates/default/activity/event/torrent/sensitive/delete.html.twig @@ -12,9 +12,24 @@ #{{ torrent.sensitive.id }} {% endif %} {{ 'for torrent' | trans }} - - {{ torrent.name }} - + {% if session.user.moderator or session.user.owner %} + + {{ torrent.name }} + + {% if torrent.approved == false %} + #{{ torrent.id }} ({{ 'waiting for approve' | trans }}) + {% endif %} + {% else %} + {% if torrent.approved == false %} + #{{ torrent.id }} ({{ 'waiting for approve' | trans }}) + {% elseif torrent.sensitive == true %} + #{{ torrent.id }} ({{ 'sensitive' | trans }}) + {% else %} + + {{ torrent.name }} + + {% endif %} + {% endif %}
{{ added | format_ago }} diff --git a/templates/default/activity/event/torrent/star/add.html.twig b/templates/default/activity/event/torrent/star/add.html.twig index 1ed0cf6..102a43d 100644 --- a/templates/default/activity/event/torrent/star/add.html.twig +++ b/templates/default/activity/event/torrent/star/add.html.twig @@ -6,9 +6,24 @@ {{ 'added star for torrent' | trans }} - - {{ torrent.name }} - + {% if session.user.moderator or session.user.owner %} + + {{ torrent.name }} + + {% if torrent.approved == false %} + #{{ torrent.id }} ({{ 'waiting for approve' | trans }}) + {% endif %} + {% else %} + {% if torrent.approved == false %} + #{{ torrent.id }} ({{ 'waiting for approve' | trans }}) + {% elseif torrent.sensitive == true %} + #{{ torrent.id }} ({{ 'sensitive' | trans }}) + {% else %} + + {{ torrent.name }} + + {% endif %} + {% endif %}
{{ added | format_ago }} diff --git a/templates/default/activity/event/torrent/star/delete.html.twig b/templates/default/activity/event/torrent/star/delete.html.twig index 38994da..496bf5c 100644 --- a/templates/default/activity/event/torrent/star/delete.html.twig +++ b/templates/default/activity/event/torrent/star/delete.html.twig @@ -7,9 +7,24 @@ {{ 'removed star from torrent' | trans }} - - {{ torrent.name }} - + {% if session.user.moderator or session.user.owner %} + + {{ torrent.name }} + + {% if torrent.approved == false %} + #{{ torrent.id }} ({{ 'waiting for approve' | trans }}) + {% endif %} + {% else %} + {% if torrent.approved == false %} + #{{ torrent.id }} ({{ 'waiting for approve' | trans }}) + {% elseif torrent.sensitive == true %} + #{{ torrent.id }} ({{ 'sensitive' | trans }}) + {% else %} + + {{ torrent.name }} + + {% endif %} + {% endif %}
{{ added | format_ago }} diff --git a/templates/default/activity/list.html.twig b/templates/default/activity/list.html.twig index caa7f45..da37c9e 100644 --- a/templates/default/activity/list.html.twig +++ b/templates/default/activity/list.html.twig @@ -5,7 +5,7 @@
{{ render(controller( 'App\\Controller\\ActivityController::event', - { activity : activity } + { user : session.user, activity : activity } )) }}
{% endfor %} diff --git a/templates/default/torrent/info.html.twig b/templates/default/torrent/info.html.twig index 1aa7873..0921085 100644 --- a/templates/default/torrent/info.html.twig +++ b/templates/default/torrent/info.html.twig @@ -340,7 +340,7 @@
{{ render(controller( 'App\\Controller\\ActivityController::event', - { activity : activity } + { user : session.user, activity : activity } )) }}
{% endfor %} diff --git a/templates/default/torrent/list.html.twig b/templates/default/torrent/list.html.twig index 51a145b..ada5514 100644 --- a/templates/default/torrent/list.html.twig +++ b/templates/default/torrent/list.html.twig @@ -3,7 +3,7 @@ {% block main_content %} {% if torrents %} {% for torrent in torrents %} -
+

@@ -12,11 +12,25 @@

{% if torrent.scrape.leechers == 0 and torrent.scrape.leechers == 0 %} - {{ 'wanted' | trans }} {% endif %} + {% if torrent.approved == false %} + + + + + + {% endif %} + {% if torrent.sensitive == true %} + + + + + + {% endif %}
{% if torrent.keywords %}
diff --git a/templates/default/user/info.html.twig b/templates/default/user/info.html.twig index dfa7e16..6bb8837 100644 --- a/templates/default/user/info.html.twig +++ b/templates/default/user/info.html.twig @@ -232,7 +232,7 @@
{{ render(controller( 'App\\Controller\\ActivityController::event', - { activity : activity } + { user: session.user, activity : activity } )) }}
{% endfor %}