Commit 5b393d66 by Damien Moulard

allow switching between roles if different roles are all presta/caissier/...

parent eb287f25
......@@ -18,6 +18,7 @@ fos_ck_editor:
NumberedList, BulletedList, -, Outdent, Indent, -,
Blockquote, -, Image, Link, Unlink, Table]
- [Format, Maximize, Source]
removePlugins: 'scayt,wsc,tableselection'
enterMode: CKEDITOR.ENTER_BR
filebrowserBrowseRoute: admin_sonata_media_media_ckeditor_browser
......
......@@ -48,6 +48,8 @@ use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface;
use Symfony\Component\Security\Guard\GuardAuthenticatorHandler;
use Symfony\Component\Security\Guard\Token\PostAuthenticationGuardToken;
use Symfony\Component\Security\Core\Authentication\Token\SwitchUserToken;
use Symfony\Component\Security\Core\Role\SwitchUserRole;
class IndexController extends AbstractController
{
......@@ -719,8 +721,8 @@ class IndexController extends AbstractController
return $this->redirectToRoute('index');
}
/**
* Choix du presta géré.
/**
* Choix du caissier géré.
*
* @Route("/login/caissier/choice/{usergrpid}/{caissierid}", name="caissier_choice")
* @ParamConverter("group", class="App:Usergroup", options={"mapping": {"usergrpid": "id"}})
......@@ -794,18 +796,44 @@ class IndexController extends AbstractController
$this->em->persist($this->getUser());
$this->em->flush();
}
$token = new PostAuthenticationGuardToken(
$this->getUser(),
'main',
$this->getUser()->getRoles()
);
$this->tokenStorage->setToken($token);
$currentToken = $this->tokenStorage->getToken();
$switchUserRole = null;
if ($currentToken instanceof SwitchUserToken) {
foreach ($currentToken->getRoles() as $role) {
if ($role instanceof SwitchUserRole) {
$switchUserRole = $role;
break;
}
}
}
$this->guard->authenticateUserAndHandleSuccess(
$this->getUser(),
$request,
$this->authenticator,
'main'
);
// Si le super admin était en impersonation, on réapplique le SwitchUserToken par-dessus
// celui que le guard vient de créer, pour ne pas perdre ROLE_PREVIOUS_ADMIN.
if (null !== $switchUserRole) {
$freshToken = $this->tokenStorage->getToken();
$roles = $freshToken->getRoles();
$roles[] = $switchUserRole;
$token = new SwitchUserToken(
$this->getUser(),
$this->getUser()->getPassword(),
'main',
$roles,
$switchUserRole->getSource()
);
$this->tokenStorage->setToken($token);
} else {
$token = $this->tokenStorage->getToken();
}
$this->session->set('_security_main', serialize($token));
}
}
......@@ -92,9 +92,23 @@
{% if app.user %}
<a href="{{path('myaccount')}}" class="dropdown-item">{{ 'Mon compte'|trans }}</a>
{% endif %}
{% if app.user.possiblegroups|length > 1 %}
{% if
app.user.possiblegroups|length > 1
or
app.user.prestataires
and app.user.prestataires|length > 1
or
app.user.caissiers
and app.user.caissiers|length > 1
or
app.user.comptoirsgeres
and app.user.comptoirsgeres|length > 1
or
app.user.groupesgeres
and app.user.groupesgeres|length > 1
%}
<a href="#" class="viewChoiceGroup dropdown-item">{{ 'Choix du rôle'|trans }}</a>
{% endif %}
{% endif %}
{% if is_granted('ROLE_PREVIOUS_ADMIN') %}
<a href="{{path('index')}}?_switch_user=_exit" class="dropdown-item">{{ 'RETOUR SUPER ADMIN'|trans }}</a>
{% endif %}
......
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