links can now be deleted

This commit is contained in:
overflowerror 2021-01-08 18:17:16 +01:00
parent daf162b373
commit f2a8ed241b
6 changed files with 99 additions and 32 deletions

View file

@ -24,4 +24,27 @@
.customNavbar {
margin-right: auto;
}
.no-content {
margin-left: 3%;
}
.deleteToggle:after {
display: none;
}
.deleteConfirm {
text-align: center;
padding: 1vw;
font-size: 1vw;
min-width: 14vw;
}
.deleteButton {
color: red;
}
.no-wrap {
white-space: nowrap;
}

View file

@ -134,23 +134,4 @@
.length {
top: calc(9 / 16 * 100% + 4% + 5%);
}
.no-content {
margin-left: 3%;
}
.deleteToggle:after {
display: none;
}
.deleteConfirm {
text-align: center;
padding: 1vw;
font-size: 1vw;
min-width: 14vw;
}
.deleteButton {
color: red;
}

View file

@ -26,6 +26,7 @@ use Symfony\Component\Routing\Annotation\Route;
class DashboardController extends AbstractController
{
public const DELETE_VIDEO_CSRF_TOKEN_ID = "delete-video";
public const DELETE_LINK_CSRF_TOKEN_ID = "delete-link";
private $userService;
private $videoService;
@ -107,7 +108,7 @@ class DashboardController extends AbstractController
/**
* @Route("/video/delete", name="app_video_delete", methods={"POST"})
*/
public function delete(Request $request): Response
public function deleteVideo(Request $request): Response
{
$token = $request->request->get("csrfToken");
$videoId = $request->request->get("videoId");
@ -241,4 +242,36 @@ class DashboardController extends AbstractController
"form" => $form->createView()
]);
}
/**
* @Route("/links/delete", name="app_link_delete", methods={"POST"})
*/
public function deleteLink(Request $request): Response
{
$token = $request->request->get("csrfToken");
$linkId = $request->request->get("linkId");
if (!$this->isCsrfTokenValid(self::DELETE_LINK_CSRF_TOKEN_ID, $token)) {
throw new AccessDeniedHttpException();
}
if (!$linkId) {
throw new BadRequestHttpException();
}
try {
$linkId = $this->uuidMapper->fromString($linkId);
} catch (ConversionException $e) {
throw new BadRequestHttpException();
}
$link = $this->videoLinkService->get($linkId);
if ($link == null || $link->getCreator() != $this->userService->getLoggedInUser()) {
throw new AccessDeniedHttpException();
}
$this->videoLinkService->delete($link);
return $this->redirectToRoute("app_links");
}
}

View file

@ -58,4 +58,10 @@ class VideoLinkRepository extends ServiceEntityRepository
{
$this->_em->flush();
}
public function delete(VideoLink $link)
{
$this->_em->remove($link);
$this->_em->flush();
}
}

View file

@ -58,4 +58,9 @@ class VideoLinkService
{
$this->videoLinkRepository->save($videoLink);
}
public function delete(VideoLink $link)
{
$this->videoLinkRepository->delete($link);
}
}

View file

@ -13,12 +13,10 @@
create a link for.
</div>
{% else %}
{% set deleteCsrfToken = csrf_token(constant("App\\Controller\\DashboardController::DELETE_LINK_CSRF_TOKEN_ID")) %}
<div class="links bg-light shadow-5">
<table class="table table-hover">
<tr>
<td>
<input type="checkbox">
</td>
<td></td>
<th>
Video
@ -39,14 +37,10 @@
Time left
</th>
<th>
Link
</th>
</tr>
{% for link in links %}
<tr>
<td>
<input type="checkbox">
</td>
<td>
{% if not link.viewable() %}
<i class="fas fa-exclamation-circle"></i>
@ -91,11 +85,36 @@
-
{% endif %}
</td>
<td>
<button class="btn btn-primary btn-floating" onclick="clipboard('{{ url("app_watch_page", {
linkId: link.customId,
videoId: link.video.customId
}) }}')"><i class="fas fa-clipboard"></i></button>
<td class="no-wrap">
<div class="btn-group" role="group">
<button class="btn btn-link" onclick="clipboard('{{ url("app_watch_page", {
linkId: link.customId,
videoId: link.video.customId
}) }}')"><i class="fas fa-clipboard"></i>
</button>
<form action="{{ path("app_link_delete") }}" method="POST">
<input type="hidden" name="linkId" value="{{ link.customId }}">
<input type="hidden" name="csrfToken" value="{{ deleteCsrfToken }}">
<button class="btn btn-link dropdown-toggle deleteToggle" style="color: red;"
id="{{ link.customId }}-deleteDropDown"
data-mdb-toggle="dropdown"
aria-expanded="false"
onclick="">
<i class="fas fa-trash-alt"></i>
</button>
<div class="dropdown-menu dropdown-menu-end deleteConfirm"
id="{{ link.customId }}-deleteDropDownMenu"
aria-labelledby="{{ link.customId }}-deleteDropDown">
Do you really want to delete this link?<br/>
<button class="btn btn-link deleteButton">YES</button>
<button class="btn btn-primary" onclick="removeClass('show', [
'#{{ link.customId }}-deleteDropDown',
'#{{ link.customId }}-deleteDropDownMenu'
]); return false;">NO
</button>
</div>
</form>
</div>
</td>
</tr>
{% endfor %}