Improve create and start permission handling (#613)

This commit is contained in:
Kevin Papst
2019-03-06 10:24:27 +01:00
committed by GitHub
parent bce85b04d6
commit e260dd84ad
31 changed files with 258 additions and 86 deletions

View File

@@ -0,0 +1,55 @@
<?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\Security;
use App\Entity\User;
use App\Repository\UserRepository;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
class CurrentUser
{
/**
* @var TokenStorageInterface
*/
protected $storage;
/**
* @var UserRepository
*/
protected $repository;
/**
* @param TokenStorageInterface $storage
* @param UserRepository $repository
*/
public function __construct(TokenStorageInterface $storage, UserRepository $repository)
{
$this->storage = $storage;
$this->repository = $repository;
}
/**
* @return User|null
*/
public function getUser()
{
if (null === $this->storage->getToken()) {
return null;
}
/** @var User $user */
$user = $this->storage->getToken()->getUser();
if (!($user instanceof User)) {
return null;
}
return $this->repository->getById($user->getId());
}
}