improve permission handling for quick entry controller (#3081)

This commit is contained in:
Kevin Papst
2022-01-20 22:24:19 +01:00
committed by GitHub
parent 49bb9980b8
commit 97c23f75dd
3 changed files with 75 additions and 20 deletions

View File

@@ -10,7 +10,6 @@
namespace App\EventSubscriber;
use App\Event\ConfigureMainMenuEvent;
use App\Timesheet\TrackingModeService;
use App\Twig\IconExtension;
use App\Utils\MenuItemModel;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
@@ -22,12 +21,10 @@ use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
final class MenuSubscriber implements EventSubscriberInterface
{
private $security;
private $trackingModeService;
public function __construct(AuthorizationCheckerInterface $security, TrackingModeService $trackingModeService)
public function __construct(AuthorizationCheckerInterface $security)
{
$this->security = $security;
$this->trackingModeService = $trackingModeService;
}
public static function getSubscribedEvents(): array
@@ -55,13 +52,10 @@ final class MenuSubscriber implements EventSubscriberInterface
$timesheets->setChildRoutes(['timesheet_export', 'timesheet_edit', 'timesheet_create', 'timesheet_multi_update']);
$menu->addItem($timesheets);
if ($auth->isGranted('weekly_own_timesheet') && $auth->isGranted('edit_own_timesheet')) {
$mode = $this->trackingModeService->getActiveMode();
if ($mode->canEditDuration() || $mode->canEditEnd()) {
$menu->addItem(
new MenuItemModel('quick_entry', 'quick_entry.title', 'quick_entry', [], $icons->icon('weekly-times'))
);
}
if ($auth->isGranted('quick-entry')) {
$menu->addItem(
new MenuItemModel('quick_entry', 'quick_entry.title', 'quick_entry', [], $icons->icon('weekly-times'))
);
}
$menu->addItem(