mirror of
https://github.com/YGGverse/YGGtracker.git
synced 2025-01-10 23:17:53 +00:00
implement locales moderation methods
This commit is contained in:
parent
fafca13b32
commit
d34ff8ecc6
@ -104,7 +104,6 @@ class TorrentController extends AbstractController
|
||||
'POST'
|
||||
]
|
||||
)]
|
||||
|
||||
public function editLocales(
|
||||
Request $request,
|
||||
TranslatorInterface $translator,
|
||||
@ -256,10 +255,135 @@ class TorrentController extends AbstractController
|
||||
return $this->render(
|
||||
'default/torrent/edit/locales.html.twig',
|
||||
[
|
||||
'torrentId' => $torrent->getId(),
|
||||
'moderator' => $user->isModerator(),
|
||||
'locales' => explode('|', $this->getParameter('app.locales')),
|
||||
'editions' => $editions,
|
||||
'form' => $form,
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
#[Route(
|
||||
'/{_locale}/torrent/{torrentId}/approve/locales/{torrentLocalesId}',
|
||||
name: 'torrent_approve_locales',
|
||||
requirements:
|
||||
[
|
||||
'torrentId' => '\d+',
|
||||
'torrentLocalesId' => '\d+',
|
||||
],
|
||||
methods:
|
||||
[
|
||||
'GET'
|
||||
]
|
||||
)]
|
||||
public function approveLocales(
|
||||
Request $request,
|
||||
TranslatorInterface $translator,
|
||||
UserService $userService,
|
||||
TorrentService $torrentService
|
||||
): Response
|
||||
{
|
||||
// Init user
|
||||
$user = $userService->init(
|
||||
$request->getClientIp()
|
||||
);
|
||||
|
||||
// Check permissions
|
||||
if (!$user->isModerator())
|
||||
{
|
||||
// @TODO
|
||||
throw new \Exception(
|
||||
$translator->trans('Access denied')
|
||||
);
|
||||
}
|
||||
|
||||
// Init torrent
|
||||
if (!$torrent = $torrentService->getTorrent($request->get('torrentId')))
|
||||
{
|
||||
throw $this->createNotFoundException();
|
||||
}
|
||||
|
||||
// Init torrent locales
|
||||
if (!$torrentLocales = $torrentService->getTorrentLocales($request->get('torrentLocalesId')))
|
||||
{
|
||||
throw $this->createNotFoundException();
|
||||
}
|
||||
|
||||
// Update approved
|
||||
$torrentService->toggleTorrentLocalesApproved(
|
||||
$torrentLocales->getId()
|
||||
);
|
||||
|
||||
// Redirect to info page created
|
||||
return $this->redirectToRoute(
|
||||
'torrent_edit_locales',
|
||||
[
|
||||
'_locale' => $request->get('_locale'),
|
||||
'torrentId' => $torrent->getId(),
|
||||
'locales' => explode('|', $this->getParameter('app.locales')),
|
||||
'editions' => $editions,
|
||||
'form' => $form,
|
||||
'torrentLocalesId' => $torrentLocales->getId(),
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
#[Route(
|
||||
'/{_locale}/torrent/{torrentId}/delete/locales/{torrentLocalesId}',
|
||||
name: 'torrent_delete_locales',
|
||||
requirements:
|
||||
[
|
||||
'torrentId' => '\d+',
|
||||
'torrentLocalesId' => '\d+',
|
||||
],
|
||||
methods:
|
||||
[
|
||||
'GET'
|
||||
]
|
||||
)]
|
||||
public function deleteLocales(
|
||||
Request $request,
|
||||
TranslatorInterface $translator,
|
||||
UserService $userService,
|
||||
TorrentService $torrentService
|
||||
): Response
|
||||
{
|
||||
// Init user
|
||||
$user = $userService->init(
|
||||
$request->getClientIp()
|
||||
);
|
||||
|
||||
// Check permissions
|
||||
if (!$user->isModerator())
|
||||
{
|
||||
// @TODO
|
||||
throw new \Exception(
|
||||
$translator->trans('Access denied')
|
||||
);
|
||||
}
|
||||
|
||||
// Init torrent
|
||||
if (!$torrent = $torrentService->getTorrent($request->get('torrentId')))
|
||||
{
|
||||
throw $this->createNotFoundException();
|
||||
}
|
||||
|
||||
// Init torrent locales
|
||||
if (!$torrentLocales = $torrentService->getTorrentLocales($request->get('torrentLocalesId')))
|
||||
{
|
||||
throw $this->createNotFoundException();
|
||||
}
|
||||
|
||||
// Update approved
|
||||
$torrentService->deleteTorrentLocales(
|
||||
$torrentLocales->getId()
|
||||
);
|
||||
|
||||
// Redirect to info page created
|
||||
return $this->redirectToRoute(
|
||||
'torrent_edit_locales',
|
||||
[
|
||||
'_locale' => $request->get('_locale'),
|
||||
'torrentId' => $torrent->getId(),
|
||||
'torrentLocalesId' => $torrentLocales->getId(),
|
||||
]
|
||||
);
|
||||
}
|
||||
|
@ -158,6 +158,36 @@ class TorrentService
|
||||
->findTorrentSensitive($torrentId);
|
||||
}
|
||||
|
||||
// Update
|
||||
public function toggleTorrentLocalesApproved(
|
||||
int $id
|
||||
): ?TorrentLocales
|
||||
{
|
||||
$torrentLocales = $this->getTorrentLocales($id);
|
||||
|
||||
$torrentLocales->setApproved(
|
||||
!$torrentLocales->isApproved() // toggle current value
|
||||
);
|
||||
|
||||
$this->entityManagerInterface->persist($torrentLocales);
|
||||
$this->entityManagerInterface->flush();
|
||||
|
||||
return $torrentLocales;
|
||||
}
|
||||
|
||||
// Delete
|
||||
public function deleteTorrentLocales(
|
||||
int $id
|
||||
): ?TorrentLocales
|
||||
{
|
||||
$torrentLocales = $this->getTorrentLocales($id);
|
||||
|
||||
$this->entityManagerInterface->remove($torrentLocales);
|
||||
$this->entityManagerInterface->flush();
|
||||
|
||||
return $torrentLocales;
|
||||
}
|
||||
|
||||
// Setters
|
||||
public function add(
|
||||
string $filepath,
|
||||
|
@ -1,5 +1,5 @@
|
||||
{% extends 'default/layout.html.twig' %}
|
||||
{% block title %}{{'Edit torrent locales'|trans }} - {{ name }}{% endblock %}
|
||||
{% block title %}{{'Torrent'|trans }} #{{ torrentId }} - {{'Edit locales'|trans }} - {{ name }}{% endblock %}
|
||||
{% block main_content %}
|
||||
<div class="padding-24-px margin-y-8-px border-radius-3-px background-color-night">
|
||||
<div class="margin-b-24-px padding-b-16-px border-bottom-default">
|
||||
@ -67,17 +67,41 @@
|
||||
</a>
|
||||
<div class="float-right">
|
||||
{% if edition.approved %}
|
||||
<span title="{{'Approved'|trans }}">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 0 16 16">
|
||||
<path d="M16 8A8 8 0 1 1 0 8a8 8 0 0 1 16 0zm-3.97-3.03a.75.75 0 0 0-1.08.022L7.477 9.417 5.384 7.323a.75.75 0 0 0-1.06 1.06L6.97 11.03a.75.75 0 0 0 1.079-.02l3.992-4.99a.75.75 0 0 0-.01-1.05z"/>
|
||||
</svg>
|
||||
</span>
|
||||
{% if moderator %}
|
||||
<a href="{{ path('torrent_approve_locales', { torrentId : torrentId, torrentLocalesId : edition.id }) }}" title="{{ 'Approved' | trans }}">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 0 16 16">
|
||||
<path d="M16 8A8 8 0 1 1 0 8a8 8 0 0 1 16 0zm-3.97-3.03a.75.75 0 0 0-1.08.022L7.477 9.417 5.384 7.323a.75.75 0 0 0-1.06 1.06L6.97 11.03a.75.75 0 0 0 1.079-.02l3.992-4.99a.75.75 0 0 0-.01-1.05z"/>
|
||||
</svg>
|
||||
</a>
|
||||
{% else %}
|
||||
<span title="{{ 'Approved' | trans }}">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 0 16 16">
|
||||
<path d="M16 8A8 8 0 1 1 0 8a8 8 0 0 1 16 0zm-3.97-3.03a.75.75 0 0 0-1.08.022L7.477 9.417 5.384 7.323a.75.75 0 0 0-1.06 1.06L6.97 11.03a.75.75 0 0 0 1.079-.02l3.992-4.99a.75.75 0 0 0-.01-1.05z"/>
|
||||
</svg>
|
||||
</span>
|
||||
{% endif %}
|
||||
{% else %}
|
||||
<span title="{{'Waiting for approve'|trans }}">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-hourglass" 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"/>
|
||||
{% if moderator %}
|
||||
<a href="{{ path('torrent_approve_locales', { torrentId : torrentId, torrentLocalesId : edition.id }) }}" title="{{ 'Approved' | trans }}">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-hourglass" 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>
|
||||
</a>
|
||||
{% else %}
|
||||
<span title="{{ 'Waiting for approve' | trans }}">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-hourglass" 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>
|
||||
</span>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
{% if moderator %}
|
||||
<a class="margin-l-8-px text-color-red" href="{{ path('torrent_delete_locales', { torrentId : torrentId, torrentLocalesId : edition.id }) }}" title="{{ 'Delete' | trans }}">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-x-circle" viewBox="0 0 16 16">
|
||||
<path d="M8 15A7 7 0 1 1 8 1a7 7 0 0 1 0 14zm0 1A8 8 0 1 0 8 0a8 8 0 0 0 0 16z"/>
|
||||
<path d="M4.646 4.646a.5.5 0 0 1 .708 0L8 7.293l2.646-2.647a.5.5 0 0 1 .708.708L8.707 8l2.647 2.646a.5.5 0 0 1-.708.708L8 8.707l-2.646 2.647a.5.5 0 0 1-.708-.708L7.293 8 4.646 5.354a.5.5 0 0 1 0-.708z"/>
|
||||
</svg>
|
||||
</span>
|
||||
</a>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
|
Loading…
Reference in New Issue
Block a user