This repository was archived by the owner on Oct 15, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 4 files changed +20
-4
lines changed
Expand file tree Collapse file tree 4 files changed +20
-4
lines changed Original file line number Diff line number Diff line change @@ -27,12 +27,12 @@ security:
2727 secret : " %kernel.secret%" # required
2828 lifetime : 604800 # 1 week in seconds
2929
30+ # https://symfony.com/doc/current/security/impersonating_user.html
31+ switch_user : true
32+
3033 # activate different ways to authenticate
3134 # https://symfony.com/doc/current/security.html#the-firewall
3235
33- # https://symfony.com/doc/current/security/impersonating_user.html
34- # switch_user: true
35-
3636 # Easy way to control access for large sections of your site
3737 # Note: Only the *first* access control that matches will be used
3838 access_control :
Original file line number Diff line number Diff line change 55namespace App \Controller \Admin ;
66
77use App \Entity \User ;
8+ use EasyCorp \Bundle \EasyAdminBundle \Config \Action ;
9+ use EasyCorp \Bundle \EasyAdminBundle \Config \Actions ;
10+ use EasyCorp \Bundle \EasyAdminBundle \Config \Crud ;
811use EasyCorp \Bundle \EasyAdminBundle \Controller \AbstractCrudController ;
912use EasyCorp \Bundle \EasyAdminBundle \Field \ArrayField ;
1013use EasyCorp \Bundle \EasyAdminBundle \Field \AssociationField ;
@@ -54,4 +57,13 @@ public function configureFields(string $pageName): iterable
5457 DateTimeField::new ('updated_at ' , 'Updated at ' )->hideOnForm (),
5558 ];
5659 }
60+
61+ public function configureActions (Actions $ actions ): Actions
62+ {
63+ return $ actions ->add (
64+ Crud::PAGE_INDEX ,
65+ Action::new ('impersonate ' , 'Impersonate ' )
66+ ->linkToUrl (fn (User $ user ) => "/?_switch_user= {$ user ->getUserIdentifier ()}" )
67+ );
68+ }
5769}
Original file line number Diff line number Diff line change 5757 {{ app .user .name }}
5858 </button >
5959 <ul class =" dropdown-menu dropdown-menu-end p-2 rounded-3" >
60- {% if ' ROLE_ADMIN' in app . user . roles %}
60+ {% if is_granted( ' ROLE_ADMIN' ) %}
6161 <li ><a class =" dropdown-item rounded-2 mb-2" href =" {{ path(' admin' ) }}" >管理後台</a ></li >
6262 {% endif %}
63+ {% if is_granted(' IS_IMPERSONATOR' ) %}
64+ <li ><a class =" dropdown-item rounded-2 mb-2" href =" {{ impersonation_exit_path(path(' app_home' )) }}" >結束模擬</a ></li >
65+ {% endif %}
6366 <li ><a class =" dropdown-item rounded-2 mb-2" href =" {{ path(' app_profile' ) }}" >個人資料</a ></li >
6467 <li ><a class =" dropdown-item rounded-2" href =" {{ path(' app_logout' ) }}" >登出</a ></li >
6568 </ul >
Original file line number Diff line number Diff line change @@ -54,6 +54,7 @@ Mark Resolved: 標記為已解決
5454Mark Closed : 標記為已關閉
5555New & In Progress : 新問題 & 處理中
5656Resolved & Closed : 已解決 & 已關閉
57+ Impersonate : 模擬使用者
5758
5859challenge.error-type.user : 輸入錯誤
5960challenge.error-type.server : 伺服器錯誤
You can’t perform that action at this time.
0 commit comments