mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-13 13:54:23 +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:
parent
59fed905e9
commit
92e6506ecb
@ -61,20 +61,10 @@ class ThirdPartyController extends Controller
|
|||||||
$repository = $this->getDoctrine()->getManager()
|
$repository = $this->getDoctrine()->getManager()
|
||||||
->getRepository(ThirdParty::class);
|
->getRepository(ThirdParty::class);
|
||||||
|
|
||||||
$centers = $this->authorizationHelper
|
$nbThirdParties = $repository->count([]); //$repository->countByMemberOfCenters($centers);
|
||||||
->getReachableCenters(
|
|
||||||
$this->getUser(),
|
|
||||||
new Role(ThirdPartyVoter::SHOW)
|
|
||||||
);
|
|
||||||
|
|
||||||
$nbThirdParties = $repository->countByMemberOfCenters($centers);
|
|
||||||
$pagination = $this->paginatorFactory->create($nbThirdParties);
|
$pagination = $this->paginatorFactory->create($nbThirdParties);
|
||||||
|
|
||||||
$thirdParties = $repository->findByMemberOfCenters(
|
$thirdParties = $repository->findAll();
|
||||||
$centers,
|
|
||||||
$pagination->getCurrentPage()->getFirstItemNumber(),
|
|
||||||
$pagination->getItemsPerPage()
|
|
||||||
);
|
|
||||||
|
|
||||||
return $this->render('ChillThirdPartyBundle:ThirdParty:index.html.twig', array(
|
return $this->render('ChillThirdPartyBundle:ThirdParty:index.html.twig', array(
|
||||||
'third_parties' => $thirdParties,
|
'third_parties' => $thirdParties,
|
||||||
@ -89,16 +79,7 @@ class ThirdPartyController extends Controller
|
|||||||
{
|
{
|
||||||
$this->denyAccessUnlessGranted(ThirdPartyVoter::CREATE);
|
$this->denyAccessUnlessGranted(ThirdPartyVoter::CREATE);
|
||||||
|
|
||||||
$centers = $this->authorizationHelper
|
$centers = [];
|
||||||
->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");
|
|
||||||
}
|
|
||||||
|
|
||||||
$thirdParty = new ThirdParty();
|
$thirdParty = new ThirdParty();
|
||||||
$thirdParty->setCenters(new ArrayCollection($centers));
|
$thirdParty->setCenters(new ArrayCollection($centers));
|
||||||
@ -142,16 +123,10 @@ class ThirdPartyController extends Controller
|
|||||||
{
|
{
|
||||||
$this->denyAccessUnlessGranted(ThirdPartyVoter::CREATE);
|
$this->denyAccessUnlessGranted(ThirdPartyVoter::CREATE);
|
||||||
|
|
||||||
$centers = $this->authorizationHelper
|
$repository = $this->getDoctrine()->getManager()
|
||||||
->getReachableCenters(
|
->getRepository(ThirdParty::class);
|
||||||
$this->getUser(),
|
|
||||||
new Role(ThirdPartyVoter::CREATE)
|
|
||||||
);
|
|
||||||
|
|
||||||
if (count($centers) === 0) {
|
$centers = $repository->findAll();
|
||||||
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
|
// 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
|
||||||
|
@ -341,7 +341,7 @@ class ThirdParty
|
|||||||
*/
|
*/
|
||||||
public function getTypes()
|
public function getTypes()
|
||||||
{
|
{
|
||||||
return $this->type;
|
return $this->types;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -64,10 +64,10 @@ class ThirdPartyType extends AbstractType
|
|||||||
}
|
}
|
||||||
if (count($types) === 1) {
|
if (count($types) === 1) {
|
||||||
$builder
|
$builder
|
||||||
->add('type', HiddenType::class, [
|
->add('types', HiddenType::class, [
|
||||||
'data' => array_values($types)
|
'data' => array_values($types)
|
||||||
])
|
])
|
||||||
->get('type')
|
->get('types')
|
||||||
->addModelTransformer(new CallbackTransformer(
|
->addModelTransformer(new CallbackTransformer(
|
||||||
function (?array $typeArray): ?string {
|
function (?array $typeArray): ?string {
|
||||||
if (null === $typeArray) {
|
if (null === $typeArray) {
|
||||||
@ -84,7 +84,7 @@ class ThirdPartyType extends AbstractType
|
|||||||
))
|
))
|
||||||
;
|
;
|
||||||
} else {
|
} else {
|
||||||
$builder->add('type', ChoiceType::class, [
|
$builder->add('types', ChoiceType::class, [
|
||||||
'choices' => $types,
|
'choices' => $types,
|
||||||
'expanded' => true,
|
'expanded' => true,
|
||||||
'multiple' => true,
|
'multiple' => true,
|
||||||
|
@ -51,7 +51,7 @@
|
|||||||
<th>{{ (tp.active ? '<i class="fa fa-check chill-green">' : '<i class="fa fa-times chill-red">')|raw }}</th>
|
<th>{{ (tp.active ? '<i class="fa fa-check chill-green">' : '<i class="fa fa-times chill-red">')|raw }}</th>
|
||||||
<td>{{ tp.name }}</td>
|
<td>{{ tp.name }}</td>
|
||||||
{% set types = [] %}
|
{% set types = [] %}
|
||||||
{% for t in tp.type %}
|
{% for t in tp.types %}
|
||||||
{% set types = types|merge( [ ('chill_3party.key_label.'~t)|trans ] ) %}
|
{% set types = types|merge( [ ('chill_3party.key_label.'~t)|trans ] ) %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
<td>{{ types|join(', ') }}</td>
|
<td>{{ types|join(', ') }}</td>
|
||||||
|
@ -26,7 +26,7 @@
|
|||||||
{{ form_row(form.profession) }}
|
{{ form_row(form.profession) }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{{ form_row(form.type) }}
|
{{ form_row(form.types) }}
|
||||||
{{ form_row(form.categories) }}
|
{{ form_row(form.categories) }}
|
||||||
|
|
||||||
{{ form_row(form.telephone) }}
|
{{ form_row(form.telephone) }}
|
||||||
|
@ -48,7 +48,7 @@
|
|||||||
|
|
||||||
<dt>{{ 'Type'|trans }}</dt>
|
<dt>{{ 'Type'|trans }}</dt>
|
||||||
{% set types = [] %}
|
{% set types = [] %}
|
||||||
{% for t in thirdParty.type %}
|
{% for t in thirdParty.types %}
|
||||||
{% set types = types|merge( [ ('chill_3party.key_label.'~t)|trans ] ) %}
|
{% set types = types|merge( [ ('chill_3party.key_label.'~t)|trans ] ) %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
<dd>
|
<dd>
|
||||||
|
@ -43,7 +43,7 @@
|
|||||||
{{ form_row(form.profession) }}
|
{{ form_row(form.profession) }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{{ form_row(form.type) }}
|
{{ form_row(form.types) }}
|
||||||
{{ form_row(form.categories) }}
|
{{ form_row(form.categories) }}
|
||||||
|
|
||||||
{{ form_row(form.telephone) }}
|
{{ form_row(form.telephone) }}
|
||||||
|
@ -56,8 +56,6 @@ 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