allow users delete own content

This commit is contained in:
ghost 2023-10-08 14:35:34 +03:00
parent d34ff8ecc6
commit cbda078c38
2 changed files with 33 additions and 29 deletions

View file

@ -256,10 +256,14 @@ class TorrentController extends AbstractController
'default/torrent/edit/locales.html.twig',
[
'torrentId' => $torrent->getId(),
'moderator' => $user->isModerator(),
'locales' => explode('|', $this->getParameter('app.locales')),
'editions' => $editions,
'form' => $form,
'session' =>
[
'moderator' => $user->isModerator(),
'owner' => $user->getId() === $torrentLocales->getUserId(),
]
]
);
}
@ -289,15 +293,6 @@ class TorrentController extends AbstractController
$request->getClientIp()
);
// Check permissions
if (!$user->isModerator())
{
// @TODO
throw new \Exception(
$translator->trans('Access denied')
);
}
// Init torrent
if (!$torrent = $torrentService->getTorrent($request->get('torrentId')))
{
@ -310,6 +305,15 @@ class TorrentController extends AbstractController
throw $this->createNotFoundException();
}
// Check permissions
if (!$user->isModerator())
{
// @TODO
throw new \Exception(
$translator->trans('Access denied')
);
}
// Update approved
$torrentService->toggleTorrentLocalesApproved(
$torrentLocales->getId()
@ -351,15 +355,6 @@ class TorrentController extends AbstractController
$request->getClientIp()
);
// Check permissions
if (!$user->isModerator())
{
// @TODO
throw new \Exception(
$translator->trans('Access denied')
);
}
// Init torrent
if (!$torrent = $torrentService->getTorrent($request->get('torrentId')))
{
@ -372,6 +367,15 @@ class TorrentController extends AbstractController
throw $this->createNotFoundException();
}
// Check permissions
if (!($user->isModerator() || $user->getId() === $torrentLocales->getUserId()))
{
// @TODO
throw new \Exception(
$translator->trans('Access denied')
);
}
// Update approved
$torrentService->deleteTorrentLocales(
$torrentLocales->getId()