<?php
namespace ExamPlugin\Listener;
use AppBundle\Common\Exception\AccessDeniedException;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpKernel\Event\ControllerEvent;
use Symfony\Component\HttpKernel\HttpKernelInterface;
use Topxia\Service\Common\ServiceKernel;
class ExamManageAccessListener
{
/**
* @var ContainerInterface
*/
private $container;
public function __construct(ContainerInterface $container)
{
$this->container = $container;
}
public function onKernelController(ControllerEvent $event)
{
if (HttpKernelInterface::MAIN_REQUEST != $event->getRequestType()) {
return;
}
$request = $event->getRequest();
$currentUser = ServiceKernel::instance()->getCurrentUser();
$requestPath = $request->getPathInfo();
if (((0 === stripos($requestPath, '/exam/manage') && !$currentUser->hasPermission('admin_train_exam_manage_list')) || (0 === stripos($requestPath, '/exam/test_paper') && !$currentUser->hasPermission('admin_train_test_paper_manage_list'))) && !in_array('ROLE_TRAINING_ADMIN', $currentUser['roles']) && !$currentUser->isSuperAdmin()) {
throw new AccessDeniedException('您没有访问权限,访问被拒绝,如有疑问请联系管理员!');
}
return;
}
}