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;
|
||||
|
||||
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
|
||||
case $activity::EVENT_TORRENT_DOWNLOAD_FILE_ADD:
|
||||
|
||||
|
|
|
|||
|
|
@ -76,7 +76,13 @@ class TorrentController extends AbstractController
|
|||
$page = $request->get('page') ? (int) $request->get('page') : 1;
|
||||
|
||||
// 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' =>
|
||||
[
|
||||
'id' => $torrent->getId(),
|
||||
|
|
@ -90,6 +96,7 @@ class TorrentController extends AbstractController
|
|||
],
|
||||
'locales' => $torrent->getLocales(),
|
||||
'sensitive' => $torrent->isSensitive(),
|
||||
'approved' => $torrent->isApproved(),
|
||||
'download' =>
|
||||
[
|
||||
'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
|
||||
#[Route(
|
||||
'/{_locale}/torrent/{torrentId}/edit/locales/{torrentLocalesId}',
|
||||
|
|
|
|||
|
|
@ -37,22 +37,25 @@ class Activity
|
|||
/// Torrent
|
||||
public const EVENT_TORRENT_ADD = 2000;
|
||||
|
||||
public const EVENT_TORRENT_LOCALES_ADD = 2100;
|
||||
public const EVENT_TORRENT_LOCALES_DELETE = 2101;
|
||||
public const EVENT_TORRENT_LOCALES_APPROVE_ADD = 2110;
|
||||
public const EVENT_TORRENT_LOCALES_APPROVE_DELETE = 2111;
|
||||
public const EVENT_TORRENT_APPROVE_ADD = 1100;
|
||||
public const EVENT_TORRENT_APPROVE_DELETE = 1101;
|
||||
|
||||
public const EVENT_TORRENT_SENSITIVE_ADD = 2200;
|
||||
public const EVENT_TORRENT_SENSITIVE_DELETE = 2201;
|
||||
public const EVENT_TORRENT_SENSITIVE_APPROVE_ADD = 2210;
|
||||
public const EVENT_TORRENT_SENSITIVE_APPROVE_DELETE = 2211;
|
||||
public const EVENT_TORRENT_LOCALES_ADD = 2200;
|
||||
public const EVENT_TORRENT_LOCALES_DELETE = 2201;
|
||||
public const EVENT_TORRENT_LOCALES_APPROVE_ADD = 2210;
|
||||
public const EVENT_TORRENT_LOCALES_APPROVE_DELETE = 2211;
|
||||
|
||||
public const EVENT_TORRENT_STAR_ADD = 2300;
|
||||
public const EVENT_TORRENT_STAR_DELETE = 2301;
|
||||
public const EVENT_TORRENT_SENSITIVE_ADD = 2300;
|
||||
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
|
||||
Activity::EVENT_TORRENT_ADD,
|
||||
|
||||
Activity::EVENT_TORRENT_APPROVE_ADD,
|
||||
Activity::EVENT_TORRENT_APPROVE_DELETE,
|
||||
|
||||
Activity::EVENT_TORRENT_LOCALES_ADD,
|
||||
Activity::EVENT_TORRENT_LOCALES_DELETE,
|
||||
Activity::EVENT_TORRENT_LOCALES_APPROVE_ADD,
|
||||
|
|
@ -191,6 +194,30 @@ class ActivityService
|
|||
|
||||
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
|
||||
case Activity::EVENT_TORRENT_LOCALES_ADD:
|
||||
|
||||
|
|
@ -760,6 +787,66 @@ class ActivityService
|
|||
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
|
||||
public function addEventTorrentDownloadFileAdd(
|
||||
int $userId,
|
||||
|
|
|
|||
|
|
@ -298,6 +298,30 @@ class TorrentService
|
|||
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
|
||||
{
|
||||
return $this->entityManagerInterface
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue