mirror of
https://github.com/YGGverse/YGGtracker.git
synced 2026-03-31 17:15:38 +00:00
implement user moderation tools
This commit is contained in:
parent
42cef39589
commit
8d258c677b
5 changed files with 365 additions and 26 deletions
|
|
@ -11,6 +11,8 @@ use Symfony\Component\HttpFoundation\Request;
|
|||
|
||||
use App\Service\ActivityService;
|
||||
use App\Service\UserService;
|
||||
use App\Service\PageService;
|
||||
use App\Service\TorrentService;
|
||||
|
||||
class UserController extends AbstractController
|
||||
{
|
||||
|
|
@ -307,6 +309,183 @@ class UserController extends AbstractController
|
|||
);
|
||||
}
|
||||
|
||||
#[Route(
|
||||
'/{_locale}/user/{userId}/moderator/toggle',
|
||||
name: 'user_moderator_toggle',
|
||||
requirements:
|
||||
[
|
||||
'userId' => '\d+',
|
||||
],
|
||||
methods:
|
||||
[
|
||||
'GET'
|
||||
]
|
||||
)]
|
||||
public function toggleModerator(
|
||||
Request $request,
|
||||
TranslatorInterface $translator,
|
||||
UserService $userService
|
||||
): Response
|
||||
{
|
||||
// Init user
|
||||
$user = $userService->init(
|
||||
$request->getClientIp()
|
||||
);
|
||||
|
||||
if (!$user->isModerator())
|
||||
{
|
||||
// @TODO
|
||||
throw new \Exception(
|
||||
$translator->trans('Access denied')
|
||||
);
|
||||
}
|
||||
|
||||
// Init target user
|
||||
if (!$userTarget = $userService->getUser($request->get('userId')))
|
||||
{
|
||||
throw $this->createNotFoundException();
|
||||
}
|
||||
|
||||
// Update
|
||||
$userService->toggleUserModerator(
|
||||
$userTarget->getId()
|
||||
);
|
||||
|
||||
// Redirect to info page created
|
||||
return $this->redirectToRoute(
|
||||
'user_info',
|
||||
[
|
||||
'_locale' => $request->get('_locale'),
|
||||
'userId' => $userTarget->getId()
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
#[Route(
|
||||
'/{_locale}/user/{userId}/status/toggle',
|
||||
name: 'user_status_toggle',
|
||||
requirements:
|
||||
[
|
||||
'userId' => '\d+',
|
||||
],
|
||||
methods:
|
||||
[
|
||||
'GET'
|
||||
]
|
||||
)]
|
||||
public function toggleStatus(
|
||||
Request $request,
|
||||
TranslatorInterface $translator,
|
||||
UserService $userService
|
||||
): Response
|
||||
{
|
||||
// Init user
|
||||
$user = $userService->init(
|
||||
$request->getClientIp()
|
||||
);
|
||||
|
||||
if (!$user->isModerator())
|
||||
{
|
||||
// @TODO
|
||||
throw new \Exception(
|
||||
$translator->trans('Access denied')
|
||||
);
|
||||
}
|
||||
|
||||
// Init target user
|
||||
if (!$userTarget = $userService->getUser($request->get('userId')))
|
||||
{
|
||||
throw $this->createNotFoundException();
|
||||
}
|
||||
|
||||
// Update
|
||||
$userService->toggleUserStatus(
|
||||
$userTarget->getId()
|
||||
);
|
||||
|
||||
// Redirect to info page created
|
||||
return $this->redirectToRoute(
|
||||
'user_info',
|
||||
[
|
||||
'_locale' => $request->get('_locale'),
|
||||
'userId' => $userTarget->getId()
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
#[Route(
|
||||
'/{_locale}/user/{userId}/approved/toggle',
|
||||
name: 'user_approved_toggle',
|
||||
requirements:
|
||||
[
|
||||
'userId' => '\d+',
|
||||
],
|
||||
methods:
|
||||
[
|
||||
'GET'
|
||||
]
|
||||
)]
|
||||
public function toggleApproved(
|
||||
Request $request,
|
||||
TranslatorInterface $translator,
|
||||
UserService $userService,
|
||||
PageService $pageService,
|
||||
TorrentService $torrentService
|
||||
): Response
|
||||
{
|
||||
// Init user
|
||||
$user = $userService->init(
|
||||
$request->getClientIp()
|
||||
);
|
||||
|
||||
if (!$user->isModerator())
|
||||
{
|
||||
// @TODO
|
||||
throw new \Exception(
|
||||
$translator->trans('Access denied')
|
||||
);
|
||||
}
|
||||
|
||||
// Init target user
|
||||
if (!$userTarget = $userService->getUser($request->get('userId')))
|
||||
{
|
||||
throw $this->createNotFoundException();
|
||||
}
|
||||
|
||||
// Auto-approve all related content on user approve
|
||||
if (!$userTarget->isApproved())
|
||||
{
|
||||
$torrentService->setTorrentsApprovedByUserId(
|
||||
$userTarget->getId(),
|
||||
true
|
||||
);
|
||||
|
||||
$torrentService->setTorrentLocalesApprovedByUserId(
|
||||
$userTarget->getId(),
|
||||
true
|
||||
);
|
||||
|
||||
$torrentService->setTorrentSensitivesApprovedByUserId(
|
||||
$userTarget->getId(),
|
||||
true
|
||||
);
|
||||
}
|
||||
|
||||
// Update user approved
|
||||
$userService->toggleUserApproved(
|
||||
$userTarget->getId()
|
||||
);
|
||||
|
||||
// Redirect to info page created
|
||||
return $this->redirectToRoute(
|
||||
'user_info',
|
||||
[
|
||||
'_locale' => $request->get('_locale'),
|
||||
'userId' => $userTarget->getId()
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
public function module(string $route = ''): Response
|
||||
{
|
||||
return $this->render(
|
||||
|
|
|
|||
|
|
@ -280,6 +280,27 @@ class TorrentService
|
|||
->getTorrentScrapeQueue();
|
||||
}
|
||||
|
||||
public function setTorrentsApprovedByUserId(
|
||||
int $userId,
|
||||
bool $value
|
||||
): void
|
||||
{
|
||||
foreach ($this->entityManagerInterface
|
||||
->getRepository(Torrent::class)
|
||||
->findBy(
|
||||
[
|
||||
'userId' => $userId
|
||||
]) as $torrent)
|
||||
{
|
||||
$torrent->setApproved(
|
||||
$value
|
||||
);
|
||||
|
||||
$this->entityManagerInterface->persist($torrent);
|
||||
$this->entityManagerInterface->flush();
|
||||
}
|
||||
}
|
||||
|
||||
// Torrent locale
|
||||
public function getTorrentLocales(int $id): ?TorrentLocales
|
||||
{
|
||||
|
|
@ -352,6 +373,27 @@ class TorrentService
|
|||
return $torrentLocales;
|
||||
}
|
||||
|
||||
public function setTorrentLocalesApprovedByUserId(
|
||||
int $userId,
|
||||
bool $value
|
||||
): void
|
||||
{
|
||||
foreach ($this->entityManagerInterface
|
||||
->getRepository(TorrentLocales::class)
|
||||
->findBy(
|
||||
[
|
||||
'userId' => $userId
|
||||
]) as $torrentLocales)
|
||||
{
|
||||
$torrentLocales->setApproved(
|
||||
$value
|
||||
);
|
||||
|
||||
$this->entityManagerInterface->persist($torrentLocales);
|
||||
$this->entityManagerInterface->flush();
|
||||
}
|
||||
}
|
||||
|
||||
// Torrent sensitive
|
||||
public function getTorrentSensitive(int $id): ?TorrentSensitive
|
||||
{
|
||||
|
|
@ -424,6 +466,27 @@ class TorrentService
|
|||
return $torrentSensitive;
|
||||
}
|
||||
|
||||
public function setTorrentSensitivesApprovedByUserId(
|
||||
int $userId,
|
||||
bool $value
|
||||
): void
|
||||
{
|
||||
foreach ($this->entityManagerInterface
|
||||
->getRepository(TorrentSensitive::class)
|
||||
->findBy(
|
||||
[
|
||||
'userId' => $userId
|
||||
]) as $torrentSensitive)
|
||||
{
|
||||
$torrentSensitive->setApproved(
|
||||
$value
|
||||
);
|
||||
|
||||
$this->entityManagerInterface->persist($torrentSensitive);
|
||||
$this->entityManagerInterface->flush();
|
||||
}
|
||||
}
|
||||
|
||||
// Torrent star
|
||||
public function findTorrentStar(
|
||||
int $torrentId,
|
||||
|
|
|
|||
|
|
@ -162,4 +162,49 @@ class UserService
|
|||
$this->entityManagerInterface->flush();
|
||||
}
|
||||
}
|
||||
|
||||
public function toggleUserModerator(
|
||||
int $userId
|
||||
): void
|
||||
{
|
||||
if ($user = $this->getUser($userId))
|
||||
{
|
||||
$user->setModerator(
|
||||
!$user->isModerator()
|
||||
);
|
||||
|
||||
$this->entityManagerInterface->persist($user);
|
||||
$this->entityManagerInterface->flush();
|
||||
}
|
||||
}
|
||||
|
||||
public function toggleUserStatus(
|
||||
int $userId
|
||||
): void
|
||||
{
|
||||
if ($user = $this->getUser($userId))
|
||||
{
|
||||
$user->setStatus(
|
||||
!$user->isStatus()
|
||||
);
|
||||
|
||||
$this->entityManagerInterface->persist($user);
|
||||
$this->entityManagerInterface->flush();
|
||||
}
|
||||
}
|
||||
|
||||
public function toggleUserApproved(
|
||||
int $userId
|
||||
): void
|
||||
{
|
||||
if ($user = $this->getUser($userId))
|
||||
{
|
||||
$user->setApproved(
|
||||
!$user->isApproved()
|
||||
);
|
||||
|
||||
$this->entityManagerInterface->persist($user);
|
||||
$this->entityManagerInterface->flush();
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue