mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-06 15:59:51 +00:00
fix right to create person for amli use
This commit is contained in:
parent
ad63df85c7
commit
e2634b0b0f
@ -11,6 +11,7 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace Chill\PersonBundle\Controller;
|
namespace Chill\PersonBundle\Controller;
|
||||||
|
|
||||||
|
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 +21,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 +46,8 @@ use function is_array;
|
|||||||
|
|
||||||
final class PersonController extends AbstractController
|
final class PersonController extends AbstractController
|
||||||
{
|
{
|
||||||
|
private AuthorizationHelperInterface $authorizationHelper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var ConfigPersonAltNamesHelper
|
* @var ConfigPersonAltNamesHelper
|
||||||
*/
|
*/
|
||||||
@ -85,6 +89,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,
|
||||||
@ -95,6 +100,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;
|
||||||
@ -211,15 +217,10 @@ final class PersonController extends AbstractController
|
|||||||
{
|
{
|
||||||
$person = new Person();
|
$person = new Person();
|
||||||
|
|
||||||
if (
|
$centers = $this->authorizationHelper->getReachableCenters($this->getUser(), PersonVoter::CREATE);
|
||||||
1 === count($this->security->getUser()
|
|
||||||
->getGroupCenters())
|
if (1 === count($centers)) {
|
||||||
) {
|
$person->setCenter($centers[0]);
|
||||||
$person->setCenter(
|
|
||||||
$this->security->getUser()
|
|
||||||
->getGroupCenters()[0]
|
|
||||||
->getCenter()
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$form = $this->createForm(CreationPersonType::class, $person)
|
$form = $this->createForm(CreationPersonType::class, $person)
|
||||||
@ -246,6 +247,8 @@ final class PersonController extends AbstractController
|
|||||||
false === $this->isLastPostDataChanges($form, $request, true)
|
false === $this->isLastPostDataChanges($form, $request, true)
|
||||||
|| count($alternatePersons) === 0
|
|| count($alternatePersons) === 0
|
||||||
) {
|
) {
|
||||||
|
$this->denyAccessUnlessGranted(PersonVoter::CREATE, $person);
|
||||||
|
|
||||||
$this->em->persist($person);
|
$this->em->persist($person);
|
||||||
|
|
||||||
$this->em->flush();
|
$this->em->flush();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user