Pārlūkot izejas kodu

Support Impersonating an user

Thomas Rabaix 13 gadi atpakaļ
vecāks
revīzija
142334c137

+ 6 - 0
Admin/Entity/UserAdmin.php

@@ -34,6 +34,12 @@ class UserAdmin extends Admin
             ->add('locked')
             ->add('createdAt')
         ;
+
+        if ($this->isGranted('ROLE_ALLOWED_TO_SWITCH')) {
+            $listMapper
+                ->add('impersonating', 'string', array('template' => 'SonataUserBundle:Admin:Field/impersonating.html.twig'))
+            ;
+        }
     }
 
     protected function configureDatagridFilters(DatagridMapper $filterMapper)

+ 8 - 1
Resources/translations/SonataUserBundle.en.xliff

@@ -26,7 +26,6 @@
                 <source>breadcrumb.link_group_edit</source>
                 <target>Edit</target>
             </trans-unit>
-
             <trans-unit id="users">
                 <source>users</source>
                 <target>Users</target>
@@ -35,6 +34,14 @@
                 <source>groups</source>
                 <target>Groups</target>
             </trans-unit>
+            <trans-unit id="switch_user_exit">
+                <source>switch_user_exit</source>
+                <target>Exit impersonating mode</target>
+            </trans-unit>
+            <trans-unit id="switch_user">
+                <source>switch_user</source>
+                <target>Impersonate User</target>
+            </trans-unit>
         </body>
     </file>
 </xliff>

+ 16 - 0
Resources/views/Admin/Field/impersonating.html.twig

@@ -0,0 +1,16 @@
+{#
+
+This file is part of the Sonata package.
+
+(c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
+
+For the full copyright and license information, please view the LICENSE
+file that was distributed with this source code.
+
+#}
+
+{% extends 'SonataAdminBundle:CRUD:base_list_field.html.twig' %}
+
+{% block field %}
+    <a href="{{ url('homepage', {'_switch_user': object.username}) }}">{{ "switch_user"|trans({}, 'SonataUserBundle')}}</a>
+{% endblock %}