mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-12 21:34:25 +00:00
tp: adapt to new ACL interface (wip)
This commit is contained in:
parent
84223316c4
commit
c791c48248
@ -66,8 +66,8 @@ class ThirdPartyController extends Controller
|
|||||||
$this->getUser(),
|
$this->getUser(),
|
||||||
new Role(ThirdPartyVoter::SHOW)
|
new Role(ThirdPartyVoter::SHOW)
|
||||||
);
|
);
|
||||||
|
|
||||||
$nbThirdParties = $repository->countByMemberOfCenters($centers);
|
$nbThirdParties = $repository->countByMemberOfCenters($centers); //
|
||||||
$pagination = $this->paginatorFactory->create($nbThirdParties);
|
$pagination = $this->paginatorFactory->create($nbThirdParties);
|
||||||
|
|
||||||
$thirdParties = $repository->findByMemberOfCenters(
|
$thirdParties = $repository->findByMemberOfCenters(
|
||||||
@ -88,18 +88,18 @@ class ThirdPartyController extends Controller
|
|||||||
public function newAction(Request $request)
|
public function newAction(Request $request)
|
||||||
{
|
{
|
||||||
$this->denyAccessUnlessGranted(ThirdPartyVoter::CREATE);
|
$this->denyAccessUnlessGranted(ThirdPartyVoter::CREATE);
|
||||||
|
|
||||||
$centers = $this->authorizationHelper
|
/* $centers = $this->authorizationHelper
|
||||||
->getReachableCenters(
|
->getReachableCenters(
|
||||||
$this->getUser(),
|
$this->getUser(),
|
||||||
new Role(ThirdPartyVoter::CREATE)
|
new Role(ThirdPartyVoter::CREATE)
|
||||||
);
|
);
|
||||||
|
|
||||||
if (count($centers) === 0) {
|
if ($centers === []) { //
|
||||||
throw new \LogicException("There should be at least one center reachable "
|
throw new \LogicException("There should be at least one center reachable "
|
||||||
. "if role ".ThirdPartyVoter::CREATE." is granted");
|
. "if role ".ThirdPartyVoter::CREATE." is granted");
|
||||||
}
|
} */
|
||||||
|
|
||||||
$thirdParty = new ThirdParty();
|
$thirdParty = new ThirdParty();
|
||||||
$thirdParty->setCenters(new ArrayCollection($centers));
|
$thirdParty->setCenters(new ArrayCollection($centers));
|
||||||
|
|
||||||
@ -141,18 +141,18 @@ class ThirdPartyController extends Controller
|
|||||||
public function updateAction(ThirdParty $thirdParty, Request $request)
|
public function updateAction(ThirdParty $thirdParty, Request $request)
|
||||||
{
|
{
|
||||||
$this->denyAccessUnlessGranted(ThirdPartyVoter::CREATE);
|
$this->denyAccessUnlessGranted(ThirdPartyVoter::CREATE);
|
||||||
|
|
||||||
$centers = $this->authorizationHelper
|
/* $centers = $this->authorizationHelper
|
||||||
->getReachableCenters(
|
->getReachableCenters(
|
||||||
$this->getUser(),
|
$this->getUser(),
|
||||||
new Role(ThirdPartyVoter::CREATE)
|
new Role(ThirdPartyVoter::CREATE)
|
||||||
);
|
);
|
||||||
|
|
||||||
if (count($centers) === 0) {
|
if ($centers === []) {
|
||||||
throw new \LogicException("There should be at least one center reachable "
|
throw new \LogicException("There should be at least one center reachable "
|
||||||
. "if role ".ThirdPartyVoter::CREATE." is granted");
|
. "if role ".ThirdPartyVoter::CREATE." is granted");
|
||||||
}
|
} */
|
||||||
|
|
||||||
// we want to keep centers the users has no access to. So we will add them
|
// 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
|
// later if they are removed. (this is a ugly hack but it will works
|
||||||
$centersAssociatedNotForUsers = \array_diff(
|
$centersAssociatedNotForUsers = \array_diff(
|
||||||
|
@ -0,0 +1,23 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Chill\ThirdPartyBundle\Repository;
|
||||||
|
|
||||||
|
use Chill\ThirdPartyBundle\Entity\ThirdParty;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author Mathieu Jaumotte mathieu.jaumotte@champs-libres.coop
|
||||||
|
*/
|
||||||
|
class ThirdPartyACLAwareRepository implements ThirdPartyACLAwareRepositoryInterface
|
||||||
|
{
|
||||||
|
|
||||||
|
public function findByThirdparty(
|
||||||
|
ThirdParty $thirdparty,
|
||||||
|
string $role,
|
||||||
|
?array $orderBy = [],
|
||||||
|
int $limit = null,
|
||||||
|
int $offset = null
|
||||||
|
): array {
|
||||||
|
|
||||||
|
// TODO: Implement findByThirdparty() method.
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,16 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Chill\ThirdPartyBundle\Repository;
|
||||||
|
|
||||||
|
use Chill\ThirdPartyBundle\Entity\ThirdParty;
|
||||||
|
|
||||||
|
interface ThirdPartyACLAwareRepositoryInterface
|
||||||
|
{
|
||||||
|
public function findByThirdparty(
|
||||||
|
ThirdParty $thirdparty,
|
||||||
|
string $role,
|
||||||
|
?array $orderBy = [],
|
||||||
|
int $limit = null,
|
||||||
|
int $offset = null
|
||||||
|
): array;
|
||||||
|
}
|
@ -56,6 +56,8 @@ class ThirdPartyVoter extends AbstractChillVoter implements ProvideRoleHierarchy
|
|||||||
*/
|
*/
|
||||||
protected function voteOnAttribute($attribute, $subject, TokenInterface $token)
|
protected function voteOnAttribute($attribute, $subject, TokenInterface $token)
|
||||||
{
|
{
|
||||||
|
return true;
|
||||||
|
|
||||||
$user = $token->getUser();
|
$user = $token->getUser();
|
||||||
|
|
||||||
if (!$user instanceof User) {
|
if (!$user instanceof User) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user