Browse Source

implement user moderation tools

main
ghost 1 year ago
parent
commit
8d258c677b
  1. 4
      public/asset/default/css/framework.css
  2. 179
      src/Controller/UserController.php
  3. 63
      src/Service/TorrentService.php
  4. 45
      src/Service/UserService.php
  5. 96
      templates/default/user/info.html.twig

4
public/asset/default/css/framework.css

@ -140,6 +140,10 @@ a.label-green:hover {
top: 2px; top: 2px;
} }
.line-height-20-px {
line-height: 20px;
}
.line-height-26-px { .line-height-26-px {
line-height: 26px; line-height: 26px;
} }

179
src/Controller/UserController.php

@ -11,6 +11,8 @@ use Symfony\Component\HttpFoundation\Request;
use App\Service\ActivityService; use App\Service\ActivityService;
use App\Service\UserService; use App\Service\UserService;
use App\Service\PageService;
use App\Service\TorrentService;
class UserController extends AbstractController 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 public function module(string $route = ''): Response
{ {
return $this->render( return $this->render(

63
src/Service/TorrentService.php

@ -280,6 +280,27 @@ class TorrentService
->getTorrentScrapeQueue(); ->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 // Torrent locale
public function getTorrentLocales(int $id): ?TorrentLocales public function getTorrentLocales(int $id): ?TorrentLocales
{ {
@ -352,6 +373,27 @@ class TorrentService
return $torrentLocales; 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 // Torrent sensitive
public function getTorrentSensitive(int $id): ?TorrentSensitive public function getTorrentSensitive(int $id): ?TorrentSensitive
{ {
@ -424,6 +466,27 @@ class TorrentService
return $torrentSensitive; 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 // Torrent star
public function findTorrentStar( public function findTorrentStar(
int $torrentId, int $torrentId,

45
src/Service/UserService.php

@ -162,4 +162,49 @@ class UserService
$this->entityManagerInterface->flush(); $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();
}
}
} }

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

@ -31,47 +31,95 @@
<table class="width-100"> <table class="width-100">
<tbody> <tbody>
<tr> <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>
<tr> <tr>
<td class="padding-t-16-px">{{ 'Joined'|trans }}</td> <td class="padding-t-16-px">{{ 'Joined'|trans }}</td>
<td class="padding-t-16-px">{{ user.added | format_ago }}</td> <td class="padding-t-16-px">{{ user.added | format_ago }}</td>
</tr> </tr>
<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>
<tr> <tr>
<td class="padding-t-16-px">{{ 'Status'|trans }}</td>
<td class="padding-t-16-px"> <td class="padding-t-16-px">
{% if user.status %} {{ 'Status' | trans }}
{{ 'active'|trans }} </td>
{% else %} <td class="padding-t-16-px">
{{ 'disabled'|trans }} {% if user.status %}
{% endif %} {{ '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> </td>
</tr> </tr>
<tr> <tr>
<td>{{ 'Approved'|trans }}</td>
<td> <td>
{% if user.approved %} {{ 'Approved' | trans }}
{{ 'yes'|trans }} </td>
{% else %} <td>
{{ 'no'|trans }} {% if user.approved %}
{% endif %} {{ '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> </td>
</tr> </tr>
<tr> <tr>
<td>{{ 'Moderator'|trans }}</td>
<td> <td>
{% if user.moderator %} {{ 'Moderator' | trans }}
{{ 'yes'|trans }} </td>
{% else %} <td>
{{ 'no'|trans }} {% if user.moderator %}
{% endif %} {{ '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> </td>
</tr> </tr>
<tr> <tr>
<td class="padding-b-8-px border-bottom-default text-right" colspan="2">{{ 'Settings'|trans }}</td> <td class="padding-y-8-px border-bottom-default text-right" colspan="2">{{ 'Settings'|trans }}</td>
</tr> </tr>
<tr> <tr>
<td class="padding-t-16-px">{{ 'Interface'|trans }}</td> <td class="padding-t-16-px">{{ 'Interface'|trans }}</td>
@ -81,7 +129,7 @@
</tr> </tr>
<tr> <tr>
<td class="width-20">{{ 'Content'|trans }}</td> <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 i, locale in user.locales %}{% if i > 0 %},{% endif %} {{ locale|locale_name(locale)|u.title }}{% endfor %}
{# {#
{% for locale in user.locales %} {% for locale in user.locales %}
@ -100,9 +148,9 @@
<td>{{ 'Sensitive'|trans }}</td> <td>{{ 'Sensitive'|trans }}</td>
<td> <td>
{% if user.sensitive %} {% if user.sensitive %}
{{ 'yes'|trans }} {{ 'Yes'|trans }}
{% else %} {% else %}
{{ 'no'|trans }} {{ 'No'|trans }}
{% endif %} {% endif %}
</td> </td>
</tr> </tr>

Loading…
Cancel
Save