refactored page actions to event subscriber (#2420)
This commit is contained in:
@@ -10,10 +10,14 @@
|
||||
namespace App\EventSubscriber\Actions;
|
||||
|
||||
use App\Constants;
|
||||
use App\Event\PageActionsEvent;
|
||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
|
||||
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
|
||||
|
||||
/**
|
||||
* Base class for all listeners, which adds the pages default toolbars.
|
||||
*/
|
||||
abstract class AbstractActionsSubscriber implements EventSubscriberInterface
|
||||
{
|
||||
private $auth;
|
||||
@@ -39,4 +43,21 @@ abstract class AbstractActionsSubscriber implements EventSubscriberInterface
|
||||
{
|
||||
return Constants::HOMEPAGE . '/documentation/' . $url;
|
||||
}
|
||||
|
||||
public static function getSubscribedEvents(): array
|
||||
{
|
||||
return [
|
||||
'actions.' . static::getActionName() => ['onActions', 1000],
|
||||
];
|
||||
}
|
||||
|
||||
public static function getActionName(): string
|
||||
{
|
||||
throw new \Exception('You need to overwrite getActionName() or getSubscribedEvents() in ' . static::class);
|
||||
}
|
||||
|
||||
public function onActions(PageActionsEvent $event): void
|
||||
{
|
||||
// non abstract - so the usage is completely optional
|
||||
}
|
||||
}
|
||||
|
||||
58
src/EventSubscriber/Actions/AbstractTimesheetSubscriber.php
Normal file
58
src/EventSubscriber/Actions/AbstractTimesheetSubscriber.php
Normal file
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Kimai time-tracking app.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace App\EventSubscriber\Actions;
|
||||
|
||||
use App\Entity\Timesheet;
|
||||
use App\Event\PageActionsEvent;
|
||||
|
||||
abstract class AbstractTimesheetSubscriber extends AbstractActionsSubscriber
|
||||
{
|
||||
protected function timesheetActions(PageActionsEvent $event, string $routeListing, string $routeEdit): void
|
||||
{
|
||||
$payload = $event->getPayload();
|
||||
|
||||
/** @var Timesheet $timesheet */
|
||||
$timesheet = $payload['timesheet'];
|
||||
if (!$event->isIndexView()) {
|
||||
$event->addBack($this->path($routeListing));
|
||||
}
|
||||
|
||||
if ($timesheet->getId() !== null) {
|
||||
if ($this->isGranted('edit', $timesheet)) {
|
||||
$class = $event->isView('edit') ? '' : 'modal-ajax-form';
|
||||
$event->addAction('edit', ['url' => $this->path($routeEdit, ['id' => $timesheet->getId()]), 'class' => $class]);
|
||||
}
|
||||
|
||||
if ($timesheet->isRunning() && $this->isGranted('stop', $timesheet)) {
|
||||
$event->addAction('stop', ['url' => $this->path('stop_timesheet', ['id' => $timesheet->getId()]), 'class' => 'api-link', 'attr' => ['data-event' => 'kimai.timesheetStop kimai.timesheetUpdate', 'data-method' => 'PATCH', 'data-msg-error' => 'timesheet.stop.error', 'data-msg-success' => 'timesheet.stop.success']]);
|
||||
}
|
||||
|
||||
if (!$timesheet->isRunning() && $this->isGranted('start', $timesheet)) {
|
||||
$event->addAction('repeat', ['url' => $this->path('restart_timesheet', ['id' => $timesheet->getId()]), 'class' => 'api-link', 'attr' => ['data-payload' => '{"copy": "all"}', 'data-event' => 'kimai.timesheetStart kimai.timesheetUpdate', 'data-method' => 'PATCH', 'data-msg-error' => 'timesheet.start.error', 'data-msg-success' => 'timesheet.start.success']]);
|
||||
}
|
||||
|
||||
if ($this->isGranted('duplicate', $timesheet)) {
|
||||
$event->addAction('copy', ['url' => $this->path('duplicate_timesheet', ['id' => $timesheet->getId()]), 'class' => 'api-link', 'attr' => ['data-payload' => '{"copy": "all"}', 'data-event' => 'kimai.timesheetStart kimai.timesheetUpdate', 'data-method' => 'PATCH', 'data-msg-error' => 'action.update.error', 'data-msg-success' => 'action.update.success']]);
|
||||
}
|
||||
|
||||
if ($event->countActions() > 0) {
|
||||
$event->addDivider();
|
||||
}
|
||||
|
||||
if ($event->isIndexView() && $this->isGranted('delete', $timesheet)) {
|
||||
$event->addAction('trash', ['url' => $this->path('delete_timesheet', ['id' => $timesheet->getId()]), 'class' => 'api-link', 'attr' => ['data-event' => 'kimai.timesheetDelete kimai.timesheetUpdate', 'data-method' => 'DELETE', 'data-question' => 'confirm.delete', 'data-msg-error' => 'action.delete.error', 'data-msg-success' => 'action.delete.success']]);
|
||||
}
|
||||
}
|
||||
|
||||
if (!$event->isIndexView()) {
|
||||
$event->addHelp($this->documentationLink('timesheet.html'));
|
||||
}
|
||||
}
|
||||
}
|
||||
39
src/EventSubscriber/Actions/AbstractTimesheetsSubscriber.php
Normal file
39
src/EventSubscriber/Actions/AbstractTimesheetsSubscriber.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Kimai time-tracking app.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace App\EventSubscriber\Actions;
|
||||
|
||||
use App\Event\PageActionsEvent;
|
||||
use App\Export\ServiceExport;
|
||||
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
|
||||
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
|
||||
|
||||
abstract class AbstractTimesheetsSubscriber extends AbstractActionsSubscriber
|
||||
{
|
||||
private $serviceExport;
|
||||
|
||||
public function __construct(AuthorizationCheckerInterface $security, UrlGeneratorInterface $urlGenerator, ServiceExport $serviceExport)
|
||||
{
|
||||
parent::__construct($security, $urlGenerator);
|
||||
$this->serviceExport = $serviceExport;
|
||||
}
|
||||
|
||||
protected function addExporter(PageActionsEvent $event, string $routeExport): void
|
||||
{
|
||||
$allExporter = $this->serviceExport->getTimesheetExporter();
|
||||
if (\count($allExporter) === 1) {
|
||||
$event->addAction('download', ['url' => $this->path($routeExport, ['exporter' => $allExporter[0]->getId()]), 'class' => 'toolbar-action']);
|
||||
} else {
|
||||
foreach ($allExporter as $exporter) {
|
||||
$id = $exporter->getId();
|
||||
$event->addActionToSubmenu('download', 'exporter.' . $id, ['title' => 'button.' . $id, 'url' => $this->path($routeExport, ['exporter' => $id]), 'class' => 'toolbar-action exporter-' . $id]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
33
src/EventSubscriber/Actions/ActivitiesSubscriber.php
Normal file
33
src/EventSubscriber/Actions/ActivitiesSubscriber.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Kimai time-tracking app.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace App\EventSubscriber\Actions;
|
||||
|
||||
use App\Event\PageActionsEvent;
|
||||
|
||||
class ActivitiesSubscriber extends AbstractActionsSubscriber
|
||||
{
|
||||
public static function getActionName(): string
|
||||
{
|
||||
return 'activities';
|
||||
}
|
||||
|
||||
public function onActions(PageActionsEvent $event): void
|
||||
{
|
||||
$event->addSearchToggle();
|
||||
$event->addColumnToggle('#modal_activity_admin');
|
||||
$event->addQuickExport($this->path('activity_export'));
|
||||
|
||||
if ($this->isGranted('create_activity')) {
|
||||
$event->addCreate($this->path('admin_activity_create'));
|
||||
}
|
||||
|
||||
$event->addHelp($this->documentationLink('activity.html'));
|
||||
}
|
||||
}
|
||||
75
src/EventSubscriber/Actions/ActivitySubscriber.php
Normal file
75
src/EventSubscriber/Actions/ActivitySubscriber.php
Normal file
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Kimai time-tracking app.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace App\EventSubscriber\Actions;
|
||||
|
||||
use App\Entity\Activity;
|
||||
use App\Event\PageActionsEvent;
|
||||
|
||||
class ActivitySubscriber extends AbstractActionsSubscriber
|
||||
{
|
||||
public static function getActionName(): string
|
||||
{
|
||||
return 'activity';
|
||||
}
|
||||
|
||||
public function onActions(PageActionsEvent $event): void
|
||||
{
|
||||
$payload = $event->getPayload();
|
||||
|
||||
/** @var Activity $activity */
|
||||
$activity = $payload['activity'];
|
||||
|
||||
if ($activity->getId() === null) {
|
||||
return;
|
||||
}
|
||||
if ($this->isGranted('view', $activity)) {
|
||||
$event->addAction('details', ['url' => $this->path('activity_details', ['id' => $activity->getId()])]);
|
||||
}
|
||||
|
||||
if ($this->isGranted('edit', $activity)) {
|
||||
$class = $event->isView('edit') ? '' : 'modal-ajax-form';
|
||||
$event->addAction('edit', ['url' => $this->path('admin_activity_edit', ['id' => $activity->getId()]), 'class' => $class]);
|
||||
}
|
||||
|
||||
if ($this->isGranted('permissions', $activity)) {
|
||||
$class = $event->isView('permissions') ? '' : 'modal-ajax-form';
|
||||
$event->addAction('permissions', ['url' => $this->path('admin_activity_permissions', ['id' => $activity->getId()]), 'class' => $class]);
|
||||
}
|
||||
|
||||
if ($event->countActions() > 0) {
|
||||
$event->addDivider();
|
||||
}
|
||||
|
||||
if ($this->isGranted('view_other_timesheet')) {
|
||||
$parameters = ['activities[]' => $activity->getId()];
|
||||
if (!$activity->isGlobal()) {
|
||||
$parameters['customers[]'] = $activity->getProject()->getCustomer()->getId();
|
||||
$parameters['projects[]'] = $activity->getProject()->getId();
|
||||
}
|
||||
$event->addActionToSubmenu('filter', 'timesheet', ['title' => 'timesheet', 'translation_domain' => 'actions', 'url' => $this->path('admin_timesheet', $parameters)]);
|
||||
}
|
||||
|
||||
if ($event->hasSubmenu('filter')) {
|
||||
$event->addDivider();
|
||||
}
|
||||
|
||||
if ($activity->isVisible() && $this->isGranted('create_other_timesheet')) {
|
||||
$parameters = ['activity' => $activity->getId()];
|
||||
if (!$activity->isGlobal()) {
|
||||
$parameters['project'] = $activity->getProject()->getId();
|
||||
}
|
||||
$event->addAction('create-timesheet', ['icon' => 'start', 'url' => $this->path('admin_timesheet_create', $parameters), 'class' => 'modal-ajax-form']);
|
||||
}
|
||||
|
||||
if ($event->isIndexView() && $this->isGranted('delete', $activity)) {
|
||||
$event->addDelete($this->path('admin_activity_delete', ['id' => $activity->getId()]));
|
||||
}
|
||||
}
|
||||
}
|
||||
29
src/EventSubscriber/Actions/CalendarSubscriber.php
Normal file
29
src/EventSubscriber/Actions/CalendarSubscriber.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Kimai time-tracking app.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace App\EventSubscriber\Actions;
|
||||
|
||||
use App\Event\PageActionsEvent;
|
||||
|
||||
class CalendarSubscriber extends AbstractActionsSubscriber
|
||||
{
|
||||
public static function getActionName(): string
|
||||
{
|
||||
return 'calendar';
|
||||
}
|
||||
|
||||
public function onActions(PageActionsEvent $event): void
|
||||
{
|
||||
if ($this->isGranted('create_own_timesheet')) {
|
||||
$event->addCreate($this->path('timesheet_create'));
|
||||
}
|
||||
|
||||
$event->addHelp($this->documentationLink('calendar.html'));
|
||||
}
|
||||
}
|
||||
79
src/EventSubscriber/Actions/CustomerSubscriber.php
Normal file
79
src/EventSubscriber/Actions/CustomerSubscriber.php
Normal file
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Kimai time-tracking app.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace App\EventSubscriber\Actions;
|
||||
|
||||
use App\Entity\Customer;
|
||||
use App\Event\PageActionsEvent;
|
||||
|
||||
class CustomerSubscriber extends AbstractActionsSubscriber
|
||||
{
|
||||
public static function getActionName(): string
|
||||
{
|
||||
return 'customer';
|
||||
}
|
||||
|
||||
public function onActions(PageActionsEvent $event): void
|
||||
{
|
||||
$payload = $event->getPayload();
|
||||
|
||||
/** @var Customer $customer */
|
||||
$customer = $payload['customer'];
|
||||
|
||||
if ($customer->getId() === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($this->isGranted('view', $customer)) {
|
||||
$event->addAction('details', ['url' => $this->path('customer_details', ['id' => $customer->getId()])]);
|
||||
}
|
||||
|
||||
if ($this->isGranted('edit', $customer)) {
|
||||
$class = $event->isView('edit') ? '' : 'modal-ajax-form';
|
||||
$event->addAction('edit', ['url' => $this->path('admin_customer_edit', ['id' => $customer->getId()]), 'class' => $class]);
|
||||
}
|
||||
|
||||
if ($this->isGranted('permissions', $customer)) {
|
||||
$class = $event->isView('permissions') ? '' : 'modal-ajax-form';
|
||||
$event->addAction('permissions', ['url' => $this->path('admin_customer_permissions', ['id' => $customer->getId()]), 'class' => $class]);
|
||||
}
|
||||
|
||||
if ($event->countActions() > 0) {
|
||||
$event->addDivider();
|
||||
}
|
||||
|
||||
if ($this->isGranted('view_project') || $this->isGranted('view_teamlead_project') || $this->isGranted('view_team_project')) {
|
||||
$event->addActionToSubmenu('filter', 'project', ['title' => 'project', 'translation_domain' => 'actions', 'url' => $this->path('admin_project', ['customers[]' => $customer->getId()])]);
|
||||
}
|
||||
|
||||
if ($this->isGranted('view_activity')) {
|
||||
$event->addActionToSubmenu('filter', 'activity', ['title' => 'activity', 'translation_domain' => 'actions', 'url' => $this->path('admin_activity', ['customers[]' => $customer->getId()])]);
|
||||
}
|
||||
|
||||
if ($this->isGranted('view_other_timesheet')) {
|
||||
$event->addActionToSubmenu('filter', 'timesheet', ['title' => 'timesheet', 'translation_domain' => 'actions', 'url' => $this->path('admin_timesheet', ['customers[]' => $customer->getId()])]);
|
||||
}
|
||||
|
||||
if ($event->hasSubmenu('filter')) {
|
||||
$event->addDivider();
|
||||
}
|
||||
|
||||
if ($customer->isVisible() && $this->isGranted('create_project')) {
|
||||
$event->addAction('create-project', ['icon' => 'create', 'url' => $this->path('admin_project_create_with_customer', ['customer' => $customer->getId()]), 'class' => 'modal-ajax-form']);
|
||||
}
|
||||
|
||||
if ($event->isIndexView() && $this->isGranted('delete', $customer)) {
|
||||
$event->addAction('trash', ['url' => $this->path('admin_customer_delete', ['id' => $customer->getId()]), 'class' => 'modal-ajax-form text-red']);
|
||||
}
|
||||
|
||||
if ($this->isGranted('view_reporting') && $this->isGranted('budget_project')) {
|
||||
$event->addAction('report_project_view', ['url' => $this->path('report_project_view', ['customer' => $customer->getId()]), 'icon' => 'reporting', 'translation_domain' => 'reporting']);
|
||||
}
|
||||
}
|
||||
}
|
||||
33
src/EventSubscriber/Actions/CustomersSubscriber.php
Normal file
33
src/EventSubscriber/Actions/CustomersSubscriber.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Kimai time-tracking app.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace App\EventSubscriber\Actions;
|
||||
|
||||
use App\Event\PageActionsEvent;
|
||||
|
||||
class CustomersSubscriber extends AbstractActionsSubscriber
|
||||
{
|
||||
public static function getActionName(): string
|
||||
{
|
||||
return 'customers';
|
||||
}
|
||||
|
||||
public function onActions(PageActionsEvent $event): void
|
||||
{
|
||||
$event->addSearchToggle();
|
||||
$event->addColumnToggle('#modal_customer_admin');
|
||||
$event->addQuickExport($this->path('customer_export'));
|
||||
|
||||
if ($this->isGranted('create_customer')) {
|
||||
$event->addCreate($this->path('admin_customer_create'));
|
||||
}
|
||||
|
||||
$event->addHelp($this->documentationLink('customer.html'));
|
||||
}
|
||||
}
|
||||
31
src/EventSubscriber/Actions/ExportSubscriber.php
Normal file
31
src/EventSubscriber/Actions/ExportSubscriber.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Kimai time-tracking app.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace App\EventSubscriber\Actions;
|
||||
|
||||
use App\Event\PageActionsEvent;
|
||||
|
||||
class ExportSubscriber extends AbstractActionsSubscriber
|
||||
{
|
||||
public static function getActionName(): string
|
||||
{
|
||||
return 'export';
|
||||
}
|
||||
|
||||
public function onActions(PageActionsEvent $event): void
|
||||
{
|
||||
$event->addColumnToggle('#modal_export');
|
||||
|
||||
if ($event->isView('preview')) {
|
||||
$event->addAction('off', ['id' => 'export-toggle-button']);
|
||||
}
|
||||
|
||||
$event->addHelp($this->documentationLink('export.html'));
|
||||
}
|
||||
}
|
||||
@@ -13,25 +13,19 @@ use App\Event\PageActionsEvent;
|
||||
|
||||
class InvoiceArchiveSubscriber extends AbstractActionsSubscriber
|
||||
{
|
||||
public static function getSubscribedEvents(): array
|
||||
public static function getActionName(): string
|
||||
{
|
||||
return [
|
||||
'actions.invoice_details' => ['onActions', 1000],
|
||||
];
|
||||
return 'invoice_details';
|
||||
}
|
||||
|
||||
public function onActions(PageActionsEvent $event)
|
||||
public function onActions(PageActionsEvent $event): void
|
||||
{
|
||||
$actions = $event->getActions();
|
||||
|
||||
if ($this->isGranted('view_invoice')) {
|
||||
$actions['back'] = ['url' => $this->path('invoice'), 'translation_domain' => 'actions'];
|
||||
$event->addBack($this->path('invoice'));
|
||||
}
|
||||
|
||||
$actions['visibility'] = '#modal_invoices';
|
||||
$actions['download'] = ['url' => $this->path('invoice_export'), 'class' => 'toolbar-action'];
|
||||
$actions['help'] = ['url' => $this->documentationLink('invoices.html'), 'target' => '_blank'];
|
||||
|
||||
$event->setActions($actions);
|
||||
$event->addSearchToggle();
|
||||
$event->addColumnToggle('#modal_invoices');
|
||||
$event->addQuickExport($this->path('invoice_export'));
|
||||
$event->addHelp($this->documentationLink('invoices.html'));
|
||||
}
|
||||
}
|
||||
|
||||
44
src/EventSubscriber/Actions/InvoiceSubscriber.php
Normal file
44
src/EventSubscriber/Actions/InvoiceSubscriber.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Kimai time-tracking app.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace App\EventSubscriber\Actions;
|
||||
|
||||
use App\Entity\Invoice;
|
||||
use App\Event\PageActionsEvent;
|
||||
|
||||
class InvoiceSubscriber extends AbstractActionsSubscriber
|
||||
{
|
||||
public static function getActionName(): string
|
||||
{
|
||||
return 'invoice';
|
||||
}
|
||||
|
||||
public function onActions(PageActionsEvent $event): void
|
||||
{
|
||||
$payload = $event->getPayload();
|
||||
|
||||
/** @var Invoice $invoice */
|
||||
$invoice = $payload['invoice'];
|
||||
|
||||
if ($invoice->getId() === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($this->isGranted('history_invoice')) {
|
||||
if ($invoice->isNew()) {
|
||||
$event->addAction('invoice.pending', ['url' => $this->path('admin_invoice_status', ['id' => $invoice->getId(), 'status' => 'pending'])]);
|
||||
} elseif ($invoice->isPending()) {
|
||||
$event->addAction('invoice.paid', ['url' => $this->path('admin_invoice_status', ['id' => $invoice->getId(), 'status' => 'paid'])]);
|
||||
}
|
||||
|
||||
$event->addAction('download', ['url' => $this->path('admin_invoice_download', ['id' => $invoice->getId()]), 'target' => '_blank']);
|
||||
$event->addDelete($this->path('admin_invoice_delete', ['id' => $invoice->getId()]), false);
|
||||
}
|
||||
}
|
||||
}
|
||||
42
src/EventSubscriber/Actions/InvoiceTemplateSubscriber.php
Normal file
42
src/EventSubscriber/Actions/InvoiceTemplateSubscriber.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Kimai time-tracking app.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace App\EventSubscriber\Actions;
|
||||
|
||||
use App\Entity\InvoiceTemplate;
|
||||
use App\Event\PageActionsEvent;
|
||||
|
||||
class InvoiceTemplateSubscriber extends AbstractActionsSubscriber
|
||||
{
|
||||
public static function getActionName(): string
|
||||
{
|
||||
return 'invoice_template';
|
||||
}
|
||||
|
||||
public function onActions(PageActionsEvent $event): void
|
||||
{
|
||||
$payload = $event->getPayload();
|
||||
|
||||
/** @var InvoiceTemplate $template */
|
||||
$template = $payload['template'];
|
||||
|
||||
if ($template->getId() === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($this->isGranted('manage_invoice_template')) {
|
||||
if (!$event->isIndexView()) {
|
||||
$event->addBack($this->path('invoice'));
|
||||
}
|
||||
$event->addAction('edit', ['url' => $this->path('admin_invoice_template_edit', ['id' => $template->getId()]), 'class' => 'modal-ajax-form']);
|
||||
$event->addAction('copy', ['url' => $this->path('admin_invoice_template_copy', ['id' => $template->getId()])]);
|
||||
$event->addDelete($this->path('admin_invoice_template_delete', ['id' => $template->getId()]), false);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Kimai time-tracking app.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace App\EventSubscriber\Actions;
|
||||
|
||||
use App\Event\PageActionsEvent;
|
||||
|
||||
class InvoiceTemplateUploadSubscriber extends AbstractActionsSubscriber
|
||||
{
|
||||
public static function getActionName(): string
|
||||
{
|
||||
return 'invoice_upload';
|
||||
}
|
||||
|
||||
public function onActions(PageActionsEvent $event): void
|
||||
{
|
||||
if ($event->isIndexView() && $this->isGranted('manage_invoice_template')) {
|
||||
$event->addBack($this->path('admin_invoice_template'));
|
||||
}
|
||||
|
||||
$event->addHelp($this->documentationLink('invoices.html'));
|
||||
}
|
||||
}
|
||||
40
src/EventSubscriber/Actions/InvoiceTemplatesSubscriber.php
Normal file
40
src/EventSubscriber/Actions/InvoiceTemplatesSubscriber.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Kimai time-tracking app.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace App\EventSubscriber\Actions;
|
||||
|
||||
use App\Event\PageActionsEvent;
|
||||
|
||||
class InvoiceTemplatesSubscriber extends AbstractActionsSubscriber
|
||||
{
|
||||
public static function getActionName(): string
|
||||
{
|
||||
return 'invoice_templates';
|
||||
}
|
||||
|
||||
public function onActions(PageActionsEvent $event): void
|
||||
{
|
||||
if ($this->isGranted('view_invoice')) {
|
||||
$event->addBack($this->path('invoice'));
|
||||
}
|
||||
|
||||
$event->addColumnToggle('#modal_invoice_template');
|
||||
|
||||
if ($this->isGranted('manage_invoice_template')) {
|
||||
$event->addAction('create', ['url' => $this->path('admin_invoice_template_create'), 'class' => 'modal-ajax-form']);
|
||||
}
|
||||
|
||||
// File upload does not work in a modal right now
|
||||
if ($this->isGranted('upload_invoice_template')) {
|
||||
$event->addAction('upload', ['url' => $this->path('admin_invoice_document_upload')]);
|
||||
}
|
||||
|
||||
$event->addHelp($this->documentationLink('invoices.html'));
|
||||
}
|
||||
}
|
||||
39
src/EventSubscriber/Actions/InvoicesSubscriber.php
Normal file
39
src/EventSubscriber/Actions/InvoicesSubscriber.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Kimai time-tracking app.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace App\EventSubscriber\Actions;
|
||||
|
||||
use App\Event\PageActionsEvent;
|
||||
|
||||
class InvoicesSubscriber extends AbstractActionsSubscriber
|
||||
{
|
||||
public static function getActionName(): string
|
||||
{
|
||||
return 'invoices';
|
||||
}
|
||||
|
||||
public function onActions(PageActionsEvent $event): void
|
||||
{
|
||||
$event->addColumnToggle('#modal_invoice');
|
||||
|
||||
if ($this->isGranted('history_invoice')) {
|
||||
$event->addAction('list', ['url' => $this->path('admin_invoice_list')]);
|
||||
}
|
||||
|
||||
if ($this->isGranted('manage_invoice_template')) {
|
||||
$event->addAction('invoice-template', ['url' => $this->path('admin_invoice_template')]);
|
||||
}
|
||||
|
||||
if ($this->isGranted('system_configuration')) {
|
||||
$event->addAction('settings', ['url' => $this->path('system_configuration_section', ['section' => 'invoice']), 'class' => 'modal-ajax-form']);
|
||||
}
|
||||
|
||||
$event->addHelp($this->documentationLink('invoices.html'));
|
||||
}
|
||||
}
|
||||
34
src/EventSubscriber/Actions/PermissionsSubscriber.php
Normal file
34
src/EventSubscriber/Actions/PermissionsSubscriber.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Kimai time-tracking app.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace App\EventSubscriber\Actions;
|
||||
|
||||
use App\Event\PageActionsEvent;
|
||||
|
||||
class PermissionsSubscriber extends AbstractActionsSubscriber
|
||||
{
|
||||
public static function getActionName(): string
|
||||
{
|
||||
return 'user_permissions';
|
||||
}
|
||||
|
||||
public function onActions(PageActionsEvent $event): void
|
||||
{
|
||||
// the "create role" page
|
||||
if (!$event->isIndexView() && $this->isGranted('role_permissions')) {
|
||||
//$event->addBack($this->path('admin_user_permissions'));
|
||||
}
|
||||
|
||||
if ($this->isGranted('role_permissions')) {
|
||||
$event->addCreate($this->path('admin_user_roles'), !$event->isView('role'));
|
||||
}
|
||||
|
||||
$event->addHelp($this->documentationLink('permissions.html'));
|
||||
}
|
||||
}
|
||||
31
src/EventSubscriber/Actions/PluginSubscriber.php
Normal file
31
src/EventSubscriber/Actions/PluginSubscriber.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Kimai time-tracking app.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace App\EventSubscriber\Actions;
|
||||
|
||||
use App\Event\PageActionsEvent;
|
||||
use App\Plugin\Plugin;
|
||||
|
||||
class PluginSubscriber extends AbstractActionsSubscriber
|
||||
{
|
||||
public static function getActionName(): string
|
||||
{
|
||||
return 'plugin';
|
||||
}
|
||||
|
||||
public function onActions(PageActionsEvent $event): void
|
||||
{
|
||||
$payload = $event->getPayload();
|
||||
|
||||
/** @var Plugin $plugin */
|
||||
$plugin = $payload['plugin'];
|
||||
|
||||
$event->addAction('home', ['url' => $plugin->getMetadata()->getHomepage(), 'target' => '_blank']);
|
||||
}
|
||||
}
|
||||
27
src/EventSubscriber/Actions/PluginsSubscriber.php
Normal file
27
src/EventSubscriber/Actions/PluginsSubscriber.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Kimai time-tracking app.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace App\EventSubscriber\Actions;
|
||||
|
||||
use App\Constants;
|
||||
use App\Event\PageActionsEvent;
|
||||
|
||||
class PluginsSubscriber extends AbstractActionsSubscriber
|
||||
{
|
||||
public static function getActionName(): string
|
||||
{
|
||||
return 'plugins';
|
||||
}
|
||||
|
||||
public function onActions(PageActionsEvent $event): void
|
||||
{
|
||||
$event->addAction('shop', ['url' => Constants::HOMEPAGE . '/store/', 'target' => '_blank']);
|
||||
$event->addHelp($this->documentationLink('plugins.html'));
|
||||
}
|
||||
}
|
||||
75
src/EventSubscriber/Actions/ProjectSubscriber.php
Normal file
75
src/EventSubscriber/Actions/ProjectSubscriber.php
Normal file
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Kimai time-tracking app.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace App\EventSubscriber\Actions;
|
||||
|
||||
use App\Entity\Project;
|
||||
use App\Event\PageActionsEvent;
|
||||
|
||||
class ProjectSubscriber extends AbstractActionsSubscriber
|
||||
{
|
||||
public static function getActionName(): string
|
||||
{
|
||||
return 'project';
|
||||
}
|
||||
|
||||
public function onActions(PageActionsEvent $event): void
|
||||
{
|
||||
$payload = $event->getPayload();
|
||||
|
||||
/** @var Project $project */
|
||||
$project = $payload['project'];
|
||||
|
||||
if ($project->getId() === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($this->isGranted('view', $project)) {
|
||||
$event->addAction('details', ['url' => $this->path('project_details', ['id' => $project->getId()])]);
|
||||
}
|
||||
|
||||
if ($this->isGranted('edit', $project)) {
|
||||
$class = $event->isView('edit') ? '' : 'modal-ajax-form';
|
||||
$event->addAction('edit', ['url' => $this->path('admin_project_edit', ['id' => $project->getId()]), 'class' => $class]);
|
||||
}
|
||||
|
||||
if ($this->isGranted('permissions', $project)) {
|
||||
$class = $event->isView('permissions') ? '' : 'modal-ajax-form';
|
||||
$event->addAction('permissions', ['url' => $this->path('admin_project_permissions', ['id' => $project->getId()]), 'class' => $class]);
|
||||
}
|
||||
|
||||
if ($event->countActions() > 0) {
|
||||
$event->addDivider();
|
||||
}
|
||||
|
||||
if ($this->isGranted('view_activity')) {
|
||||
$event->addActionToSubmenu('filter', 'activity', ['title' => 'activity', 'translation_domain' => 'actions', 'url' => $this->path('admin_activity', ['customers[]' => $project->getCustomer()->getId(), 'projects[]' => $project->getId()])]);
|
||||
}
|
||||
|
||||
if ($this->isGranted('view_other_timesheet')) {
|
||||
$event->addActionToSubmenu('filter', 'timesheet', ['title' => 'timesheet', 'translation_domain' => 'actions', 'url' => $this->path('admin_timesheet', ['customers[]' => $project->getCustomer()->getId(), 'projects[]' => $project->getId()])]);
|
||||
}
|
||||
|
||||
if ($event->hasSubmenu('filter')) {
|
||||
$event->addDivider();
|
||||
}
|
||||
|
||||
if ($project->isVisible() && $project->getCustomer()->isVisible() && $this->isGranted('create_activity')) {
|
||||
$event->addAction('create-activity', ['icon' => 'create', 'url' => $this->path('admin_activity_create_with_project', ['project' => $project->getId()]), 'class' => 'modal-ajax-form']);
|
||||
}
|
||||
|
||||
if ($this->isGranted('edit', $project)) {
|
||||
$event->addAction('copy', ['url' => $this->path('admin_project_duplicate', ['id' => $project->getId()])]);
|
||||
}
|
||||
|
||||
if ($event->isIndexView() && $this->isGranted('delete', $project)) {
|
||||
$event->addAction('trash', ['url' => $this->path('admin_project_delete', ['id' => $project->getId()]), 'class' => 'modal-ajax-form text-red']);
|
||||
}
|
||||
}
|
||||
}
|
||||
33
src/EventSubscriber/Actions/ProjectsSubscriber.php
Normal file
33
src/EventSubscriber/Actions/ProjectsSubscriber.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Kimai time-tracking app.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace App\EventSubscriber\Actions;
|
||||
|
||||
use App\Event\PageActionsEvent;
|
||||
|
||||
class ProjectsSubscriber extends AbstractActionsSubscriber
|
||||
{
|
||||
public static function getActionName(): string
|
||||
{
|
||||
return 'projects';
|
||||
}
|
||||
|
||||
public function onActions(PageActionsEvent $event): void
|
||||
{
|
||||
$event->addSearchToggle();
|
||||
$event->addColumnToggle('#modal_project_admin');
|
||||
$event->addQuickExport($this->path('project_export'));
|
||||
|
||||
if ($this->isGranted('create_project')) {
|
||||
$event->addCreate($this->path('admin_project_create'));
|
||||
}
|
||||
|
||||
$event->addHelp($this->documentationLink('project.html'));
|
||||
}
|
||||
}
|
||||
42
src/EventSubscriber/Actions/ReportingSubscriber.php
Normal file
42
src/EventSubscriber/Actions/ReportingSubscriber.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Kimai time-tracking app.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace App\EventSubscriber\Actions;
|
||||
|
||||
use App\Event\PageActionsEvent;
|
||||
use App\Reporting\ReportingService;
|
||||
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
|
||||
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
|
||||
|
||||
class ReportingSubscriber extends AbstractActionsSubscriber
|
||||
{
|
||||
private $reportingService;
|
||||
|
||||
public function __construct(AuthorizationCheckerInterface $security, UrlGeneratorInterface $urlGenerator, ReportingService $reportingService)
|
||||
{
|
||||
parent::__construct($security, $urlGenerator);
|
||||
$this->reportingService = $reportingService;
|
||||
}
|
||||
|
||||
public static function getActionName(): string
|
||||
{
|
||||
return 'reporting';
|
||||
}
|
||||
|
||||
public function onActions(PageActionsEvent $event): void
|
||||
{
|
||||
$reports = $this->reportingService->getAvailableReports($event->getUser());
|
||||
|
||||
foreach ($reports as $report) {
|
||||
$event->addActionToSubmenu('reporting', $report->getId(), ['title' => $report->getLabel(), 'translation_domain' => 'reporting', 'url' => $this->path($report->getRoute()), 'class' => 'toolbar-action report-' . $report->getId()]);
|
||||
}
|
||||
|
||||
$event->addHelp($this->documentationLink('reporting.html'));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Kimai time-tracking app.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace App\EventSubscriber\Actions;
|
||||
|
||||
use App\Event\PageActionsEvent;
|
||||
|
||||
class SystemConfigurationSubscriber extends AbstractActionsSubscriber
|
||||
{
|
||||
public static function getActionName(): string
|
||||
{
|
||||
return 'system_configuration';
|
||||
}
|
||||
|
||||
public function onActions(PageActionsEvent $event): void
|
||||
{
|
||||
$event->addHelp($this->documentationLink('configurations.html'));
|
||||
}
|
||||
}
|
||||
71
src/EventSubscriber/Actions/TagSubscriber.php
Normal file
71
src/EventSubscriber/Actions/TagSubscriber.php
Normal file
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Kimai time-tracking app.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace App\EventSubscriber\Actions;
|
||||
|
||||
use App\Entity\Tag;
|
||||
use App\Event\PageActionsEvent;
|
||||
|
||||
class TagSubscriber extends AbstractActionsSubscriber
|
||||
{
|
||||
public static function getActionName(): string
|
||||
{
|
||||
return 'tag';
|
||||
}
|
||||
|
||||
public function onActions(PageActionsEvent $event): void
|
||||
{
|
||||
$payload = $event->getPayload();
|
||||
|
||||
$tag = $payload['tag'];
|
||||
$id = null;
|
||||
$name = null;
|
||||
|
||||
if (\is_array($tag)) {
|
||||
// tag can be either and array (on index page => [id, name, color, amount]) ...
|
||||
$id = $tag['id'];
|
||||
$name = $tag['name'];
|
||||
} elseif ($tag instanceof Tag) {
|
||||
// ...or an entity on detail page
|
||||
$id = $tag->getId();
|
||||
$name = $tag->getName();
|
||||
}
|
||||
|
||||
if (!$event->isIndexView() && $this->isGranted('view_tag')) {
|
||||
//$event->addBack($this->path('tags'));
|
||||
}
|
||||
|
||||
if ($id === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($this->isGranted('manage_tag')) {
|
||||
$class = ($event->isView('edit') ? '' : 'modal-ajax-form');
|
||||
$event->addAction('edit', ['url' => $this->path('tags_edit', ['id' => $id]), 'class' => $class]);
|
||||
}
|
||||
|
||||
if ($this->isGranted('view_other_timesheet')) {
|
||||
$event->addActionToSubmenu('filter', 'timesheet', ['title' => 'timesheet', 'translation_domain' => 'actions', 'url' => $this->path('admin_timesheet', ['tags' => $name])]);
|
||||
}
|
||||
|
||||
if ($event->isIndexView() && $this->isGranted('delete_tag')) {
|
||||
$event->addAction('trash', [
|
||||
'url' => $this->path('delete_tag', ['id' => $id]),
|
||||
'class' => 'api-link',
|
||||
'attr' => [
|
||||
'data-event' => 'kimai.tagDelete kimai.tagUpdate',
|
||||
'data-method' => 'DELETE',
|
||||
'data-question' => 'confirm.delete',
|
||||
'data-msg-error' => 'action.delete.error',
|
||||
'data-msg-success' => 'action.delete.success'
|
||||
]
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
31
src/EventSubscriber/Actions/TagsSubscriber.php
Normal file
31
src/EventSubscriber/Actions/TagsSubscriber.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Kimai time-tracking app.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace App\EventSubscriber\Actions;
|
||||
|
||||
use App\Event\PageActionsEvent;
|
||||
|
||||
class TagsSubscriber extends AbstractActionsSubscriber
|
||||
{
|
||||
public static function getActionName(): string
|
||||
{
|
||||
return 'tags';
|
||||
}
|
||||
|
||||
public function onActions(PageActionsEvent $event): void
|
||||
{
|
||||
$event->addSearchToggle();
|
||||
|
||||
if ($this->isGranted('manage_tag')) {
|
||||
$event->addCreate($this->path('tags_create'));
|
||||
}
|
||||
|
||||
$event->addHelp($this->documentationLink('tags.html'));
|
||||
}
|
||||
}
|
||||
59
src/EventSubscriber/Actions/TeamSubscriber.php
Normal file
59
src/EventSubscriber/Actions/TeamSubscriber.php
Normal file
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Kimai time-tracking app.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace App\EventSubscriber\Actions;
|
||||
|
||||
use App\Entity\Team;
|
||||
use App\Event\PageActionsEvent;
|
||||
|
||||
class TeamSubscriber extends AbstractActionsSubscriber
|
||||
{
|
||||
public static function getActionName(): string
|
||||
{
|
||||
return 'team';
|
||||
}
|
||||
|
||||
public function onActions(PageActionsEvent $event): void
|
||||
{
|
||||
$payload = $event->getPayload();
|
||||
|
||||
/** @var Team $team */
|
||||
$team = $payload['team'];
|
||||
|
||||
if (!$event->isIndexView() && $this->isGranted('view_tag')) {
|
||||
//$event->addBack($this->path('admin_team'));
|
||||
}
|
||||
|
||||
if ($team->getId() === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($this->isGranted('edit', $team)) {
|
||||
$event->addAction('edit', ['url' => $this->path('admin_team_edit', ['id' => $team->getId()])]);
|
||||
|
||||
if ($this->isGranted('create_team')) {
|
||||
$event->addAction('copy', ['url' => $this->path('team_duplicate', ['id' => $team->getId()])]);
|
||||
}
|
||||
}
|
||||
|
||||
if ($event->isIndexView() && $this->isGranted('delete', $team)) {
|
||||
$event->addAction('trash', [
|
||||
'url' => $this->path('delete_team', ['id' => $team->getId()]),
|
||||
'class' => 'api-link',
|
||||
'attr' => [
|
||||
'data-event' => 'kimai.teamDelete kimai.teamUpdate',
|
||||
'data-method' => 'DELETE',
|
||||
'data-question' => 'confirm.delete',
|
||||
'data-msg-error' => 'action.delete.error',
|
||||
'data-msg-success' => 'action.delete.success'
|
||||
]
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
31
src/EventSubscriber/Actions/TeamsSubscriber.php
Normal file
31
src/EventSubscriber/Actions/TeamsSubscriber.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Kimai time-tracking app.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace App\EventSubscriber\Actions;
|
||||
|
||||
use App\Event\PageActionsEvent;
|
||||
|
||||
class TeamsSubscriber extends AbstractActionsSubscriber
|
||||
{
|
||||
public static function getActionName(): string
|
||||
{
|
||||
return 'teams';
|
||||
}
|
||||
|
||||
public function onActions(PageActionsEvent $event): void
|
||||
{
|
||||
$event->addSearchToggle();
|
||||
|
||||
if ($this->isGranted('create_team')) {
|
||||
$event->addCreate($this->path('admin_team_create'), false);
|
||||
}
|
||||
|
||||
$event->addHelp($this->documentationLink('teams.html'));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Kimai time-tracking app.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace App\EventSubscriber\Actions;
|
||||
|
||||
use App\Event\PageActionsEvent;
|
||||
|
||||
class TimesheetMultiUpdateSubscriber extends AbstractActionsSubscriber
|
||||
{
|
||||
public static function getActionName(): string
|
||||
{
|
||||
return 'timesheets_multi_update';
|
||||
}
|
||||
|
||||
public function onActions(PageActionsEvent $event): void
|
||||
{
|
||||
$event->addBack($this->path('timesheet'));
|
||||
$event->addHelp($this->documentationLink('timesheet.html'));
|
||||
}
|
||||
}
|
||||
25
src/EventSubscriber/Actions/TimesheetSubscriber.php
Normal file
25
src/EventSubscriber/Actions/TimesheetSubscriber.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Kimai time-tracking app.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace App\EventSubscriber\Actions;
|
||||
|
||||
use App\Event\PageActionsEvent;
|
||||
|
||||
class TimesheetSubscriber extends AbstractTimesheetSubscriber
|
||||
{
|
||||
public static function getActionName(): string
|
||||
{
|
||||
return 'timesheet';
|
||||
}
|
||||
|
||||
public function onActions(PageActionsEvent $event): void
|
||||
{
|
||||
$this->timesheetActions($event, 'timesheet', 'timesheet_edit');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Kimai time-tracking app.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace App\EventSubscriber\Actions;
|
||||
|
||||
use App\Event\PageActionsEvent;
|
||||
|
||||
class TimesheetTeamMultiUpdateSubscriber extends AbstractActionsSubscriber
|
||||
{
|
||||
public static function getActionName(): string
|
||||
{
|
||||
return 'timesheets_team_multi_update';
|
||||
}
|
||||
|
||||
public function onActions(PageActionsEvent $event): void
|
||||
{
|
||||
$event->addBack($this->path('admin_timesheet'));
|
||||
$event->addHelp($this->documentationLink('timesheet.html'));
|
||||
}
|
||||
}
|
||||
25
src/EventSubscriber/Actions/TimesheetTeamSubscriber.php
Normal file
25
src/EventSubscriber/Actions/TimesheetTeamSubscriber.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Kimai time-tracking app.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace App\EventSubscriber\Actions;
|
||||
|
||||
use App\Event\PageActionsEvent;
|
||||
|
||||
class TimesheetTeamSubscriber extends AbstractTimesheetSubscriber
|
||||
{
|
||||
public static function getActionName(): string
|
||||
{
|
||||
return 'timesheet_team';
|
||||
}
|
||||
|
||||
public function onActions(PageActionsEvent $event): void
|
||||
{
|
||||
$this->timesheetActions($event, 'admin_timesheet', 'admin_timesheet_edit');
|
||||
}
|
||||
}
|
||||
36
src/EventSubscriber/Actions/TimesheetsSubscriber.php
Normal file
36
src/EventSubscriber/Actions/TimesheetsSubscriber.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Kimai time-tracking app.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace App\EventSubscriber\Actions;
|
||||
|
||||
use App\Event\PageActionsEvent;
|
||||
|
||||
class TimesheetsSubscriber extends AbstractTimesheetsSubscriber
|
||||
{
|
||||
public static function getActionName(): string
|
||||
{
|
||||
return 'timesheets';
|
||||
}
|
||||
|
||||
public function onActions(PageActionsEvent $event): void
|
||||
{
|
||||
$event->addSearchToggle();
|
||||
$event->addColumnToggle('#modal_timesheet');
|
||||
|
||||
if ($this->isGranted('export_own_timesheet')) {
|
||||
$this->addExporter($event, 'timesheet_export');
|
||||
}
|
||||
|
||||
if ($this->isGranted('create_own_timesheet')) {
|
||||
$event->addCreate($this->path('timesheet_create'));
|
||||
}
|
||||
|
||||
$event->addHelp($this->documentationLink('timesheet.html'));
|
||||
}
|
||||
}
|
||||
37
src/EventSubscriber/Actions/TimesheetsTeamSubscriber.php
Normal file
37
src/EventSubscriber/Actions/TimesheetsTeamSubscriber.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Kimai time-tracking app.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace App\EventSubscriber\Actions;
|
||||
|
||||
use App\Event\PageActionsEvent;
|
||||
|
||||
class TimesheetsTeamSubscriber extends AbstractTimesheetsSubscriber
|
||||
{
|
||||
public static function getActionName(): string
|
||||
{
|
||||
return 'timesheets_team';
|
||||
}
|
||||
|
||||
public function onActions(PageActionsEvent $event): void
|
||||
{
|
||||
$event->addSearchToggle();
|
||||
$event->addColumnToggle('#modal_timesheet_admin');
|
||||
|
||||
if ($this->isGranted('export_other_timesheet')) {
|
||||
$this->addExporter($event, 'admin_timesheet_export');
|
||||
}
|
||||
|
||||
if ($this->isGranted('create_other_timesheet')) {
|
||||
$event->addActionToSubmenu('create', 'single', ['title' => 'create', 'url' => $this->path('admin_timesheet_create'), 'class' => 'create-ts modal-ajax-form']);
|
||||
$event->addActionToSubmenu('create', 'multi-user', ['title' => 'create-timesheet-multiuser', 'translation_domain' => 'actions', 'url' => $this->path('admin_timesheet_create_multiuser'), 'class' => 'create-ts-mu modal-ajax-form']);
|
||||
}
|
||||
|
||||
$event->addHelp($this->documentationLink('timesheet.html'));
|
||||
}
|
||||
}
|
||||
@@ -14,21 +14,15 @@ use App\Event\PageActionsEvent;
|
||||
|
||||
class UserSubscriber extends AbstractActionsSubscriber
|
||||
{
|
||||
public static function getSubscribedEvents(): array
|
||||
public static function getActionName(): string
|
||||
{
|
||||
return [
|
||||
'actions.user' => ['onActions', 1000],
|
||||
];
|
||||
return 'user';
|
||||
}
|
||||
|
||||
public function onActions(PageActionsEvent $event)
|
||||
public function onActions(PageActionsEvent $event): void
|
||||
{
|
||||
$payload = $event->getPayload();
|
||||
|
||||
if (!isset($payload['user'])) {
|
||||
return;
|
||||
}
|
||||
|
||||
/** @var User $user */
|
||||
$user = $payload['user'];
|
||||
|
||||
@@ -36,58 +30,47 @@ class UserSubscriber extends AbstractActionsSubscriber
|
||||
return;
|
||||
}
|
||||
|
||||
$actions = $event->getActions();
|
||||
|
||||
if ($this->isGranted('view', $user)) {
|
||||
$actions['profile-stats'] = ['icon' => 'avatar', 'url' => $this->path('user_profile', ['username' => $user->getUsername()]), 'translation_domain' => 'actions'];
|
||||
$event->addAction('profile-stats', ['icon' => 'avatar', 'url' => $this->path('user_profile', ['username' => $user->getUsername()]), 'translation_domain' => 'actions']);
|
||||
$event->addDivider();
|
||||
}
|
||||
|
||||
if (\count($actions) > 0) {
|
||||
$actions['divider'] = null;
|
||||
}
|
||||
|
||||
$subActions = [];
|
||||
if ($this->isGranted('edit', $user)) {
|
||||
$subActions['edit'] = ['url' => $this->path('user_profile_edit', ['username' => $user->getUsername()]), 'title' => 'edit', 'translation_domain' => 'actions'];
|
||||
$event->addActionToSubmenu('edit', 'edit', ['url' => $this->path('user_profile_edit', ['username' => $user->getUsername()]), 'title' => 'edit', 'translation_domain' => 'actions']);
|
||||
}
|
||||
if ($this->isGranted('preferences', $user)) {
|
||||
$subActions['settings'] = ['url' => $this->path('user_profile_preferences', ['username' => $user->getUsername()]), 'title' => 'settings', 'translation_domain' => 'actions'];
|
||||
$event->addActionToSubmenu('edit', 'settings', ['url' => $this->path('user_profile_preferences', ['username' => $user->getUsername()]), 'title' => 'settings', 'translation_domain' => 'actions']);
|
||||
}
|
||||
if ($this->isGranted('password', $user)) {
|
||||
$subActions['password'] = ['url' => $this->path('user_profile_password', ['username' => $user->getUsername()]), 'title' => 'profile.password'];
|
||||
$event->addActionToSubmenu('edit', 'password', ['url' => $this->path('user_profile_password', ['username' => $user->getUsername()]), 'title' => 'profile.password']);
|
||||
}
|
||||
if ($this->isGranted('api-token', $user)) {
|
||||
$subActions['api-token'] = ['url' => $this->path('user_profile_api_token', ['username' => $user->getUsername()]), 'title' => 'profile.api-token'];
|
||||
$event->addActionToSubmenu('edit', 'api-token', ['url' => $this->path('user_profile_api_token', ['username' => $user->getUsername()]), 'title' => 'profile.api-token']);
|
||||
}
|
||||
if ($this->isGranted('teams', $user)) {
|
||||
$subActions['teams'] = ['url' => $this->path('user_profile_teams', ['username' => $user->getUsername()]), 'title' => 'profile.teams'];
|
||||
$event->addActionToSubmenu('edit', 'teams', ['url' => $this->path('user_profile_teams', ['username' => $user->getUsername()]), 'title' => 'profile.teams']);
|
||||
}
|
||||
if ($this->isGranted('roles', $user)) {
|
||||
$subActions['roles'] = ['url' => $this->path('user_profile_roles', ['username' => $user->getUsername()]), 'title' => 'profile.roles'];
|
||||
$event->addActionToSubmenu('edit', 'roles', ['url' => $this->path('user_profile_roles', ['username' => $user->getUsername()]), 'title' => 'profile.roles']);
|
||||
}
|
||||
|
||||
if (\count($subActions) > 0) {
|
||||
$actions['edit'] = ['children' => $subActions, 'title' => 'edit'];
|
||||
$actions['divider2'] = null;
|
||||
if ($event->hasSubmenu('edit')) {
|
||||
$event->addDivider();
|
||||
}
|
||||
|
||||
$viewOther = $this->isGranted('view_other_timesheet');
|
||||
if ($this->isGranted('view_reporting')) {
|
||||
if ($viewOther || ($event->getUser()->getId() === $user->getId())) {
|
||||
$actions['menu.reporting'] = ['url' => $this->path('report_user_month', ['user' => $user->getId()]), 'icon' => 'reporting'];
|
||||
$event->addAction('menu.reporting', ['url' => $this->path('report_user_month', ['user' => $user->getId()]), 'icon' => 'reporting']);
|
||||
}
|
||||
}
|
||||
|
||||
if ($viewOther && $user->isEnabled()) {
|
||||
$actions['timesheet'] = $this->path('admin_timesheet', ['users[]' => $user->getId()]);
|
||||
$event->addAction('timesheet', ['url' => $this->path('admin_timesheet', ['users[]' => $user->getId()])]);
|
||||
}
|
||||
|
||||
$view = $payload['view'] ?? null;
|
||||
|
||||
if ($view === 'index' && $this->isGranted('delete', $user)) {
|
||||
$actions['trash'] = ['url' => $this->path('admin_user_delete', ['id' => $user->getId()]), 'class' => 'modal-ajax-form'];
|
||||
if ($event->isIndexView() && $this->isGranted('delete', $user)) {
|
||||
$event->addAction('trash', ['url' => $this->path('admin_user_delete', ['id' => $user->getId()]), 'class' => 'modal-ajax-form']);
|
||||
}
|
||||
|
||||
$event->setActions($actions);
|
||||
}
|
||||
}
|
||||
|
||||
35
src/EventSubscriber/Actions/UsersSubscriber.php
Normal file
35
src/EventSubscriber/Actions/UsersSubscriber.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Kimai time-tracking app.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace App\EventSubscriber\Actions;
|
||||
|
||||
use App\Event\PageActionsEvent;
|
||||
|
||||
class UsersSubscriber extends AbstractActionsSubscriber
|
||||
{
|
||||
public static function getActionName(): string
|
||||
{
|
||||
return 'users';
|
||||
}
|
||||
|
||||
public function onActions(PageActionsEvent $event): void
|
||||
{
|
||||
$event->addSearchToggle();
|
||||
if ($event->isIndexView()) {
|
||||
$event->addColumnToggle('#modal_user_admin');
|
||||
}
|
||||
$event->addQuickExport($this->path('user_export'));
|
||||
|
||||
if ($this->isGranted('create_user')) {
|
||||
$event->addCreate($this->path('admin_user_create'), false);
|
||||
}
|
||||
|
||||
$event->addHelp($this->documentationLink('users.html'));
|
||||
}
|
||||
}
|
||||
@@ -61,6 +61,7 @@ final class UserPreferenceSubscriber implements EventSubscriberInterface
|
||||
$timezone = date_default_timezone_get();
|
||||
}
|
||||
|
||||
$enableDefaultReport = $this->voter->isGranted('view_reporting');
|
||||
$enableHourlyRate = false;
|
||||
$hourlyRateOptions = [];
|
||||
|
||||
@@ -151,6 +152,7 @@ final class UserPreferenceSubscriber implements EventSubscriberInterface
|
||||
->setValue(ReportingService::DEFAULT_VIEW)
|
||||
->setOrder(650)
|
||||
->setSection('behaviour')
|
||||
->setEnabled($enableDefaultReport)
|
||||
->setType(ReportType::class),
|
||||
|
||||
(new UserPreference())
|
||||
|
||||
Reference in New Issue
Block a user