mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-12 21:34:25 +00:00
DX: [authorization helper] Create an authorization helper with current user already available
See https://gitlab.com/Chill-Projet/chill-bundles/-/issues/14
This commit is contained in:
parent
ba261ddeb9
commit
1585a73974
@ -0,0 +1,46 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Chill is a software for social workers
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view
|
||||||
|
* the LICENSE file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Chill\MainBundle\Security\Authorization;
|
||||||
|
|
||||||
|
use Chill\MainBundle\Entity\User;
|
||||||
|
use Symfony\Component\Security\Core\Security;
|
||||||
|
|
||||||
|
class AuthorizationHelperForCurrentUser implements AuthorizationHelperForCurrentUserInterface
|
||||||
|
{
|
||||||
|
private AuthorizationHelperInterface $authorizationHelper;
|
||||||
|
|
||||||
|
private Security $security;
|
||||||
|
|
||||||
|
public function __construct(AuthorizationHelperInterface $authorizationHelper, Security $security)
|
||||||
|
{
|
||||||
|
$this->authorizationHelper = $authorizationHelper;
|
||||||
|
$this->security = $security;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getReachableCenters(string $role, ?Scope $scope = null): array
|
||||||
|
{
|
||||||
|
if (!$this->security->getUser() instanceof User) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->authorizationHelper->getReachableCenters($this->security->getUser(), $role, $scope);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getReachableScopes(string $role, $center): array
|
||||||
|
{
|
||||||
|
if (!$this->security->getUser() instanceof User) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->authorizationHelper->getReachableScopes($this->security->getUser(), $role, $center);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,28 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Chill is a software for social workers
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view
|
||||||
|
* the LICENSE file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Chill\MainBundle\Security\Authorization;
|
||||||
|
|
||||||
|
interface AuthorizationHelperForCurrentUserInterface
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Get reachable Centers for the given user, role,
|
||||||
|
* and optionnaly Scope.
|
||||||
|
*
|
||||||
|
* @return Center[]
|
||||||
|
*/
|
||||||
|
public function getReachableCenters(string $role, ?Scope $scope = null): array;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array|Center|Center[] $center
|
||||||
|
*/
|
||||||
|
public function getReachableScopes(string $role, $center): array;
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user