Ver Fonte

FD3-568 se agrega chequeo si esta usuario suplantado

Guillermo Espinoza há 7 anos atrás
pai
commit
a51f10ed2d

+ 7 - 0
Resources/config/services.yml

@@ -11,3 +11,10 @@ services:
 
     base_oauthclient_security_oauthproxyprovider:
         class: Base\OAuthClientBundle\Security\OAuthProxyUserProvider
+
+            
+    base_oauthclient.twig_is_granted_previous_admin_extension:
+       class: Base\OAuthClientBundle\Twig\IsGrantedPreviousAdminExtension
+       arguments: ["@webservice", "%env(HOST_BASE)%"]
+       tags:
+           - { name: twig.extension }

+ 1 - 0
Resources/translations/BaseOAuthClientBundle.es.yml

@@ -1,2 +1,3 @@
 link:
     user_logout: Cerrar Sesión
+    user_exit_impersonate: Salir suplantar

+ 3 - 0
Resources/views/Core/oauth_user_block.html.twig

@@ -1,5 +1,8 @@
 {% extends "SonataAdminBundle:Core:user_block.html.twig" %}
 
 {% block user_block %}
+    {% if is_granted_previous_admin() %}
+    <li><a href="{{ switch_user_exit() }}">{{ 'link.user_exit_impersonate'|trans({}, 'BaseOAuthClientBundle') }}</a></li>
+    {% endif %}
     <li><a href="{{ path('logout') }}">{{ 'link.user_logout'|trans({}, 'BaseOAuthClientBundle') }}</a></li>
 {% endblock %}

+ 66 - 0
Twig/IsGrantedPreviousAdminExtension.php

@@ -0,0 +1,66 @@
+<?php
+
+namespace Base\OAuthClientBundle\Twig;
+
+use WebserviceBundle\Services\Webservice;
+
+class IsGrantedPreviousAdminExtension extends \Twig_Extension
+{
+
+    /**
+     * @var Webservice
+     */
+    protected $webservice;
+
+    /**
+     * @var string
+     */
+    protected $urlBase;
+
+
+    /**
+     * @param Webservice $webservice
+     * @param string $urlBase
+     */
+    public function __construct(Webservice $webservice, $urlBase)
+    {
+        $this->webservice = $webservice;
+        $this->urlBase = $urlBase;
+    }
+
+    /**
+     * @return array
+     */
+    public function getFunctions()
+    {
+        return array(
+            new \Twig_SimpleFunction('is_granted_previous_admin', array($this, 'isGrantedPreviousAdmin')),
+            new \Twig_SimpleFunction('switch_user_exit', array($this, 'switchUserExit')),
+        );
+    }
+
+    /**
+     * @return boolean
+     */
+    public function isGrantedPreviousAdmin()
+    {
+        return $this->webservice->makeGetRequest($this->urlBase . '/admin/user/is_granted');
+    }
+
+    /**
+     * @return boolean
+     */
+    public function switchUserExit()
+    {
+        return 'https://' . $this->urlBase . '/?_switch_user=_exit';
+    }
+
+    /**
+     * @return string
+     */
+    public function getName()
+    {
+        return 'is_granted_previous_admin_extension';
+    }
+
+}