Commit 43f00f57 by Julien Jorry

BO : empêcher la suppresion des groupes admin

parent ff11addd
...@@ -9,8 +9,12 @@ sonata_user: ...@@ -9,8 +9,12 @@ sonata_user:
admin: # Admin Classes admin: # Admin Classes
user: user:
class: App\Application\Sonata\UserBundle\Admin\UserAdmin class: App\Application\Sonata\UserBundle\Admin\UserAdmin
# controller: SonataAdminBundle:CRUD controller: App\Controller\CRUD\CRUDController
translation: SonataUserBundle translation: SonataUserBundle
group:
class: Sonata\UserBundle\Admin\Entity\GroupAdmin
controller: App\Controller\CRUD\GroupCRUDController
translation: SonataUserBundle
impersonating: impersonating:
route: sonata_admin_dashboard route: sonata_admin_dashboard
......
<?php
namespace App\Controller\CRUD;
use Sonata\AdminBundle\Controller\CRUDController as Controller;
use Sonata\AdminBundle\Datagrid\ProxyQueryInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;
class GroupCRUDController extends Controller
{
public function deleteAction($id)
{
$request = $this->getRequest();
$id = $request->get($this->admin->getIdParameter());
$object = $this->admin->getObject($id);
if (!$object) {
throw $this->createNotFoundException(sprintf('unable to find the object with id: %s', $id));
}
if ($object->hasRole('ROLE_ADMIN_SIEGE') || $object->hasRole('ROLE_SUPER_ADMIN') || $object->hasRole('ROLE_ADMIN')) {
$this->addFlash(
'sonata_flash_error',
'Vous ne pouvez pas supprimer les groupe ayant les rôles ROLE_SUPER_ADMIN, ROLE_ADMIN et ROLE_ADMIN_SIEGE !'
);
return $this->redirectTo($object);
}
return parent::deleteAction($id);
}
public function batchActionDelete(ProxyQueryInterface $query)
{
$objects = $query->execute();
foreach ($objects as $object) {
if ($object->hasRole('ROLE_ADMIN_SIEGE') || $object->hasRole('ROLE_SUPER_ADMIN') || $object->hasRole('ROLE_ADMIN')) {
$this->addFlash(
'sonata_flash_error',
'Vous ne pouvez pas supprimer les groupe ayant les rôles ROLE_SUPER_ADMIN, ROLE_ADMIN et ROLE_ADMIN_SIEGE !'
);
return new RedirectResponse(
$this->admin->generateUrl('list', array('filter' => $this->admin->getFilterParameters()))
);
}
}
return parent::batchActionDelete($query);
}
}
...@@ -24,36 +24,8 @@ class IndexController extends AbstractController ...@@ -24,36 +24,8 @@ class IndexController extends AbstractController
// array('%name%' => $user->getName()) // array('%name%' => $user->getName())
// ); // );
// GEOCODING ADDRESS :
// $httpClient = new \Http\Adapter\Guzzle6\Client();
// $provider = Nominatim::withOpenStreetMapServer($httpClient, 'test');
// $geocoder = new \Geocoder\StatefulGeocoder($provider, 'fr');
// $result = $geocoder->geocodeQuery(GeocodeQuery::create("19300 Rosiers-d'Egletons"));
// dump($result);
// exit();
return $this->render('index.html.twig', [ return $this->render('index.html.twig', [
'news' => array(), 'news' => array(),
]); ]);
} }
/**
* @Route("/toto/{id}/{name}", name="toto")
*/
// public function index(TranslatorInterface $translator)
public function toto($id, $name)
{
// Exemple pour la traduction :
// $translated = $translator->trans('Symfony is great');
// $translator->transChoice(
// 'Hurry up %name%! There is one apple left.|There are %count% apples left.',
// 10,
// // no need to include %count% here; Symfony does that for you
// array('%name%' => $user->getName())
// );
return $this->render('index.html.twig', [
'toto' => 'toto',
'id' => $id
]);
}
} }
...@@ -212,9 +212,10 @@ class User extends BaseUser ...@@ -212,9 +212,10 @@ class User extends BaseUser
*/ */
public function removeCotisation(Cotisation $cotisation) public function removeCotisation(Cotisation $cotisation)
{ {
if ($this->cotisations->contains($cotisation)) { throw new \LogicException('User::removeCotisation : This code should not be reached!');
$this->cotisations->removeElement($cotisation); // if ($this->cotisations->contains($cotisation)) {
} // $this->cotisations->removeElement($cotisation);
// }
return $this; return $this;
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment