mirror of
https://github.com/YGGverse/YGGtracker.git
synced 2025-01-24 05:34:26 +00:00
implement user moderation tools
This commit is contained in:
parent
42cef39589
commit
8d258c677b
@ -140,6 +140,10 @@ a.label-green:hover {
|
||||
top: 2px;
|
||||
}
|
||||
|
||||
.line-height-20-px {
|
||||
line-height: 20px;
|
||||
}
|
||||
|
||||
.line-height-26-px {
|
||||
line-height: 26px;
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
@ -31,47 +31,95 @@
|
||||
<table class="width-100">
|
||||
<tbody>
|
||||
<tr>
|
||||
<td class="padding-b-8-px border-bottom-default text-right" colspan="2">{{ 'Common'|trans }}</td>
|
||||
<td class="padding-y-8-px border-bottom-default text-right" colspan="2">{{ 'Common'|trans }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="padding-t-16-px">{{ 'Joined'|trans }}</td>
|
||||
<td class="padding-t-16-px">{{ user.added | format_ago }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="padding-b-8-px border-bottom-default text-right" colspan="2">{{ 'Access'|trans }}</td>
|
||||
<td class="padding-y-8-px border-bottom-default text-right" colspan="2">{{ 'Access'|trans }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="padding-t-16-px">{{ 'Status'|trans }}</td>
|
||||
<td class="padding-t-16-px">
|
||||
{% if user.status %}
|
||||
{{ 'active'|trans }}
|
||||
{% else %}
|
||||
{{ 'disabled'|trans }}
|
||||
{% endif %}
|
||||
{{ 'Status' | trans }}
|
||||
</td>
|
||||
<td class="padding-t-16-px">
|
||||
{% if user.status %}
|
||||
{{ 'Active' | trans }}
|
||||
{% if user.moderator %}
|
||||
<a class="float-right" href="{{ path('user_status_toggle', { userId : user.id }) }}" title="{{ 'Toggle' | trans }}">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 0 16 16">
|
||||
<path d="M5 3a5 5 0 0 0 0 10h6a5 5 0 0 0 0-10H5zm6 9a4 4 0 1 1 0-8 4 4 0 0 1 0 8z"/>
|
||||
</svg>
|
||||
</a>
|
||||
{% endif %}
|
||||
{% else %}
|
||||
{{ 'Disabled' | trans }}
|
||||
{% if user.moderator %}
|
||||
<a class="float-right text-color-red" href="{{ path('user_status_toggle', { userId : user.id }) }}" title="{{ 'Toggle' | trans }}">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 0 16 16">
|
||||
<path d="M11 4a4 4 0 0 1 0 8H8a4.992 4.992 0 0 0 2-4 4.992 4.992 0 0 0-2-4h3zm-6 8a4 4 0 1 1 0-8 4 4 0 0 1 0 8zM0 8a5 5 0 0 0 5 5h6a5 5 0 0 0 0-10H5a5 5 0 0 0-5 5z"/>
|
||||
</svg>
|
||||
</a>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>{{ 'Approved'|trans }}</td>
|
||||
<td>
|
||||
{% if user.approved %}
|
||||
{{ 'yes'|trans }}
|
||||
{% else %}
|
||||
{{ 'no'|trans }}
|
||||
{% endif %}
|
||||
{{ 'Approved' | trans }}
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>{{ 'Moderator'|trans }}</td>
|
||||
<td>
|
||||
{% if user.moderator %}
|
||||
{{ 'yes'|trans }}
|
||||
{% else %}
|
||||
{{ 'no'|trans }}
|
||||
{% endif %}
|
||||
{% if user.approved %}
|
||||
{{ 'Yes'| trans }}
|
||||
{% if user.moderator %}
|
||||
<a class="float-right" href="{{ path('user_approved_toggle', { userId : user.id }) }}" title="{{ 'Toggle' | trans }}">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 0 16 16">
|
||||
<path d="M5 3a5 5 0 0 0 0 10h6a5 5 0 0 0 0-10H5zm6 9a4 4 0 1 1 0-8 4 4 0 0 1 0 8z"/>
|
||||
</svg>
|
||||
</a>
|
||||
{% endif %}
|
||||
{% else %}
|
||||
{{ 'No'| trans }}
|
||||
{% if user.moderator %}
|
||||
<a class="float-right text-color-red" href="{{ path('user_approved_toggle', { userId : user.id }) }}" title="{{ 'Toggle' | trans }}">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 0 16 16">
|
||||
<path d="M11 4a4 4 0 0 1 0 8H8a4.992 4.992 0 0 0 2-4 4.992 4.992 0 0 0-2-4h3zm-6 8a4 4 0 1 1 0-8 4 4 0 0 1 0 8zM0 8a5 5 0 0 0 5 5h6a5 5 0 0 0 0-10H5a5 5 0 0 0-5 5z"/>
|
||||
</svg>
|
||||
</a>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="padding-b-8-px border-bottom-default text-right" colspan="2">{{ 'Settings'|trans }}</td>
|
||||
<td>
|
||||
{{ 'Moderator' | trans }}
|
||||
</td>
|
||||
<td>
|
||||
{% if user.moderator %}
|
||||
{{ 'Yes'| trans }}
|
||||
{% if user.moderator %}
|
||||
<a class="float-right" href="{{ path('user_moderator_toggle', { userId : user.id }) }}" title="{{ 'Toggle' | trans }}">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 0 16 16">
|
||||
<path d="M5 3a5 5 0 0 0 0 10h6a5 5 0 0 0 0-10H5zm6 9a4 4 0 1 1 0-8 4 4 0 0 1 0 8z"/>
|
||||
</svg>
|
||||
</a>
|
||||
{% endif %}
|
||||
{% else %}
|
||||
{{ 'No'| trans }}
|
||||
{% if user.moderator %}
|
||||
<a class="float-right text-color-red" href="{{ path('user_moderator_toggle', { userId : user.id }) }}" title="{{ 'Toggle' | trans }}">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 0 16 16">
|
||||
<path d="M11 4a4 4 0 0 1 0 8H8a4.992 4.992 0 0 0 2-4 4.992 4.992 0 0 0-2-4h3zm-6 8a4 4 0 1 1 0-8 4 4 0 0 1 0 8zM0 8a5 5 0 0 0 5 5h6a5 5 0 0 0 0-10H5a5 5 0 0 0-5 5z"/>
|
||||
</svg>
|
||||
</a>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="padding-y-8-px border-bottom-default text-right" colspan="2">{{ 'Settings'|trans }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="padding-t-16-px">{{ 'Interface'|trans }}</td>
|
||||
@ -81,7 +129,7 @@
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="width-20">{{ 'Content'|trans }}</td>
|
||||
<td class="width-80">
|
||||
<td class="width-80 line-height-20-px">
|
||||
{% for i, locale in user.locales %}{% if i > 0 %},{% endif %} {{ locale|locale_name(locale)|u.title }}{% endfor %}
|
||||
{#
|
||||
{% for locale in user.locales %}
|
||||
@ -100,9 +148,9 @@
|
||||
<td>{{ 'Sensitive'|trans }}</td>
|
||||
<td>
|
||||
{% if user.sensitive %}
|
||||
{{ 'yes'|trans }}
|
||||
{{ 'Yes'|trans }}
|
||||
{% else %}
|
||||
{{ 'no'|trans }}
|
||||
{{ 'No'|trans }}
|
||||
{% endif %}
|
||||
</td>
|
||||
</tr>
|
||||
|
Loading…
x
Reference in New Issue
Block a user