Browse Source

implement locales moderation methods

main
ghost 1 year ago
parent
commit
d34ff8ecc6
  1. 126
      src/Controller/TorrentController.php
  2. 30
      src/Service/TorrentService.php
  3. 30
      templates/default/torrent/edit/locales.html.twig

126
src/Controller/TorrentController.php

@ -104,7 +104,6 @@ class TorrentController extends AbstractController
'POST' 'POST'
] ]
)] )]
public function editLocales( public function editLocales(
Request $request, Request $request,
TranslatorInterface $translator, TranslatorInterface $translator,
@ -257,6 +256,7 @@ class TorrentController extends AbstractController
'default/torrent/edit/locales.html.twig', 'default/torrent/edit/locales.html.twig',
[ [
'torrentId' => $torrent->getId(), 'torrentId' => $torrent->getId(),
'moderator' => $user->isModerator(),
'locales' => explode('|', $this->getParameter('app.locales')), 'locales' => explode('|', $this->getParameter('app.locales')),
'editions' => $editions, 'editions' => $editions,
'form' => $form, 'form' => $form,
@ -264,6 +264,130 @@ class TorrentController extends AbstractController
); );
} }
#[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(),
'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(),
]
);
}
#[Route( #[Route(
'/{_locale}/submit/torrent', '/{_locale}/submit/torrent',
name: 'torrent_submit', name: 'torrent_submit',

30
src/Service/TorrentService.php

@ -158,6 +158,36 @@ class TorrentService
->findTorrentSensitive($torrentId); ->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 // Setters
public function add( public function add(
string $filepath, string $filepath,

30
templates/default/torrent/edit/locales.html.twig

@ -1,5 +1,5 @@
{% extends 'default/layout.html.twig' %} {% 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 %} {% block main_content %}
<div class="padding-24-px margin-y-8-px border-radius-3-px background-color-night"> <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"> <div class="margin-b-24-px padding-b-16-px border-bottom-default">
@ -67,18 +67,42 @@
</a> </a>
<div class="float-right"> <div class="float-right">
{% if edition.approved %} {% if edition.approved %}
<span title="{{'Approved'|trans }}"> {% 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"> <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"/> <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> </svg>
</span> </span>
{% endif %}
{% else %} {% else %}
<span title="{{'Waiting for approve'|trans }}"> {% 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"> <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"/> <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> </svg>
</span> </span>
{% endif %} {% 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>
</a>
{% endif %}
</div> </div>
</div> </div>
{% endfor %} {% endfor %}

Loading…
Cancel
Save