Skip to content

Commit

Permalink
fix invitation removal permisions (display) / add tab fragment load /…
Browse files Browse the repository at this point in the history
… add event invitation (not email) removal
  • Loading branch information
Kerrialn committed Jan 15, 2024
1 parent 73a6edb commit d28a48e
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 31 deletions.
19 changes: 17 additions & 2 deletions assets/app.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import './bootstrap.js';
import {Tooltip, Toast} from 'bootstrap'
import {Tooltip, Toast, Tab} from 'bootstrap'
import 'bootstrap';
import 'chartjs-adapter-date-fns';
/*
Expand All @@ -13,14 +13,29 @@ import 'chartjs-adapter-date-fns';
import './styles/app.scss';



document.addEventListener('turbo:load', function (e) {
let tooltipTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="tooltip"]'))
let tooltipList = tooltipTriggerList.map(function (tooltipTriggerEl) {
return new Tooltip(tooltipTriggerEl)
});
});


document.addEventListener('turbo:load', function () {
const tabLinks = document.querySelectorAll('a[role="tab"]');
for (const tabLink of tabLinks) {
tabLink.addEventListener('click', function (event) {
event.preventDefault();
history.pushState({}, 'Page title', tabLink.href);
});
}

const selectedTab = window.location.hash;
console.log(`a[href='${selectedTab}}']`)
let tabTrigger = new Tab(document.querySelector(`a[href='${selectedTab}']`));
tabTrigger.show();
});

document.addEventListener('turbo:load', function (e) {
const toastElList = document.querySelectorAll('.toast')
const toastList = [...toastElList].map(toastEl => new Toast(toastEl, {}));
Expand Down
28 changes: 25 additions & 3 deletions src/Controller/Controller/Event/EventInvitationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
namespace App\Controller\Controller\Event;

use App\Entity\Event\EventEmailInvitation;
use App\Entity\Event\EventInvitation;
use App\Enum\FlashEnum;
use App\Repository\Event\EventInvitationRepository;
use App\Repository\EventEmailInvitationRepository;
use App\Security\Voter\EventVoter;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
Expand All @@ -20,15 +22,16 @@ class EventInvitationController extends AbstractController
{
public function __construct(
private readonly EventEmailInvitationRepository $emailInvitationRepository,
private readonly EventInvitationRepository $eventInvitationRepository,
private readonly TranslatorInterface $translator,
) {
}

/**
* @throws TransportExceptionInterface
*/
#[Route('/remove/{id}/{token}', name: 'remove_email_invitation', methods: [Request::METHOD_GET])]
public function remove(EventEmailInvitation $emailInvitation, string $token): Response
#[Route('/remove/email/{id}/{token}', name: 'remove_email_invitation', methods: [Request::METHOD_GET])]
public function removeEmailInvitation(EventEmailInvitation $emailInvitation, string $token): Response
{
if ($this->isCsrfTokenValid(id: 'remove-invitation', token: $token)) {
$event = $emailInvitation->getEvent();
Expand All @@ -37,7 +40,26 @@ public function remove(EventEmailInvitation $emailInvitation, string $token): Re
$this->addFlash(FlashEnum::MESSAGE->value, $this->translator->trans('changes-saved'));
return $this->redirectToRoute('show_event', [
'id' => $event->getId(),
'_fragment' => 'invited-users',
'_fragment' => 'invited',
]);
}
return $this->redirectToRoute('app_login');
}

/**
* @throws TransportExceptionInterface
*/
#[Route('/remove/{id}/{token}', name: 'remove_invitation', methods: [Request::METHOD_GET])]
public function removeInvitation(EventInvitation $eventInvitation, string $token): Response
{
if ($this->isCsrfTokenValid(id: 'remove-invitation', token: $token)) {
$event = $eventInvitation->getEvent();
$this->isGranted(EventVoter::EDIT_EVENT, $eventInvitation->getEvent());
$this->eventInvitationRepository->remove($eventInvitation, true);
$this->addFlash(FlashEnum::MESSAGE->value, $this->translator->trans('changes-saved'));
return $this->redirectToRoute('show_event', [
'id' => $event->getId(),
'_fragment' => 'invited',
]);
}
return $this->redirectToRoute('app_login');
Expand Down
60 changes: 34 additions & 26 deletions templates/events/show.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -178,41 +178,45 @@
<div class="nav nav-pills nav-justified" id="pills-tab"
role="tablist">
<div class="nav-item" role="presentation">
<button class="nav-link active d-flex justify-content-between align-items-center"
id="pills-home-tab" data-bs-toggle="pill" data-bs-target="#going"
type="button" role="tab" aria-controls="pills-home"
aria-selected="true">
<a class="nav-link active d-flex justify-content-between align-items-center"
id="pills-home-tab" data-bs-toggle="pill"
data-bs-target="#going"
href="#going"
type="button" role="tab" aria-controls="pills-home"
aria-selected="true">
<span class="fw-bold me-3">{{ event.isComplete ? 'went'|trans|capitalize : 'going'|trans|capitalize }}</span>
<span class="fw-bold badge rounded-pill text-bg-dark">{{ event.eventOrganisers.count + event.eventParticipants.count|compact_notation }}</span>
</button>
</a>
</div>
{% if not event.isComplete %}
<div class="nav-item" role="presentation">
<button class="nav-link d-flex justify-content-between align-items-center"
id="invited-tab"
data-bs-toggle="pill" data-bs-target="#invited"
type="button" role="tab" aria-controls="pills-invited"
aria-selected="true">
<a class="nav-link d-flex justify-content-between align-items-center"
id="invited-tab"
href="#invited"
data-bs-toggle="pill" data-bs-target="#invited"
type="button" role="tab" aria-controls="pills-invited"
aria-selected="true">
<span class="fw-bold me-3">{{ 'invited'|trans|capitalize }}</span>
<span class="fw-bold badge rounded-pill text-bg-dark">{{ event.eventEmailInvitations.count + event.eventInvitations.count|compact_notation }}</span>
</button>
</a>
</div>
<div class="nav-item" role="presentation">
<button class="nav-link d-flex justify-content-between align-items-center"
id="requests-tab" data-bs-toggle="pill"
data-bs-target="#requests"
type="button" role="tab" aria-controls="pills-requested"
aria-selected="true">
<a class="nav-link d-flex justify-content-between align-items-center"
id="requests-tab" data-bs-toggle="pill"
href="#requests"
data-bs-target="#requests"
type="button" role="tab" aria-controls="pills-requested"
aria-selected="true">
<span class="fw-bold me-3">{{ 'requests'|trans|capitalize }}</span>
<span class="fw-bold badge rounded-pill text-bg-dark">{{ event.eventRequests.count|compact_notation }}</span>
</button>
</a>
</div>
{% endif %}
</div>
</div>
<div class="tab-content" id="pills-tabContent">
<div class="tab-pane fade show active" id="going" role="tabpanel"
aria-labelledby="pills-home-tab"
aria-labelledby="pills-going-tab"
tabindex="0">
<div class="list-group rounded-bottom list-group-flush">
{% for organiser in event.eventOrganisers %}
Expand Down Expand Up @@ -273,10 +277,12 @@
</div>
</div>
<div>
<a href="#"
class="link-danger">
<div class="bi bi-x-lg fs-4 text-danger"></div>
</a>
{% if app.user and app.user|has_event_permission(event, 'role.event.manager') or app.user and app.user|has_event_permission(event, 'role.event.admin') %}
<a href="{{ path('remove_invitation', {id: invitation.id, token: csrf_token('remove-invitation')}) }}"
class="link-danger">
<div class="bi bi-x-lg fs-4 text-danger"></div>
</a>
{% endif %}
</div>
</div>
{% elseif invitation|instanceof('App\\Entity\\Event\\EventEmailInvitation') %}
Expand All @@ -293,10 +299,12 @@
</div>
</div>
<div>
<a href="{{ path('remove_email_invitation', {id: invitation.id, token: csrf_token('remove-invitation')}) }}"
class="link-danger">
<div class="bi bi-x-lg fs-4 text-danger"></div>
</a>
{% if app.user and app.user|has_event_permission(event, 'role.event.manager') or app.user and app.user|has_event_permission(event, 'role.event.admin') %}
<a href="{{ path('remove_email_invitation', {id: invitation.id, token: csrf_token('remove-invitation')}) }}"
class="link-danger">
<div class="bi bi-x-lg fs-4 text-danger"></div>
</a>
{% endif %}
</div>
</div>
{% endif %}
Expand Down

0 comments on commit d28a48e

Please sign in to comment.