Commit 20f4c1e3 by Damien Moulard

user admin: prevent deleting user if its adherent account has flux

parent aca3a2c6
......@@ -9,9 +9,20 @@ use Symfony\Component\Form\FormView;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
use App\Utils\CustomEntityManager;
use App\Entity\User;
use App\Entity\Flux;
class CRUDController extends Controller
{
protected $em;
public function __construct(CustomEntityManager $em)
{
$this->em = $em;
}
/**
* Create action.
*
......@@ -220,6 +231,19 @@ class CRUDController extends Controller
return $this->redirectTo($object);
}
// Prevent deleting user if flux related to its Adherent account exist
if ($object instanceof User && $object->getAdherent()) {
$query = $this->em->getRepository(Flux::class)->getQueryByAdherent($object->getAdherent());
if (null != $query && count($query->getResult()) > 0) {
$this->addFlash(
'sonata_flash_error',
'Vous ne pouvez pas supprimer ce compte utilisateur car des flux en relation à son compte Adhérent existent.'
);
return $this->redirectTo($object);
}
}
return parent::deleteAction($id);
}
......
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