2017-02-08 5 views
0

私のKernelRequestに問題があります。まず、ユーザーはプロファイルに関連付けられた権限のリストを持っています。バックオフィスでは、管理者は多くのプロファイルを作成したり、アクセスできる機能を作成したりできます。KernelRequestのリダイレクト時のSymfonyエラーajax

たとえば、ユーザーが/ profil/meに行くとします。私のKernelRequestはpath/profilにアクセスできるかどうかをチェックします。そうでない場合は、ユーザーを自宅にリダイレクトします。

残念ながら、これはAJAX呼び出しでは動作しません...私はfullcalendarを使用して、私のコンソールで、私はこのメッセージを持っている:

Uncaught SyntaxError: Unexpected token < router.js:9 
Uncaught Error: The route "fullcalendar_loader" does not exist. 

リダイレクトは正常に動作しますが、私はいつもこのメッセージを持って、なぜ?

public function onKernelRequest(GetResponseEvent $event) 
{ 
    $session = new Session(); 
    $routeToRedirect = 'home_index'; 
    $user = $session->get('JUNGO2_UTILISATEUR'); 
    $profil = $user->getProfil()->getId(); 
    $routeInterceptName = $event->getRequest()->get('_route'); 
    $routeInterceptPath = $this->router->getRouteCollection()->get($routeInterceptName); 

    if (HttpKernel::MASTER_REQUEST != $event->getRequestType() || $routeInterceptName == "app_security_login" || $routeInterceptName == "home_index"){ 
     return; 
    } 
    // if user are not in home 
    if ($routeToRedirect != $routeInterceptName) { 
     // For a profile, we list all privileges 
     $profil = $this->em->getRepository('AppBundle:Profil')->findOneById($profil); 
     $privileges = $this->em->getRepository('AppBundle:Privilege')->getPrivilegeByProfilNotNull($profil); 
     $routeInterceptPath = $routeInterceptPath->getPath(); 
     //We retrieve the first word after the '/'' 
     // Example: if the route is /user/profil, we just retrieve /user 
     $t = explode("/", $routeInterceptPath); 
     $routeInterceptPath = "/".$t[1]; 


     // We look at whether the url corresponds to one of these privileges 
     foreach ($privileges as $privilege) { 
      $route = $privilege->getRoute(); 
      $route = $this->router->getRouteCollection()->get($route)->getPath(); 
      if($routeInterceptPath == $route){ 
       return; 
      } 
     } 

     // ERROR WITH AJAX 
     $response = new RedirectResponse($this->router->generate($routeToRedirect)); 
     $event->setResponse($response); 
    } 
} 

リダイレクトの最後の2行を削除しても、エラーメッセージは表示されません。しかしもちろん、リダイレクトはもうありません。

あなたは何が間違っているか考えていますか?

おかげ

答えて

0

なぜaccess controlsを使わないのでしょうか?その後、ロールでこれを処理できます。

0

security.ymlアクセスコントロールの使い方がわかりません。管理者はバックオフィスで直接ロールを作成し、アクセスできるルートをこれらのロールに関連付けることができます。

私は3つのエンティティ(そしてもちろん、テーブル連想)があります。名前だけで

役割/プロファイルまたは/管理ブール

権限のようなルートで

権限を

これは最適な解決策ではないかもしれませんが、私は他に何も見つかりませんでした。 私は既に別のプロジェクトでアクセスコントロールを使用していますが、静的ロールは3/4しかありません。

関連する問題