mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-21 15:13:50 +00:00
tp: adapt controller/entity/formtype to works with new ACL (TO BE CHECKED)
* rename type by types -> getTypes() getter * adapt controller to fix centers errors * remove voteOnAttribute return always true in voter
This commit is contained in:
@@ -60,22 +60,12 @@ class ThirdPartyController extends Controller
|
||||
$this->denyAccessUnlessGranted(ThirdPartyVoter::SHOW);
|
||||
$repository = $this->getDoctrine()->getManager()
|
||||
->getRepository(ThirdParty::class);
|
||||
|
||||
$centers = $this->authorizationHelper
|
||||
->getReachableCenters(
|
||||
$this->getUser(),
|
||||
new Role(ThirdPartyVoter::SHOW)
|
||||
);
|
||||
|
||||
$nbThirdParties = $repository->countByMemberOfCenters($centers);
|
||||
|
||||
$nbThirdParties = $repository->count([]); //$repository->countByMemberOfCenters($centers);
|
||||
$pagination = $this->paginatorFactory->create($nbThirdParties);
|
||||
|
||||
$thirdParties = $repository->findByMemberOfCenters(
|
||||
$centers,
|
||||
$pagination->getCurrentPage()->getFirstItemNumber(),
|
||||
$pagination->getItemsPerPage()
|
||||
);
|
||||
|
||||
|
||||
$thirdParties = $repository->findAll();
|
||||
|
||||
return $this->render('ChillThirdPartyBundle:ThirdParty:index.html.twig', array(
|
||||
'third_parties' => $thirdParties,
|
||||
'pagination' => $pagination
|
||||
@@ -88,18 +78,9 @@ class ThirdPartyController extends Controller
|
||||
public function newAction(Request $request)
|
||||
{
|
||||
$this->denyAccessUnlessGranted(ThirdPartyVoter::CREATE);
|
||||
|
||||
$centers = $this->authorizationHelper
|
||||
->getReachableCenters(
|
||||
$this->getUser(),
|
||||
new Role(ThirdPartyVoter::CREATE)
|
||||
);
|
||||
|
||||
if (count($centers) === 0) {
|
||||
throw new \LogicException("There should be at least one center reachable "
|
||||
. "if role ".ThirdPartyVoter::CREATE." is granted");
|
||||
}
|
||||
|
||||
|
||||
$centers = [];
|
||||
|
||||
$thirdParty = new ThirdParty();
|
||||
$thirdParty->setCenters(new ArrayCollection($centers));
|
||||
|
||||
@@ -141,18 +122,12 @@ class ThirdPartyController extends Controller
|
||||
public function updateAction(ThirdParty $thirdParty, Request $request)
|
||||
{
|
||||
$this->denyAccessUnlessGranted(ThirdPartyVoter::CREATE);
|
||||
|
||||
$centers = $this->authorizationHelper
|
||||
->getReachableCenters(
|
||||
$this->getUser(),
|
||||
new Role(ThirdPartyVoter::CREATE)
|
||||
);
|
||||
|
||||
if (count($centers) === 0) {
|
||||
throw new \LogicException("There should be at least one center reachable "
|
||||
. "if role ".ThirdPartyVoter::CREATE." is granted");
|
||||
}
|
||||
|
||||
|
||||
$repository = $this->getDoctrine()->getManager()
|
||||
->getRepository(ThirdParty::class);
|
||||
|
||||
$centers = $repository->findAll();
|
||||
|
||||
// we want to keep centers the users has no access to. So we will add them
|
||||
// later if they are removed. (this is a ugly hack but it will works
|
||||
$centersAssociatedNotForUsers = \array_diff(
|
||||
|
Reference in New Issue
Block a user