mirror of
https://github.com/YGGverse/YGGtracker.git
synced 2026-03-31 17:15:38 +00:00
add torrent approved moderation tools
This commit is contained in:
parent
92c2a56bbf
commit
ed6c4ea415
8 changed files with 513 additions and 207 deletions
|
|
@ -372,6 +372,60 @@ class ActivityController extends AbstractController
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case $activity::EVENT_TORRENT_APPROVE_ADD:
|
||||||
|
|
||||||
|
return $this->render(
|
||||||
|
'default/activity/event/torrent/approve/add.html.twig',
|
||||||
|
[
|
||||||
|
'added' => $activity->getAdded(),
|
||||||
|
'user' =>
|
||||||
|
[
|
||||||
|
'id' => $activity->getUserId(),
|
||||||
|
'identicon' => $userService->identicon(
|
||||||
|
$userService->getUser(
|
||||||
|
$activity->getUserId()
|
||||||
|
)->getAddress()
|
||||||
|
)
|
||||||
|
],
|
||||||
|
'torrent' =>
|
||||||
|
[
|
||||||
|
'id' => $activity->getTorrentId(),
|
||||||
|
'name' => $torrentService->readTorrentFileByTorrentId(
|
||||||
|
$activity->getTorrentId()
|
||||||
|
)->getName()
|
||||||
|
]
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case $activity::EVENT_TORRENT_APPROVE_DELETE:
|
||||||
|
|
||||||
|
return $this->render(
|
||||||
|
'default/activity/event/torrent/approve/delete.html.twig',
|
||||||
|
[
|
||||||
|
'added' => $activity->getAdded(),
|
||||||
|
'user' =>
|
||||||
|
[
|
||||||
|
'id' => $activity->getUserId(),
|
||||||
|
'identicon' => $userService->identicon(
|
||||||
|
$userService->getUser(
|
||||||
|
$activity->getUserId()
|
||||||
|
)->getAddress()
|
||||||
|
)
|
||||||
|
],
|
||||||
|
'torrent' =>
|
||||||
|
[
|
||||||
|
'id' => $activity->getTorrentId(),
|
||||||
|
'name' => $torrentService->readTorrentFileByTorrentId(
|
||||||
|
$activity->getTorrentId()
|
||||||
|
)->getName()
|
||||||
|
]
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
// Torrent Download
|
// Torrent Download
|
||||||
case $activity::EVENT_TORRENT_DOWNLOAD_FILE_ADD:
|
case $activity::EVENT_TORRENT_DOWNLOAD_FILE_ADD:
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -76,7 +76,13 @@ class TorrentController extends AbstractController
|
||||||
$page = $request->get('page') ? (int) $request->get('page') : 1;
|
$page = $request->get('page') ? (int) $request->get('page') : 1;
|
||||||
|
|
||||||
// Render template
|
// Render template
|
||||||
return $this->render('default/torrent/info.html.twig', [
|
return $this->render('default/torrent/info.html.twig',
|
||||||
|
[
|
||||||
|
'user' =>
|
||||||
|
[
|
||||||
|
'id' => $user->getId(),
|
||||||
|
'moderator' => $user->isModerator()
|
||||||
|
],
|
||||||
'torrent' =>
|
'torrent' =>
|
||||||
[
|
[
|
||||||
'id' => $torrent->getId(),
|
'id' => $torrent->getId(),
|
||||||
|
|
@ -90,6 +96,7 @@ class TorrentController extends AbstractController
|
||||||
],
|
],
|
||||||
'locales' => $torrent->getLocales(),
|
'locales' => $torrent->getLocales(),
|
||||||
'sensitive' => $torrent->isSensitive(),
|
'sensitive' => $torrent->isSensitive(),
|
||||||
|
'approved' => $torrent->isApproved(),
|
||||||
'download' =>
|
'download' =>
|
||||||
[
|
[
|
||||||
'file' =>
|
'file' =>
|
||||||
|
|
@ -564,6 +571,82 @@ class TorrentController extends AbstractController
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#[Route(
|
||||||
|
'/{_locale}/torrent/{torrentId}/approve/toggle',
|
||||||
|
name: 'torrent_approve_toggle',
|
||||||
|
requirements:
|
||||||
|
[
|
||||||
|
'torrentId' => '\d+',
|
||||||
|
],
|
||||||
|
methods:
|
||||||
|
[
|
||||||
|
'GET'
|
||||||
|
]
|
||||||
|
)]
|
||||||
|
public function approve(
|
||||||
|
Request $request,
|
||||||
|
UserService $userService,
|
||||||
|
TorrentService $torrentService,
|
||||||
|
ActivityService $activityService
|
||||||
|
): Response
|
||||||
|
{
|
||||||
|
// Init user
|
||||||
|
$user = $this->initUser(
|
||||||
|
$request,
|
||||||
|
$userService,
|
||||||
|
$activityService
|
||||||
|
);
|
||||||
|
|
||||||
|
// Init torrent
|
||||||
|
if (!$torrent = $torrentService->getTorrent($request->get('torrentId')))
|
||||||
|
{
|
||||||
|
throw $this->createNotFoundException();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check permissions
|
||||||
|
if (!$user->isModerator())
|
||||||
|
{
|
||||||
|
// @TODO
|
||||||
|
throw new \Exception(
|
||||||
|
$translator->trans('Access denied')
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Register activity event
|
||||||
|
if (!$torrent->isApproved())
|
||||||
|
{
|
||||||
|
$activityService->addEventTorrentApproveAdd(
|
||||||
|
$user->getId(),
|
||||||
|
$torrent->getId(),
|
||||||
|
time()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$activityService->addEventTorrentApproveDelete(
|
||||||
|
$user->getId(),
|
||||||
|
$torrent->getId(),
|
||||||
|
time()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update approved
|
||||||
|
$torrentService->toggleTorrentApproved(
|
||||||
|
$torrent->getId()
|
||||||
|
);
|
||||||
|
|
||||||
|
// Redirect back to form
|
||||||
|
return $this->redirectToRoute(
|
||||||
|
'torrent_info',
|
||||||
|
[
|
||||||
|
'_locale' => $request->get('_locale'),
|
||||||
|
'torrentId' => $torrent->getId()
|
||||||
|
]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
// Torrent locales
|
// Torrent locales
|
||||||
#[Route(
|
#[Route(
|
||||||
'/{_locale}/torrent/{torrentId}/edit/locales/{torrentLocalesId}',
|
'/{_locale}/torrent/{torrentId}/edit/locales/{torrentLocalesId}',
|
||||||
|
|
|
||||||
|
|
@ -37,22 +37,25 @@ class Activity
|
||||||
/// Torrent
|
/// Torrent
|
||||||
public const EVENT_TORRENT_ADD = 2000;
|
public const EVENT_TORRENT_ADD = 2000;
|
||||||
|
|
||||||
public const EVENT_TORRENT_LOCALES_ADD = 2100;
|
public const EVENT_TORRENT_APPROVE_ADD = 1100;
|
||||||
public const EVENT_TORRENT_LOCALES_DELETE = 2101;
|
public const EVENT_TORRENT_APPROVE_DELETE = 1101;
|
||||||
public const EVENT_TORRENT_LOCALES_APPROVE_ADD = 2110;
|
|
||||||
public const EVENT_TORRENT_LOCALES_APPROVE_DELETE = 2111;
|
|
||||||
|
|
||||||
public const EVENT_TORRENT_SENSITIVE_ADD = 2200;
|
public const EVENT_TORRENT_LOCALES_ADD = 2200;
|
||||||
public const EVENT_TORRENT_SENSITIVE_DELETE = 2201;
|
public const EVENT_TORRENT_LOCALES_DELETE = 2201;
|
||||||
public const EVENT_TORRENT_SENSITIVE_APPROVE_ADD = 2210;
|
public const EVENT_TORRENT_LOCALES_APPROVE_ADD = 2210;
|
||||||
public const EVENT_TORRENT_SENSITIVE_APPROVE_DELETE = 2211;
|
public const EVENT_TORRENT_LOCALES_APPROVE_DELETE = 2211;
|
||||||
|
|
||||||
public const EVENT_TORRENT_STAR_ADD = 2300;
|
public const EVENT_TORRENT_SENSITIVE_ADD = 2300;
|
||||||
public const EVENT_TORRENT_STAR_DELETE = 2301;
|
public const EVENT_TORRENT_SENSITIVE_DELETE = 2301;
|
||||||
|
public const EVENT_TORRENT_SENSITIVE_APPROVE_ADD = 2310;
|
||||||
|
public const EVENT_TORRENT_SENSITIVE_APPROVE_DELETE = 2311;
|
||||||
|
|
||||||
public const EVENT_TORRENT_DOWNLOAD_FILE_ADD = 2400;
|
public const EVENT_TORRENT_STAR_ADD = 2400;
|
||||||
|
public const EVENT_TORRENT_STAR_DELETE = 2401;
|
||||||
|
|
||||||
public const EVENT_TORRENT_DOWNLOAD_MAGNET_ADD = 2500;
|
public const EVENT_TORRENT_DOWNLOAD_FILE_ADD = 2500;
|
||||||
|
|
||||||
|
public const EVENT_TORRENT_DOWNLOAD_MAGNET_ADD = 2600;
|
||||||
|
|
||||||
// ...
|
// ...
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -43,6 +43,9 @@ class ActivityService
|
||||||
// Torrents
|
// Torrents
|
||||||
Activity::EVENT_TORRENT_ADD,
|
Activity::EVENT_TORRENT_ADD,
|
||||||
|
|
||||||
|
Activity::EVENT_TORRENT_APPROVE_ADD,
|
||||||
|
Activity::EVENT_TORRENT_APPROVE_DELETE,
|
||||||
|
|
||||||
Activity::EVENT_TORRENT_LOCALES_ADD,
|
Activity::EVENT_TORRENT_LOCALES_ADD,
|
||||||
Activity::EVENT_TORRENT_LOCALES_DELETE,
|
Activity::EVENT_TORRENT_LOCALES_DELETE,
|
||||||
Activity::EVENT_TORRENT_LOCALES_APPROVE_ADD,
|
Activity::EVENT_TORRENT_LOCALES_APPROVE_ADD,
|
||||||
|
|
@ -191,6 +194,30 @@ class ActivityService
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case Activity::EVENT_TORRENT_APPROVE_ADD:
|
||||||
|
|
||||||
|
$events
|
||||||
|
[
|
||||||
|
$this->translatorInterface->trans('Torrents')
|
||||||
|
]
|
||||||
|
[
|
||||||
|
$this->translatorInterface->trans('Approved')
|
||||||
|
] = $code;
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Activity::EVENT_TORRENT_APPROVE_DELETE:
|
||||||
|
|
||||||
|
$events
|
||||||
|
[
|
||||||
|
$this->translatorInterface->trans('Torrents')
|
||||||
|
]
|
||||||
|
[
|
||||||
|
$this->translatorInterface->trans('Disapproved')
|
||||||
|
] = $code;
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
/// Torrent locales
|
/// Torrent locales
|
||||||
case Activity::EVENT_TORRENT_LOCALES_ADD:
|
case Activity::EVENT_TORRENT_LOCALES_ADD:
|
||||||
|
|
||||||
|
|
@ -760,6 +787,66 @@ class ActivityService
|
||||||
return $activity;
|
return $activity;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function addEventTorrentApproveAdd(
|
||||||
|
int $userId,
|
||||||
|
int $torrentId,
|
||||||
|
int $added
|
||||||
|
): ?Activity
|
||||||
|
{
|
||||||
|
$activity = new Activity();
|
||||||
|
|
||||||
|
$activity->setEvent(
|
||||||
|
Activity::EVENT_TORRENT_APPROVE_ADD
|
||||||
|
);
|
||||||
|
|
||||||
|
$activity->setUserId(
|
||||||
|
$userId
|
||||||
|
);
|
||||||
|
|
||||||
|
$activity->setTorrentId(
|
||||||
|
$torrentId
|
||||||
|
);
|
||||||
|
|
||||||
|
$activity->setAdded(
|
||||||
|
$added
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->entityManagerInterface->persist($activity);
|
||||||
|
$this->entityManagerInterface->flush();
|
||||||
|
|
||||||
|
return $activity;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function addEventTorrentApproveDelete(
|
||||||
|
int $userId,
|
||||||
|
int $torrentId,
|
||||||
|
int $added
|
||||||
|
): ?Activity
|
||||||
|
{
|
||||||
|
$activity = new Activity();
|
||||||
|
|
||||||
|
$activity->setEvent(
|
||||||
|
Activity::EVENT_TORRENT_APPROVE_DELETE
|
||||||
|
);
|
||||||
|
|
||||||
|
$activity->setUserId(
|
||||||
|
$userId
|
||||||
|
);
|
||||||
|
|
||||||
|
$activity->setTorrentId(
|
||||||
|
$torrentId
|
||||||
|
);
|
||||||
|
|
||||||
|
$activity->setAdded(
|
||||||
|
$added
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->entityManagerInterface->persist($activity);
|
||||||
|
$this->entityManagerInterface->flush();
|
||||||
|
|
||||||
|
return $activity;
|
||||||
|
}
|
||||||
|
|
||||||
/// Torrent Download
|
/// Torrent Download
|
||||||
public function addEventTorrentDownloadFileAdd(
|
public function addEventTorrentDownloadFileAdd(
|
||||||
int $userId,
|
int $userId,
|
||||||
|
|
|
||||||
|
|
@ -298,6 +298,30 @@ class TorrentService
|
||||||
return $torrent;
|
return $torrent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function toggleTorrentApproved(
|
||||||
|
int $torrentId
|
||||||
|
): ?Torrent
|
||||||
|
{
|
||||||
|
$torrent = $this->getTorrent($torrentId);
|
||||||
|
|
||||||
|
$torrent->setApproved(
|
||||||
|
!$torrent->isApproved() // toggle current value
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->entityManagerInterface->persist($torrent);
|
||||||
|
$this->entityManagerInterface->flush();
|
||||||
|
|
||||||
|
$this->updateTorrentLocales(
|
||||||
|
$torrent->getId()
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->updateTorrentSensitive(
|
||||||
|
$torrent->getId()
|
||||||
|
);
|
||||||
|
|
||||||
|
return $torrent;
|
||||||
|
}
|
||||||
|
|
||||||
public function getTorrentScrapeQueue(): ?Torrent
|
public function getTorrentScrapeQueue(): ?Torrent
|
||||||
{
|
{
|
||||||
return $this->entityManagerInterface
|
return $this->entityManagerInterface
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,16 @@
|
||||||
|
<div class="row">
|
||||||
|
<div class="column width-80">
|
||||||
|
<a href="{{ path('user_info', { userId : user.id }) }}">
|
||||||
|
<img class="border-radius-50 border-color-default vertical-align-middle" src="{{ user.identicon }}" alt="{{ 'identicon' | trans }}" />
|
||||||
|
</a>
|
||||||
|
<span class="margin-l-4-px">
|
||||||
|
{{ 'approved torrent' | trans }}
|
||||||
|
</span>
|
||||||
|
<a href="{{ path('torrent_info', { torrentId : torrent.id }) }}">
|
||||||
|
{{ torrent.name }}
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
<div class="column width-20 text-right">
|
||||||
|
{{ added | format_ago }}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
@ -0,0 +1,16 @@
|
||||||
|
<div class="row">
|
||||||
|
<div class="column width-80">
|
||||||
|
<a href="{{ path('user_info', { userId : user.id }) }}">
|
||||||
|
<img class="border-radius-50 border-color-default vertical-align-middle" src="{{ user.identicon }}" alt="{{ 'identicon' | trans }}" />
|
||||||
|
</a>
|
||||||
|
<span class="margin-l-4-px">
|
||||||
|
{{ 'disapproved torrent' | trans }}
|
||||||
|
</span>
|
||||||
|
<a href="{{ path('torrent_info', { torrentId : torrent.id }) }}">
|
||||||
|
{{ torrent.name }}
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
<div class="column width-20 text-right">
|
||||||
|
{{ added | format_ago }}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
@ -23,7 +23,6 @@
|
||||||
{% block title %}{{ file.name }} - {{ 'Torrent' | trans }} #{{ torrent.id }}{% if pagination.page > 1 %} - {{ 'Page' | trans }} {{ pagination.page }}{% endif %} - {{ name }}{% endblock %}
|
{% block title %}{{ file.name }} - {{ 'Torrent' | trans }} #{{ torrent.id }}{% if pagination.page > 1 %} - {{ 'Page' | trans }} {{ pagination.page }}{% endif %} - {{ 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="padding-b-16-px">
|
|
||||||
<h1 class="display-block text-center margin-b-16-px">
|
<h1 class="display-block text-center margin-b-16-px">
|
||||||
{{ file.name }}
|
{{ file.name }}
|
||||||
{#{{ 'Torrent' | trans }} #{{ torrent.id }}#}
|
{#{{ 'Torrent' | trans }} #{{ torrent.id }}#}
|
||||||
|
|
@ -72,26 +71,51 @@
|
||||||
{{ torrent.star.total }}
|
{{ torrent.star.total }}
|
||||||
</sup>
|
</sup>
|
||||||
</div>
|
</div>
|
||||||
{#
|
<table class="width-100">
|
||||||
|
<tbody>
|
||||||
<a class="float-right margin-l-8-px" href="#" title="{{ 'Magnet'|trans }}">
|
{% if user.moderator %}
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="padding-y-8-px border-bottom-default text-right">
|
||||||
|
{{ 'Moderation' | trans }}
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td class="padding-t-16-px">
|
||||||
|
{{ 'Approved' | trans }}
|
||||||
|
</td>
|
||||||
|
<td class="padding-t-16-px">
|
||||||
|
{% if torrent.approved %}
|
||||||
|
{{ 'Yes' | trans }}
|
||||||
|
<a class="float-right" href="{{ path('torrent_approve_toggle', { torrentId : torrent.id }) }}" title="{{ 'Toggle' | 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="M8 1a7 7 0 0 0-7 7v3h4V8a3 3 0 0 1 6 0v3h4V8a7 7 0 0 0-7-7Zm7 11h-4v3h4v-3ZM5 12H1v3h4v-3ZM0 8a8 8 0 1 1 16 0v8h-6V8a2 2 0 1 0-4 0v8H0V8Z"/>
|
<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>
|
</svg>
|
||||||
</a>
|
</a>
|
||||||
#}
|
{% else %}
|
||||||
</div>
|
{{ 'No' | trans }}
|
||||||
|
<a class="float-right text-color-red" href="{{ path('torrent_approve_toggle', { torrentId : torrent.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 %}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
{% endif %}
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
<div class="padding-y-8-px border-bottom-default text-right">
|
<div class="padding-y-8-px border-bottom-default text-right">
|
||||||
{{ 'Common' | trans }}
|
{{ 'Common' | trans }}
|
||||||
</div>
|
</div>
|
||||||
<div class="padding-t-16-px">
|
</td>
|
||||||
<table class="width-100">
|
</tr>
|
||||||
<tbody>
|
|
||||||
<tr>
|
<tr>
|
||||||
<td>
|
<td class="padding-t-16-px">
|
||||||
{{ 'ID' | trans }}
|
{{ 'ID' | trans }}
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td class="padding-t-16-px">
|
||||||
#{{ torrent.id }}
|
#{{ torrent.id }}
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
@ -239,7 +263,6 @@
|
||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
|
||||||
<div class="padding-y-8-px border-bottom-default text-right">
|
<div class="padding-y-8-px border-bottom-default text-right">
|
||||||
{{ 'Files' | trans }}
|
{{ 'Files' | trans }}
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue