tp: adapt to new ACL interface (wip)

This commit is contained in:
Mathieu Jaumotte 2021-09-28 14:06:52 +02:00
parent 84223316c4
commit c791c48248
4 changed files with 57 additions and 16 deletions

View File

@ -67,7 +67,7 @@ class ThirdPartyController extends Controller
new Role(ThirdPartyVoter::SHOW)
);
$nbThirdParties = $repository->countByMemberOfCenters($centers);
$nbThirdParties = $repository->countByMemberOfCenters($centers); //
$pagination = $this->paginatorFactory->create($nbThirdParties);
$thirdParties = $repository->findByMemberOfCenters(
@ -89,16 +89,16 @@ class ThirdPartyController extends Controller
{
$this->denyAccessUnlessGranted(ThirdPartyVoter::CREATE);
$centers = $this->authorizationHelper
/* $centers = $this->authorizationHelper
->getReachableCenters(
$this->getUser(),
new Role(ThirdPartyVoter::CREATE)
);
if (count($centers) === 0) {
if ($centers === []) { //
throw new \LogicException("There should be at least one center reachable "
. "if role ".ThirdPartyVoter::CREATE." is granted");
}
} */
$thirdParty = new ThirdParty();
$thirdParty->setCenters(new ArrayCollection($centers));
@ -142,16 +142,16 @@ class ThirdPartyController extends Controller
{
$this->denyAccessUnlessGranted(ThirdPartyVoter::CREATE);
$centers = $this->authorizationHelper
/* $centers = $this->authorizationHelper
->getReachableCenters(
$this->getUser(),
new Role(ThirdPartyVoter::CREATE)
);
if (count($centers) === 0) {
if ($centers === []) {
throw new \LogicException("There should be at least one center reachable "
. "if role ".ThirdPartyVoter::CREATE." is granted");
}
} */
// 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

View File

@ -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.
}
}

View File

@ -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;
}

View File

@ -56,6 +56,8 @@ class ThirdPartyVoter extends AbstractChillVoter implements ProvideRoleHierarchy
*/
protected function voteOnAttribute($attribute, $subject, TokenInterface $token)
{
return true;
$user = $token->getUser();
if (!$user instanceof User) {