User profile layout (#2402)
This commit is contained in:
@@ -61,6 +61,7 @@ final class ReportingController extends AbstractController
|
||||
|
||||
private function canSelectUser(): bool
|
||||
{
|
||||
// also found in App\EventSubscriber\Actions\UserSubscriber
|
||||
if (!$this->isGranted('view_other_timesheet')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -23,7 +23,6 @@ class DoctrineCompilerPass implements CompilerPassInterface
|
||||
*/
|
||||
private $allowedEngines = [
|
||||
'mysql' => 'mysql',
|
||||
'mysqli' => 'mysql',
|
||||
'sqlite' => 'sqlite',
|
||||
];
|
||||
|
||||
|
||||
@@ -394,7 +394,7 @@ class Configuration implements ConfigurationInterface
|
||||
->setDeprecated('The node "%node%" at path "%path%" is deprecated, please use "kimai.timesheet.active_entries.soft_limit" instead.')
|
||||
->end()
|
||||
->scalarNode('box_color')
|
||||
->defaultValue('green')
|
||||
->defaultValue('blue')
|
||||
->setDeprecated('The node "%node%" at path "%path%" was removed, please delete it from your config.')
|
||||
->end()
|
||||
->scalarNode('select_type')
|
||||
|
||||
41
src/Event/PageActionsEvent.php
Normal file
41
src/Event/PageActionsEvent.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?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\Event;
|
||||
|
||||
use App\Entity\User;
|
||||
|
||||
class PageActionsEvent extends ThemeEvent
|
||||
{
|
||||
private $action;
|
||||
|
||||
public function __construct(User $user, array $payload, string $action)
|
||||
{
|
||||
if (!\array_key_exists('actions', $payload)) {
|
||||
$payload['actions'] = [];
|
||||
}
|
||||
parent::__construct($user, $payload);
|
||||
$this->action = $action;
|
||||
}
|
||||
|
||||
public function getActionName(): string
|
||||
{
|
||||
return $this->action;
|
||||
}
|
||||
|
||||
public function getActions(): array
|
||||
{
|
||||
return $this->payload['actions'];
|
||||
}
|
||||
|
||||
public function setActions(array $actions): void
|
||||
{
|
||||
$this->payload['actions'] = $actions;
|
||||
}
|
||||
}
|
||||
@@ -12,7 +12,7 @@ namespace App\Event;
|
||||
use App\Entity\User;
|
||||
use Symfony\Contracts\EventDispatcher\Event;
|
||||
|
||||
final class ThemeEvent extends Event
|
||||
class ThemeEvent extends Event
|
||||
{
|
||||
public const JAVASCRIPT = 'app.theme.javascript';
|
||||
public const STYLESHEET = 'app.theme.css';
|
||||
@@ -25,15 +25,15 @@ final class ThemeEvent extends Event
|
||||
/**
|
||||
* @var User|null
|
||||
*/
|
||||
protected $user;
|
||||
private $user;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $content = '';
|
||||
private $content = '';
|
||||
/**
|
||||
* @var mixed
|
||||
*/
|
||||
protected $payload = null;
|
||||
protected $payload;
|
||||
|
||||
public function __construct(?User $user = null, $payload = null)
|
||||
{
|
||||
@@ -41,13 +41,8 @@ final class ThemeEvent extends Event
|
||||
$this->payload = $payload;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated since 1.0
|
||||
*/
|
||||
public function getUser(): ?User
|
||||
{
|
||||
@trigger_error('Using ThemeEvent::getUser() is deprecated and will be removed with 2.0', E_USER_DEPRECATED);
|
||||
|
||||
return $this->user;
|
||||
}
|
||||
|
||||
|
||||
36
src/EventSubscriber/Actions/AbstractActionsSubscriber.php
Normal file
36
src/EventSubscriber/Actions/AbstractActionsSubscriber.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 Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
|
||||
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
|
||||
|
||||
abstract class AbstractActionsSubscriber implements EventSubscriberInterface
|
||||
{
|
||||
private $auth;
|
||||
private $urlGenerator;
|
||||
|
||||
public function __construct(AuthorizationCheckerInterface $security, UrlGeneratorInterface $urlGenerator)
|
||||
{
|
||||
$this->auth = $security;
|
||||
$this->urlGenerator = $urlGenerator;
|
||||
}
|
||||
|
||||
protected function isGranted($attributes, $subject = null): bool
|
||||
{
|
||||
return $this->auth->isGranted($attributes, $subject);
|
||||
}
|
||||
|
||||
protected function path(string $route, array $parameters = []): string
|
||||
{
|
||||
return $this->urlGenerator->generate($route, $parameters);
|
||||
}
|
||||
}
|
||||
95
src/EventSubscriber/Actions/UserSubscriber.php
Normal file
95
src/EventSubscriber/Actions/UserSubscriber.php
Normal file
@@ -0,0 +1,95 @@
|
||||
<?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\User;
|
||||
use App\Event\PageActionsEvent;
|
||||
|
||||
class UserSubscriber extends AbstractActionsSubscriber
|
||||
{
|
||||
public static function getSubscribedEvents(): array
|
||||
{
|
||||
return [
|
||||
'actions.user' => ['onActions', 1000],
|
||||
];
|
||||
}
|
||||
|
||||
public function onActions(PageActionsEvent $event)
|
||||
{
|
||||
$payload = $event->getPayload();
|
||||
|
||||
if (!isset($payload['user'])) {
|
||||
return;
|
||||
}
|
||||
|
||||
/** @var User $user */
|
||||
$user = $payload['user'];
|
||||
|
||||
if ($user->getId() === null) {
|
||||
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'];
|
||||
}
|
||||
|
||||
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'];
|
||||
}
|
||||
if ($this->isGranted('preferences', $user)) {
|
||||
$subActions['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'];
|
||||
}
|
||||
if ($this->isGranted('api-token', $user)) {
|
||||
$subActions['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'];
|
||||
}
|
||||
if ($this->isGranted('roles', $user)) {
|
||||
$subActions['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;
|
||||
}
|
||||
|
||||
$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'];
|
||||
}
|
||||
}
|
||||
|
||||
if ($viewOther && $user->isEnabled()) {
|
||||
$actions['timesheet'] = $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'];
|
||||
}
|
||||
|
||||
$payload['actions'] = array_merge($payload['actions'], $actions);
|
||||
|
||||
$event->setPayload($payload);
|
||||
}
|
||||
}
|
||||
@@ -24,6 +24,7 @@ final class IconExtension extends AbstractExtension
|
||||
'audit' => 'fas fa-history',
|
||||
'avatar' => 'fas fa-user',
|
||||
'back' => 'fas fa-long-arrow-alt-left',
|
||||
'barcode' => 'fas fa-barcode',
|
||||
'calendar' => 'far fa-calendar-alt',
|
||||
'clock' => 'far fa-clock',
|
||||
'comment' => 'far fa-comment',
|
||||
@@ -51,6 +52,7 @@ final class IconExtension extends AbstractExtension
|
||||
'left' => 'fas fa-chevron-left',
|
||||
'list' => 'fas fa-list',
|
||||
'locked' => 'fas fa-lock',
|
||||
'login' => 'fas fa-sign-in-alt',
|
||||
'logout' => 'fas fa-sign-out-alt',
|
||||
'mail' => 'fas fa-envelope-open',
|
||||
'mail-sent' => 'fas fa-paper-plane',
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
namespace App\Twig\Runtime;
|
||||
|
||||
use App\Entity\User;
|
||||
use App\Event\PageActionsEvent;
|
||||
use App\Event\ThemeEvent;
|
||||
use App\Event\ThemeJavascriptTranslationsEvent;
|
||||
use Symfony\Bridge\Twig\AppVariable;
|
||||
@@ -51,6 +52,23 @@ final class ThemeExtension implements RuntimeExtensionInterface
|
||||
return $themeEvent;
|
||||
}
|
||||
|
||||
public function actions(User $user, string $action, array $payload): ThemeEvent
|
||||
{
|
||||
if (!\array_key_exists('actions', $payload)) {
|
||||
$payload['actions'] = [];
|
||||
}
|
||||
|
||||
$themeEvent = new PageActionsEvent($user, $payload, $action);
|
||||
|
||||
$eventName = 'actions.' . $action;
|
||||
|
||||
if ($this->eventDispatcher->hasListeners($eventName)) {
|
||||
$this->eventDispatcher->dispatch($themeEvent, $eventName);
|
||||
}
|
||||
|
||||
return $themeEvent;
|
||||
}
|
||||
|
||||
public function getJavascriptTranslations(): array
|
||||
{
|
||||
$event = new ThemeJavascriptTranslationsEvent();
|
||||
|
||||
@@ -28,6 +28,7 @@ class RuntimeExtensions extends AbstractExtension
|
||||
{
|
||||
return [
|
||||
new TwigFunction('trigger', [ThemeExtension::class, 'trigger'], ['needs_environment' => true]),
|
||||
new TwigFunction('actions', [ThemeExtension::class, 'actions']),
|
||||
new TwigFunction('javascript_translations', [ThemeExtension::class, 'getJavascriptTranslations']),
|
||||
new TwigFunction('timesheet_exporter', [ExporterExtension::class, 'getTimesheetExporter']),
|
||||
new TwigFunction('active_timesheets', [TimesheetExtension::class, 'activeEntries']),
|
||||
|
||||
Reference in New Issue
Block a user