mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
Fixed: [create person] handle case when the user has two differents groups in the same center
Fix https://gitlab.com/Chill-Projet/chill-bundles/-/issues/72
This commit is contained in:
parent
9853845c9c
commit
ef13833966
@ -63,7 +63,7 @@ class AuthorizationHelper implements AuthorizationHelperInterface
|
|||||||
*
|
*
|
||||||
* @param User $user The user
|
* @param User $user The user
|
||||||
* @param array $centers a list of centers which are going to be filtered
|
* @param array $centers a list of centers which are going to be filtered
|
||||||
* @param Center|string $role
|
* @param string $role
|
||||||
*/
|
*/
|
||||||
public function filterReachableCenters(User $user, array $centers, $role): array
|
public function filterReachableCenters(User $user, array $centers, $role): array
|
||||||
{
|
{
|
||||||
@ -113,13 +113,14 @@ class AuthorizationHelper implements AuthorizationHelperInterface
|
|||||||
* Get reachable Centers for the given user, role,
|
* Get reachable Centers for the given user, role,
|
||||||
* and optionally Scope.
|
* and optionally Scope.
|
||||||
*
|
*
|
||||||
* @return array|Center[]
|
* @return list<Center>
|
||||||
*/
|
*/
|
||||||
public function getReachableCenters(UserInterface $user, string $role, ?Scope $scope = null): array
|
public function getReachableCenters(UserInterface $user, string $role, ?Scope $scope = null): array
|
||||||
{
|
{
|
||||||
if ($role instanceof Role) {
|
if ($role instanceof Role) {
|
||||||
$role = $role->getRole();
|
$role = $role->getRole();
|
||||||
}
|
}
|
||||||
|
/** @var array<string, Center> $centers */
|
||||||
$centers = [];
|
$centers = [];
|
||||||
|
|
||||||
foreach ($user->getGroupCenters() as $groupCenter) {
|
foreach ($user->getGroupCenters() as $groupCenter) {
|
||||||
@ -129,13 +130,13 @@ class AuthorizationHelper implements AuthorizationHelperInterface
|
|||||||
//check that the role is in the reachable roles
|
//check that the role is in the reachable roles
|
||||||
if ($this->isRoleReached($role, $roleScope->getRole())) {
|
if ($this->isRoleReached($role, $roleScope->getRole())) {
|
||||||
if (null === $scope) {
|
if (null === $scope) {
|
||||||
$centers[] = $groupCenter->getCenter();
|
$centers[spl_object_hash($groupCenter->getCenter())] = $groupCenter->getCenter();
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($scope->getId() === $roleScope->getScope()->getId()) {
|
if ($scope->getId() === $roleScope->getScope()->getId()) {
|
||||||
$centers[] = $groupCenter->getCenter();
|
$centers[spl_object_hash($groupCenter->getCenter())] = $groupCenter->getCenter();
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -143,7 +144,7 @@ class AuthorizationHelper implements AuthorizationHelperInterface
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $centers;
|
return array_values($centers);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -194,7 +195,7 @@ class AuthorizationHelper implements AuthorizationHelperInterface
|
|||||||
*
|
*
|
||||||
* @return array|Scope[]
|
* @return array|Scope[]
|
||||||
*/
|
*/
|
||||||
public function getReachableScopes(UserInterface $user, string $role, $center): array
|
public function getReachableScopes(UserInterface $user, string $role, Center|array $center): array
|
||||||
{
|
{
|
||||||
if ($role instanceof Role) {
|
if ($role instanceof Role) {
|
||||||
$role = $role->getRole();
|
$role = $role->getRole();
|
||||||
|
@ -21,12 +21,12 @@ interface AuthorizationHelperInterface
|
|||||||
* Get reachable Centers for the given user, role,
|
* Get reachable Centers for the given user, role,
|
||||||
* and optionnaly Scope.
|
* and optionnaly Scope.
|
||||||
*
|
*
|
||||||
* @return Center[]
|
* @return list<Center>
|
||||||
*/
|
*/
|
||||||
public function getReachableCenters(UserInterface $user, string $role, ?Scope $scope = null): array;
|
public function getReachableCenters(UserInterface $user, string $role, ?Scope $scope = null): array;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param array|Center|Center[] $center
|
* @param Center|list<Center> $center
|
||||||
*/
|
*/
|
||||||
public function getReachableScopes(UserInterface $user, string $role, $center): array;
|
public function getReachableScopes(UserInterface $user, string $role, Center|array $center): array;
|
||||||
}
|
}
|
||||||
|
@ -11,6 +11,8 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace Chill\PersonBundle\Controller;
|
namespace Chill\PersonBundle\Controller;
|
||||||
|
|
||||||
|
use Chill\MainBundle\Security\Authorization\AuthorizationHelper;
|
||||||
|
use Chill\MainBundle\Security\Authorization\AuthorizationHelperInterface;
|
||||||
use Chill\PersonBundle\Config\ConfigPersonAltNamesHelper;
|
use Chill\PersonBundle\Config\ConfigPersonAltNamesHelper;
|
||||||
use Chill\PersonBundle\Entity\Household\Household;
|
use Chill\PersonBundle\Entity\Household\Household;
|
||||||
use Chill\PersonBundle\Entity\Household\HouseholdMember;
|
use Chill\PersonBundle\Entity\Household\HouseholdMember;
|
||||||
@ -20,6 +22,7 @@ use Chill\PersonBundle\Form\PersonType;
|
|||||||
use Chill\PersonBundle\Privacy\PrivacyEvent;
|
use Chill\PersonBundle\Privacy\PrivacyEvent;
|
||||||
use Chill\PersonBundle\Repository\PersonRepository;
|
use Chill\PersonBundle\Repository\PersonRepository;
|
||||||
use Chill\PersonBundle\Search\SimilarPersonMatcher;
|
use Chill\PersonBundle\Search\SimilarPersonMatcher;
|
||||||
|
use Chill\PersonBundle\Security\Authorization\PersonVoter;
|
||||||
use DateTimeImmutable;
|
use DateTimeImmutable;
|
||||||
use Doctrine\ORM\EntityManagerInterface;
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
use Psr\Log\LoggerInterface;
|
use Psr\Log\LoggerInterface;
|
||||||
@ -44,6 +47,8 @@ use function is_array;
|
|||||||
|
|
||||||
final class PersonController extends AbstractController
|
final class PersonController extends AbstractController
|
||||||
{
|
{
|
||||||
|
private AuthorizationHelperInterface $authorizationHelper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var ConfigPersonAltNamesHelper
|
* @var ConfigPersonAltNamesHelper
|
||||||
*/
|
*/
|
||||||
@ -87,6 +92,7 @@ final class PersonController extends AbstractController
|
|||||||
private $validator;
|
private $validator;
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
|
AuthorizationHelperInterface $authorizationHelper,
|
||||||
SimilarPersonMatcher $similarPersonMatcher,
|
SimilarPersonMatcher $similarPersonMatcher,
|
||||||
TranslatorInterface $translator,
|
TranslatorInterface $translator,
|
||||||
EventDispatcherInterface $eventDispatcher,
|
EventDispatcherInterface $eventDispatcher,
|
||||||
@ -97,6 +103,7 @@ final class PersonController extends AbstractController
|
|||||||
EntityManagerInterface $em,
|
EntityManagerInterface $em,
|
||||||
Security $security
|
Security $security
|
||||||
) {
|
) {
|
||||||
|
$this->authorizationHelper = $authorizationHelper;
|
||||||
$this->similarPersonMatcher = $similarPersonMatcher;
|
$this->similarPersonMatcher = $similarPersonMatcher;
|
||||||
$this->translator = $translator;
|
$this->translator = $translator;
|
||||||
$this->eventDispatcher = $eventDispatcher;
|
$this->eventDispatcher = $eventDispatcher;
|
||||||
@ -206,22 +213,15 @@ final class PersonController extends AbstractController
|
|||||||
*
|
*
|
||||||
* The next post compare the data with previous one and, if yes, show a
|
* The next post compare the data with previous one and, if yes, show a
|
||||||
* review page if there are "alternate persons".
|
* review page if there are "alternate persons".
|
||||||
*
|
|
||||||
* @return Response|\Symfony\Component\HttpFoundation\RedirectResponse
|
|
||||||
*/
|
*/
|
||||||
public function newAction(Request $request)
|
public function newAction(Request $request): Response
|
||||||
{
|
{
|
||||||
$person = new Person();
|
$person = new Person();
|
||||||
|
|
||||||
if (
|
$authorizedCenters =$this->authorizationHelper->getReachableCenters($this->getUser(), PersonVoter::CREATE);
|
||||||
1 === count($this->security->getUser()
|
|
||||||
->getGroupCenters())
|
if (1 === count($authorizedCenters)) {
|
||||||
) {
|
$person->setCenter($authorizedCenters[0]);
|
||||||
$person->setCenter(
|
|
||||||
$this->security->getUser()
|
|
||||||
->getGroupCenters()[0]
|
|
||||||
->getCenter()
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$form = $this->createForm(CreationPersonType::class, $person)
|
$form = $this->createForm(CreationPersonType::class, $person)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user