Browse Source

implement approved/sensitive access behavior

main
ghost 1 year ago
parent
commit
60a5593446
  1. 338
      src/Controller/ActivityController.php
  2. 60
      src/Controller/TorrentController.php
  3. 4
      src/Controller/UserController.php
  4. 15
      templates/default/activity/event/torrent/add.html.twig
  5. 15
      templates/default/activity/event/torrent/approve/add.html.twig
  6. 15
      templates/default/activity/event/torrent/approve/delete.html.twig
  7. 15
      templates/default/activity/event/torrent/download/file/add.html.twig
  8. 15
      templates/default/activity/event/torrent/download/magnet/add.html.twig
  9. 15
      templates/default/activity/event/torrent/locales/add.html.twig
  10. 15
      templates/default/activity/event/torrent/locales/approve/add.html.twig
  11. 15
      templates/default/activity/event/torrent/locales/approve/delete.html.twig
  12. 15
      templates/default/activity/event/torrent/locales/delete.html.twig
  13. 15
      templates/default/activity/event/torrent/sensitive/add.html.twig
  14. 15
      templates/default/activity/event/torrent/sensitive/approve/add.html.twig
  15. 15
      templates/default/activity/event/torrent/sensitive/approve/delete.html.twig
  16. 15
      templates/default/activity/event/torrent/sensitive/delete.html.twig
  17. 15
      templates/default/activity/event/torrent/star/add.html.twig
  18. 15
      templates/default/activity/event/torrent/star/delete.html.twig
  19. 2
      templates/default/activity/list.html.twig
  20. 2
      templates/default/torrent/info.html.twig
  21. 18
      templates/default/torrent/list.html.twig
  22. 2
      templates/default/user/info.html.twig

338
src/Controller/ActivityController.php

@ -43,6 +43,9 @@ class ActivityController extends AbstractController @@ -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 @@ -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 @@ -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 @@ -362,10 +372,22 @@ class ActivityController extends AbstractController
],
'torrent' =>
[
'id' => $activity->getTorrentId(),
'id' => $torrent->getId(),
'sensitive' => $torrent->isSensitive(),
'approved' => $torrent->isApproved(),
'name' => $torrentService->readTorrentFileByTorrentId(
$activity->getTorrentId()
$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 @@ -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 @@ -389,10 +417,22 @@ class ActivityController extends AbstractController
],
'torrent' =>
[
'id' => $activity->getTorrentId(),
'id' => $torrent->getId(),
'sensitive' => $torrent->isSensitive(),
'approved' => $torrent->isApproved(),
'name' => $torrentService->readTorrentFileByTorrentId(
$activity->getTorrentId()
$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 @@ -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 @@ -416,10 +462,22 @@ class ActivityController extends AbstractController
],
'torrent' =>
[
'id' => $activity->getTorrentId(),
'id' => $torrent->getId(),
'sensitive' => $torrent->isSensitive(),
'approved' => $torrent->isApproved(),
'name' => $torrentService->readTorrentFileByTorrentId(
$activity->getTorrentId()
$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 @@ -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 @@ -444,10 +508,22 @@ class ActivityController extends AbstractController
],
'torrent' =>
[
'id' => $activity->getTorrentId(),
'id' => $torrent->getId(),
'sensitive' => $torrent->isSensitive(),
'approved' => $torrent->isApproved(),
'name' => $torrentService->readTorrentFileByTorrentId(
$activity->getTorrentId()
$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 @@ -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 @@ -471,10 +553,22 @@ class ActivityController extends AbstractController
],
'torrent' =>
[
'id' => $activity->getTorrentId(),
'id' => $torrent->getId(),
'sensitive' => $torrent->isSensitive(),
'approved' => $torrent->isApproved(),
'name' => $torrentService->readTorrentFileByTorrentId(
$activity->getTorrentId()
$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 @@ -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,9 +599,11 @@ class ActivityController extends AbstractController @@ -499,9 +599,11 @@ class ActivityController extends AbstractController
],
'torrent' =>
[
'id' => $activity->getTorrentId(),
'id' => $torrent->getId(),
'sensitive' => $torrent->isSensitive(),
'approved' => $torrent->isApproved(),
'name' => $torrentService->readTorrentFileByTorrentId(
$activity->getTorrentId()
$torrent->getId()
)->getName(),
'locales' => [
'id' => $activity->getData()['torrentLocalesId'],
@ -509,6 +611,16 @@ class ActivityController extends AbstractController @@ -509,6 +611,16 @@ class ActivityController extends AbstractController
$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 @@ -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,9 +650,11 @@ class ActivityController extends AbstractController @@ -532,9 +650,11 @@ class ActivityController extends AbstractController
],
'torrent' =>
[
'id' => $activity->getTorrentId(),
'id' => $torrent->getId(),
'sensitive' => $torrent->isSensitive(),
'approved' => $torrent->isApproved(),
'name' => $torrentService->readTorrentFileByTorrentId(
$activity->getTorrentId()
$torrent->getId()
)->getName(),
'locales' => [
'id' => $activity->getData()['torrentLocalesId'],
@ -542,6 +662,16 @@ class ActivityController extends AbstractController @@ -542,6 +662,16 @@ class ActivityController extends AbstractController
$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 @@ -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,9 +701,11 @@ class ActivityController extends AbstractController @@ -565,9 +701,11 @@ class ActivityController extends AbstractController
],
'torrent' =>
[
'id' => $activity->getTorrentId(),
'id' => $torrent->getId(),
'sensitive' => $torrent->isSensitive(),
'approved' => $torrent->isApproved(),
'name' => $torrentService->readTorrentFileByTorrentId(
$activity->getTorrentId()
$torrent->getId()
)->getName(),
'locales' => [
'id' => $activity->getData()['torrentLocalesId'],
@ -575,6 +713,16 @@ class ActivityController extends AbstractController @@ -575,6 +713,16 @@ class ActivityController extends AbstractController
$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 @@ -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,9 +752,11 @@ class ActivityController extends AbstractController @@ -598,9 +752,11 @@ class ActivityController extends AbstractController
],
'torrent' =>
[
'id' => $activity->getTorrentId(),
'id' => $torrent->getId(),
'sensitive' => $torrent->isSensitive(),
'approved' => $torrent->isApproved(),
'name' => $torrentService->readTorrentFileByTorrentId(
$activity->getTorrentId()
$torrent->getId()
)->getName(),
'locales' => [
'id' => $activity->getData()['torrentLocalesId'],
@ -608,6 +764,16 @@ class ActivityController extends AbstractController @@ -608,6 +764,16 @@ class ActivityController extends AbstractController
$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 @@ -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,9 +804,11 @@ class ActivityController extends AbstractController @@ -632,9 +804,11 @@ class ActivityController extends AbstractController
],
'torrent' =>
[
'id' => $activity->getTorrentId(),
'id' => $torrent->getId(),
'sensitive' => $torrent->isSensitive(),
'approved' => $torrent->isApproved(),
'name' => $torrentService->readTorrentFileByTorrentId(
$activity->getTorrentId()
$torrent->getId()
)->getName(),
'sensitive' => [
'id' => $activity->getData()['torrentSensitiveId'],
@ -642,6 +816,16 @@ class ActivityController extends AbstractController @@ -642,6 +816,16 @@ class ActivityController extends AbstractController
$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 @@ -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,9 +855,11 @@ class ActivityController extends AbstractController @@ -665,9 +855,11 @@ class ActivityController extends AbstractController
],
'torrent' =>
[
'id' => $activity->getTorrentId(),
'id' => $torrent->getId(),
'sensitive' => $torrent->isSensitive(),
'approved' => $torrent->isApproved(),
'name' => $torrentService->readTorrentFileByTorrentId(
$activity->getTorrentId()
$torrent->getId()
)->getName(),
'sensitive' => [
'id' => $activity->getData()['torrentSensitiveId'],
@ -675,6 +867,16 @@ class ActivityController extends AbstractController @@ -675,6 +867,16 @@ class ActivityController extends AbstractController
$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 @@ -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,9 +906,11 @@ class ActivityController extends AbstractController @@ -698,9 +906,11 @@ class ActivityController extends AbstractController
],
'torrent' =>
[
'id' => $activity->getTorrentId(),
'id' => $torrent->getId(),
'sensitive' => $torrent->isSensitive(),
'approved' => $torrent->isApproved(),
'name' => $torrentService->readTorrentFileByTorrentId(
$activity->getTorrentId()
$torrent->getId()
)->getName(),
'sensitive' => [
'id' => $activity->getData()['torrentSensitiveId'],
@ -708,6 +918,16 @@ class ActivityController extends AbstractController @@ -708,6 +918,16 @@ class ActivityController extends AbstractController
$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 @@ -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,9 +957,11 @@ class ActivityController extends AbstractController @@ -731,9 +957,11 @@ class ActivityController extends AbstractController
],
'torrent' =>
[
'id' => $activity->getTorrentId(),
'id' => $torrent->getId(),
'sensitive' => $torrent->isSensitive(),
'approved' => $torrent->isApproved(),
'name' => $torrentService->readTorrentFileByTorrentId(
$activity->getTorrentId()
$torrent->getId()
)->getName(),
'sensitive' => [
'id' => $activity->getData()['torrentSensitiveId'],
@ -741,6 +969,16 @@ class ActivityController extends AbstractController @@ -741,6 +969,16 @@ class ActivityController extends AbstractController
$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 @@ -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 @@ -765,10 +1009,22 @@ class ActivityController extends AbstractController
],
'torrent' =>
[
'id' => $activity->getTorrentId(),
'id' => $torrent->getId(),
'sensitive' => $torrent->isSensitive(),
'approved' => $torrent->isApproved(),
'name' => $torrentService->readTorrentFileByTorrentId(
$activity->getTorrentId()
$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 @@ -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 @@ -792,18 +1054,28 @@ class ActivityController extends AbstractController
],
'torrent' =>
[
'id' => $activity->getTorrentId(),
'id' => $torrent->getId(),
'sensitive' => $torrent->isSensitive(),
'approved' => $torrent->isApproved(),
'name' => $torrentService->readTorrentFileByTorrentId(
$activity->getTorrentId()
$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(

60
src/Controller/TorrentController.php

@ -55,6 +55,18 @@ class TorrentController extends AbstractController @@ -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 @@ -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 @@ -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)
@ -249,6 +265,8 @@ class TorrentController extends AbstractController @@ -249,6 +265,8 @@ class TorrentController extends AbstractController
[
'id' => $torrent->getId(),
'added' => $torrent->getAdded(),
'approved' => $torrent->isApproved(),
'sensitive' => $torrent->isSensitive(),
'file' =>
[
'name' => $file->getName(),
@ -341,8 +359,8 @@ class TorrentController extends AbstractController @@ -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 @@ -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)
@ -377,6 +395,8 @@ class TorrentController extends AbstractController @@ -377,6 +395,8 @@ class TorrentController extends AbstractController
[
'id' => $torrent->getId(),
'added' => $torrent->getAdded(),
'approved' => $torrent->isApproved(),
'sensitive' => $torrent->isSensitive(),
'file' =>
[
'name' => $file->getName(),
@ -1480,6 +1500,18 @@ class TorrentController extends AbstractController @@ -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 @@ -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(),

4
src/Controller/UserController.php

@ -208,6 +208,10 @@ class UserController extends AbstractController @@ -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,

15
templates/default/activity/event/torrent/add.html.twig

@ -6,9 +6,24 @@ @@ -6,9 +6,24 @@
<span class="margin-l-4-px">
{{ 'added torrent' | trans }}
</span>
{% if session.user.moderator or session.user.owner %}
<a href="{{ path('torrent_info', { torrentId : torrent.id }) }}">
{{ torrent.name }}
</a>
{% 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 %}
<a href="{{ path('torrent_info', { torrentId : torrent.id }) }}">
{{ torrent.name }}
</a>
{% endif %}
{% endif %}
</div>
<div class="column width-20 text-right">
{{ added | format_ago }}

15
templates/default/activity/event/torrent/approve/add.html.twig

@ -6,9 +6,24 @@ @@ -6,9 +6,24 @@
<span class="margin-l-4-px">
{{ 'approved torrent' | trans }}
</span>
{% if session.user.moderator or session.user.owner %}
<a href="{{ path('torrent_info', { torrentId : torrent.id }) }}">
{{ torrent.name }}
</a>
{% 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 %}
<a href="{{ path('torrent_info', { torrentId : torrent.id }) }}">
{{ torrent.name }}
</a>
{% endif %}
{% endif %}
</div>
<div class="column width-20 text-right">
{{ added | format_ago }}

15
templates/default/activity/event/torrent/approve/delete.html.twig

@ -6,9 +6,24 @@ @@ -6,9 +6,24 @@
<span class="margin-l-4-px">
{{ 'disapproved torrent' | trans }}
</span>
{% if session.user.moderator or session.user.owner %}
<a href="{{ path('torrent_info', { torrentId : torrent.id }) }}">
{{ torrent.name }}
</a>
{% 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 %}
<a href="{{ path('torrent_info', { torrentId : torrent.id }) }}">
{{ torrent.name }}
</a>
{% endif %}
{% endif %}
</div>
<div class="column width-20 text-right">
{{ added | format_ago }}

15
templates/default/activity/event/torrent/download/file/add.html.twig

@ -6,9 +6,24 @@ @@ -6,9 +6,24 @@
<span class="margin-x-l-px">
{{ 'downloaded torrent file' | trans }}
</span>
{% if session.user.moderator or session.user.owner %}
<a href="{{ path('torrent_info', { torrentId : torrent.id }) }}">
{{ torrent.name }}
</a>
{% 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 %}
<a href="{{ path('torrent_info', { torrentId : torrent.id }) }}">
{{ torrent.name }}
</a>
{% endif %}
{% endif %}
</div>
<div class="column width-20 text-right">
{{ added | format_ago }}

15
templates/default/activity/event/torrent/download/magnet/add.html.twig

@ -6,9 +6,24 @@ @@ -6,9 +6,24 @@
<span class="margin-l-4-px">
{{ 'downloaded magnet link' | trans }}
</span>
{% if session.user.moderator or session.user.owner %}
<a href="{{ path('torrent_info', { torrentId : torrent.id }) }}">
{{ torrent.name }}
</a>
{% 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 %}
<a href="{{ path('torrent_info', { torrentId : torrent.id }) }}">
{{ torrent.name }}
</a>
{% endif %}
{% endif %}
</div>
<div class="column width-20 text-right">
{{ added | format_ago }}

15
templates/default/activity/event/torrent/locales/add.html.twig

@ -14,9 +14,24 @@ @@ -14,9 +14,24 @@
#{{ torrent.locales.id }}
{% endif %}
{{ 'for torrent' | trans }}
{% if session.user.moderator or session.user.owner %}
<a href="{{ path('torrent_info', { torrentId : torrent.id }) }}">
{{ torrent.name }}
</a>
{% 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 %}
<a href="{{ path('torrent_info', { torrentId : torrent.id }) }}">
{{ torrent.name }}
</a>
{% endif %}
{% endif %}
</div>
<div class="column width-20 text-right">
{{ added | format_ago }}

15
templates/default/activity/event/torrent/locales/approve/add.html.twig

@ -12,9 +12,24 @@ @@ -12,9 +12,24 @@
#{{ torrent.locales.id }}
{% endif %}
{{ 'for torrent' | trans }}
{% if session.user.moderator or session.user.owner %}
<a href="{{ path('torrent_info', { torrentId : torrent.id }) }}">
{{ torrent.name }}
</a>
{% 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 %}
<a href="{{ path('torrent_info', { torrentId : torrent.id }) }}">
{{ torrent.name }}
</a>
{% endif %}
{% endif %}
</div>
<div class="column width-20 text-right">
{{ added | format_ago }}

15
templates/default/activity/event/torrent/locales/approve/delete.html.twig

@ -14,9 +14,24 @@ @@ -14,9 +14,24 @@
#{{ torrent.locales.id }}
{% endif %}
{{ 'for torrent' | trans }}
{% if session.user.moderator or session.user.owner %}
<a href="{{ path('torrent_info', { torrentId : torrent.id }) }}">
{{ torrent.name }}
</a>
{% 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 %}
<a href="{{ path('torrent_info', { torrentId : torrent.id }) }}">
{{ torrent.name }}
</a>
{% endif %}
{% endif %}
</div>
<div class="column width-20 text-right">
{{ added | format_ago }}

15
templates/default/activity/event/torrent/locales/delete.html.twig

@ -12,9 +12,24 @@ @@ -12,9 +12,24 @@
#{{ torrent.locales.id }}
{% endif %}
{{ 'for torrent' | trans }}
{% if session.user.moderator or session.user.owner %}
<a href="{{ path('torrent_info', { torrentId : torrent.id }) }}">
{{ torrent.name }}
</a>
{% 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 %}
<a href="{{ path('torrent_info', { torrentId : torrent.id }) }}">
{{ torrent.name }}
</a>
{% endif %}
{% endif %}
</div>
<div class="column width-20 text-right">
{{ added | format_ago }}

15
templates/default/activity/event/torrent/sensitive/add.html.twig

@ -12,9 +12,24 @@ @@ -12,9 +12,24 @@
#{{ torrent.sensitive.id }}
{% endif %}
{{ 'for torrent' | trans }}
{% if session.user.moderator or session.user.owner %}
<a href="{{ path('torrent_info', { torrentId : torrent.id }) }}">
{{ torrent.name }}
</a>
{% 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 %}
<a href="{{ path('torrent_info', { torrentId : torrent.id }) }}">
{{ torrent.name }}
</a>
{% endif %}
{% endif %}
</div>
<div class="column width-20 text-right">
{{ added | format_ago }}

15
templates/default/activity/event/torrent/sensitive/approve/add.html.twig

@ -12,9 +12,24 @@ @@ -12,9 +12,24 @@
#{{ torrent.sensitive.id }}
{% endif %}
{{ 'for torrent' | trans }}
{% if session.user.moderator or session.user.owner %}
<a href="{{ path('torrent_info', { torrentId : torrent.id }) }}">
{{ torrent.name }}
</a>
{% 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 %}
<a href="{{ path('torrent_info', { torrentId : torrent.id }) }}">
{{ torrent.name }}
</a>
{% endif %}
{% endif %}
</div>
<div class="column width-20 text-right">
{{ added | format_ago }}

15
templates/default/activity/event/torrent/sensitive/approve/delete.html.twig

@ -12,9 +12,24 @@ @@ -12,9 +12,24 @@
#{{ torrent.sensitive.id }}
{% endif %}
{{ 'for torrent' | trans }}
{% if session.user.moderator or session.user.owner %}
<a href="{{ path('torrent_info', { torrentId : torrent.id }) }}">
{{ torrent.name }}
</a>
{% 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 %}
<a href="{{ path('torrent_info', { torrentId : torrent.id }) }}">
{{ torrent.name }}
</a>
{% endif %}
{% endif %}
</div>
<div class="column width-20 text-right">
{{ added | format_ago }}

15
templates/default/activity/event/torrent/sensitive/delete.html.twig

@ -12,9 +12,24 @@ @@ -12,9 +12,24 @@
#{{ torrent.sensitive.id }}
{% endif %}
{{ 'for torrent' | trans }}
{% if session.user.moderator or session.user.owner %}
<a href="{{ path('torrent_info', { torrentId : torrent.id }) }}">
{{ torrent.name }}
</a>
{% 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 %}
<a href="{{ path('torrent_info', { torrentId : torrent.id }) }}">
{{ torrent.name }}
</a>
{% endif %}
{% endif %}
</div>
<div class="column width-20 text-right">
{{ added | format_ago }}

15
templates/default/activity/event/torrent/star/add.html.twig

@ -6,9 +6,24 @@ @@ -6,9 +6,24 @@
<span class="margin-l-4-px">
{{ 'added star for torrent' | trans }}
</span>
{% if session.user.moderator or session.user.owner %}
<a href="{{ path('torrent_info', { torrentId : torrent.id }) }}">
{{ torrent.name }}
</a>
{% 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 %}
<a href="{{ path('torrent_info', { torrentId : torrent.id }) }}">
{{ torrent.name }}
</a>
{% endif %}
{% endif %}
</div>
<div class="column width-20 text-right">
{{ added | format_ago }}

15
templates/default/activity/event/torrent/star/delete.html.twig

@ -7,9 +7,24 @@ @@ -7,9 +7,24 @@
<span class="margin-l-4-px">
{{ 'removed star from torrent' | trans }}
</span>
{% if session.user.moderator or session.user.owner %}
<a href="{{ path('torrent_info', { torrentId : torrent.id }) }}">
{{ torrent.name }}
</a>
{% 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 %}
<a href="{{ path('torrent_info', { torrentId : torrent.id }) }}">
{{ torrent.name }}
</a>
{% endif %}
{% endif %}
</div>
<div class="column width-20 text-right">
{{ added | format_ago }}

2
templates/default/activity/list.html.twig

@ -5,7 +5,7 @@ @@ -5,7 +5,7 @@
<div class="padding-16-px margin-y-8-px border-radius-3-px background-color-night">
{{ render(controller(
'App\\Controller\\ActivityController::event',
{ activity : activity }
{ user : session.user, activity : activity }
)) }}
</div>
{% endfor %}

2
templates/default/torrent/info.html.twig

@ -340,7 +340,7 @@ @@ -340,7 +340,7 @@
<div class="padding-16-px margin-y-8-px border-radius-3-px background-color-night">
{{ render(controller(
'App\\Controller\\ActivityController::event',
{ activity : activity }
{ user : session.user, activity : activity }
)) }}
</div>
{% endfor %}

18
templates/default/torrent/list.html.twig

@ -3,7 +3,7 @@ @@ -3,7 +3,7 @@
{% block main_content %}
{% if torrents %}
{% for torrent in torrents %}
<div class="padding-24-px margin-y-8-px border-radius-3-px background-color-night">
<div class="padding-24-px margin-y-8-px border-radius-3-px background-color-night{% if torrent.sensitive == true or torrent.approved == false %} opacity-06{% endif %}">
<a name="{{ torrent.id }}"></a>
<div class="margin-b-16-px">
<h2>
@ -12,11 +12,25 @@ @@ -12,11 +12,25 @@
</a>
</h2>
{% if torrent.scrape.leechers == 0 and torrent.scrape.leechers == 0 %}
<span class="label label-green margin-x-4-px font-size-10-px position-relative top--2 cursor-default"
<span class="label label-green margin-l-4-px font-size-10-px position-relative top--2 cursor-default"
title="{{ 'Active leechers waiting for seeders' | trans }}">
{{ 'wanted' | trans }}
</span>
{% endif %}
{% if torrent.approved == false %}
<sub class="margin-l-8-px float-right" title="{{ 'Waiting for approve' | trans }}">
<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" fill="currentColor" viewBox="0 0 16 16">
<path d="M2 1.5a.5.5 0 0 1 .5-.5h11a.5.5 0 0 1 0 1h-1v1a4.5 4.5 0 0 1-2.557 4.06c-.29.139-.443.377-.443.59v.7c0 .213.154.451.443.59A4.5 4.5 0 0 1 12.5 13v1h1a.5.5 0 0 1 0 1h-11a.5.5 0 1 1 0-1h1v-1a4.5 4.5 0 0 1 2.557-4.06c.29-.139.443-.377.443-.59v-.7c0-.213-.154-.451-.443-.59A4.5 4.5 0 0 1 3.5 3V2h-1a.5.5 0 0 1-.5-.5zm2.5.5v1a3.5 3.5 0 0 0 1.989 3.158c.533.256 1.011.791 1.011 1.491v.702c0 .7-.478 1.235-1.011 1.491A3.5 3.5 0 0 0 4.5 13v1h7v-1a3.5 3.5 0 0 0-1.989-3.158C8.978 9.586 8.5 9.052 8.5 8.351v-.702c0-.7.478-1.235 1.011-1.491A3.5 3.5 0 0 0 11.5 3V2h-7z"/>
</svg>
</sub>
{% endif %}
{% if torrent.sensitive == true %}
<sub class="margin-l-8-px float-right" title="{{ 'Content visible for non sensitive users only' | trans }}">
<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" fill="currentColor" viewBox="0 0 16 16">
<path d="m9.97 4.88.953 3.811C10.159 8.878 9.14 9 8 9c-1.14 0-2.158-.122-2.923-.309L6.03 4.88C6.635 4.957 7.3 5 8 5s1.365-.043 1.97-.12zm-.245-.978L8.97.88C8.718-.13 7.282-.13 7.03.88L6.275 3.9C6.8 3.965 7.382 4 8 4c.618 0 1.2-.036 1.725-.098zm4.396 8.613a.5.5 0 0 1 .037.96l-6 2a.5.5 0 0 1-.316 0l-6-2a.5.5 0 0 1 .037-.96l2.391-.598.565-2.257c.862.212 1.964.339 3.165.339s2.303-.127 3.165-.339l.565 2.257 2.391.598z"/>
</svg>
</sub>
{% endif %}
</div>
{% if torrent.keywords %}
<div class="margin-b-16-px">

2
templates/default/user/info.html.twig

@ -232,7 +232,7 @@ @@ -232,7 +232,7 @@
<div class="padding-x-24-px padding-y-16-px margin-y-8-px border-radius-3-px background-color-night">
{{ render(controller(
'App\\Controller\\ActivityController::event',
{ activity : activity }
{ user: session.user, activity : activity }
)) }}
</div>
{% endfor %}

Loading…
Cancel
Save