Fix error pages

pull/3064/head
Julio 6 years ago
parent f1641819ee
commit 5ba7f3cb3b
  1. 2
      .env.test
  2. 10
      composer.json
  3. 2
      config/packages/framework.yaml
  4. 10
      config/packages/sonata_page.yaml
  5. 4
      config/packages/twig.yaml
  6. 2
      config/routes/dev/twig.yaml
  7. 20
      config/services.yaml
  8. 2
      phpunit.xml.dist
  9. 5
      public/main/calendar/agenda_js.php
  10. 20
      public/main/inc/lib/api.lib.php
  11. 83
      src/CoreBundle/Controller/ExceptionController.php
  12. 2
      src/CoreBundle/Entity/Manager/SessionManager.php
  13. 2
      src/CoreBundle/Entity/Manager/SettingsCurrentManager.php
  14. 7
      src/CoreBundle/Menu/NavBuilder.php
  15. 3
      src/CoreBundle/Resources/config/services.yml
  16. 54
      src/ThemeBundle/Controller/ExceptionController.php
  17. 1
      src/ThemeBundle/Resources/views/Exception/exception_full.html.twig
  18. 3
      src/ThemeBundle/Resources/views/Layout/sidebar.html.twig

@ -1,4 +1,4 @@
# define your env variables for the test env here
KERNEL_CLASS='App\Kernel'
KERNEL_CLASS='Chamilo\Kernel'
APP_SECRET='s$cretf0rt3st'
SYMFONY_DEPRECATIONS_HELPER=999999

@ -63,14 +63,14 @@
"sensiolabs/security-checker": "~6.0",
"symfony/asset": "^4.0",
"symfony/dotenv": "^4.0",
"symfony/dotenv": "^5.0",
"symfony/expression-language": "^4.0",
"symfony/flex": "^1.0",
"symfony/flex": "^1.6",
"symfony/form": "^4.0",
"symfony/framework-bundle": "^4.0",
"symfony/http-kernel": "^4.0",
"symfony/monolog-bundle": "^3.1",
"symfony/mailer": "^4.0",
"symfony/mailer": "^5.0",
"symfony/polyfill-apcu": "^1.9",
"symfony/requirements-checker": "^1.1",
"symfony/security-bundle": "^4.0",
@ -78,7 +78,7 @@
"symfony/translation": "^4.0",
"symfony/twig-bundle": "^4.0",
"symfony/validator": "^4.0",
"symfony/webpack-encore-bundle": "^1.1",
"symfony/webpack-encore-bundle": "^1.7",
"symfony/yaml": "^4.0",
"tgalopin/html-sanitizer-bundle": "^1.1",
@ -212,7 +212,7 @@
"extra": {
"symfony": {
"allow-contrib": true,
"require": "4.4.*"
"require": "5.0.*"
}
}
}

@ -14,4 +14,4 @@ framework:
name: chamilo2
fragments: ~
http_method_override: true
annotations: true
annotations: true

@ -21,17 +21,9 @@ sonata_page:
- ^/connect/(.*)
- ^/editor/(.*)
- ^/login/(.*)
- ^/main(.*)
- ^/plugin(.*)
- ^/error
- ^/packages/(.*)
- ^/package/(.*)
- ^install
- ^/install/(.*)
- install.php
- install.php/(.*)
- install.php/packages/(.*)
- install.php/package/(.*)
- install.php/(.*)/(.*)
- ^/bundles/(.*)
- ^/_wdt/(.*)
- ^/_profiler/(.*)

@ -9,7 +9,9 @@ twig:
- '@SonataFormatter/Form/formatter.html.twig'
- '@SonataCore/Form/datepicker.html.twig'
- '@SonataCore/Form/color.html.twig'
exception_controller: 'Chamilo\ThemeBundle\Controller\ExceptionController::showAction'
exception_controller: Chamilo\CoreBundle\Controller\ExceptionController::showAction
globals:
show_toolbar: true
show_footer: true

@ -1,3 +1,3 @@
_errors:
resource: '@TwigBundle/Resources/config/routing/errors.xml'
resource: '@FrameworkBundle/Resources/config/routing/errors.xml'
prefix: /_error

@ -1,6 +1,7 @@
# Put parameters here that don't need to change on each machine where the app is deployed
# https://symfony.com/doc/current/best_practices/configuration.html#application-related-configuration
parameters:
app_env: '%env(APP_ENV)%'
password_encryption: '%env(APP_ENCRYPT_METHOD)%'
secret: '%env(APP_SECRET)%'
locale: '%env(APP_LOCALE)%'
@ -19,7 +20,6 @@ parameters:
glide_config:
source: 'oneup_flysystem.resources_filesystem'
cache: 'oneup_flysystem.cache_resources_filesystem'
#cache: 'var/cache/resource/'
glide_media_filters:
editor_thumbnail:
@ -87,11 +87,6 @@ services:
exclude: '../src/ThemeBundle/{Entity,Migrations,Tests}'
public: true
Chamilo\ThemeBundle\Controller\ExceptionController:
public: true
arguments:
$debug: '%kernel.debug%'
Doctrine\ORM\EntityManager: "@doctrine.orm.default_entity_manager"
chamilo_core.hook_factory:
@ -170,17 +165,10 @@ gregwar_captcha:
height: 50
length: 6
cocur_slugify:
lowercase: true
imports:
- {resource: ../src/CoreBundle/Resources/config/services.yml}
- {resource: ../src/PageBundle/Resources/config/services.yml}
- {resource: ../vendor/knplabs/doctrine-behaviors/config/orm-services.yml}
#sylius_resource:
# resources:
# app.exercise_category:
# driver: 'doctrine/orm'
# classes:
# model: 'Chamilo\CourseBundle\Entity\CExerciseCategory'
cocur_slugify:
lowercase: true

@ -9,11 +9,11 @@
>
<php>
<ini name="error_reporting" value="-1" />
<ini name="display_errors" value="true"/>
<server name="APP_ENV" value="test" force="true" />
<server name="SHELL_VERBOSITY" value="-1" />
<server name="SYMFONY_PHPUNIT_REMOVE" value="" />
<server name="SYMFONY_PHPUNIT_VERSION" value="7.5" />
<server name="KERNEL_CLASS" value="Chamilo\Kernel" />
</php>
<testsuites>

@ -1,9 +1,6 @@
<?php
/* For licensing terms, see /license.txt */
/**
* @package chamilo.calendar
*/
/* For licensing terms, see /license.txt */
// use anonymous mode when accessing this course tool
$use_anonymous = true;

@ -7,15 +7,12 @@ use Chamilo\CoreBundle\Entity\Session as SessionEntity;
use Chamilo\CoreBundle\Entity\SettingsCurrent;
use Chamilo\CoreBundle\Framework\Container;
use Chamilo\CourseBundle\Entity\CGroupInfo;
use Chamilo\CourseBundle\Entity\CItemProperty;
use Chamilo\ThemeBundle\Controller\ExceptionController;
use Chamilo\UserBundle\Entity\User;
use ChamiloSession as Session;
use Symfony\Bridge\Twig\Mime\TemplatedEmail;
use Symfony\Component\Debug\Exception\FlattenException;
use Symfony\Component\Finder\Finder;
use Symfony\Component\Mime\Address;
use Symfony\Component\Mime\Email;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
/**
@ -3658,23 +3655,10 @@ function api_not_allowed(
$message = null,
$responseCode = 0
) {
$debug = api_get_setting('server_type') === 'test';
// Default code is 403 forbidden
$responseCode = empty($responseCode) ? 403 : $responseCode;
$message = empty($message) ? get_lang('You are not allowed') : $message;
Session::write('error_message', $message);
// Create new exception rendered by template:
// src/ThemeBundle/Resources/views/Exception/error.html.twig
// if error is 404 then the template is:
// src/ThemeBundle/Resources/views/Exception/error404.html.twig
$exception = new Exception($message);
$request = Container::getRequest();
$exception = FlattenException::create($exception, $responseCode);
$controller = new ExceptionController(Container::getTwig(), $debug);
$response = $controller->showAction($request, $exception);
$response->send();
header('Location: '.api_get_path(WEB_PUBLIC_PATH).'error');
exit;
}

@ -0,0 +1,83 @@
<?php
/* For licensing terms, see /license.txt */
namespace Chamilo\CoreBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\ErrorHandler\Exception\FlattenException;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Exception\HttpException;
use Symfony\Component\Routing\Annotation\Route;
class ExceptionController extends AbstractController
{
public function showAction(FlattenException $exception)
{
if ('dev' === $this->getParameter('app_env')) {
throw new HttpException($exception->getCode(), $exception->getMessage());
}
$showException = true;
$name = $showException ? 'exception' : 'error';
$code = $exception->getCode();
$format = 'html';
$loader = $this->container->get('twig')->getLoader();
// when not in debug, try to find a template for the specific HTTP status code and format
if (!$showException) {
$template = sprintf('@ChamiloTheme/Exception/%s%s.%s.twig', $name, $code, $format);
if ($loader->exists($template)) {
return $template;
}
}
// try to find a template for the given format
$template = sprintf('@ChamiloTheme/Exception/%s.%s.twig', $name, $format);
if ($loader->exists($template)) {
return $template;
}
// default to a generic HTML exception
//$request->setRequestFormat('html');
$template = sprintf('@ChamiloTheme/Exception/%s.html.twig', $showException ? 'exception_full' : $name);
return $this->render($template, ['exception' => $exception]);
}
/**
* @Route("/error")
*/
public function errorAction(Request $request)
{
$message = $request->getSession()->get('error_message', '');
$exception = new FlattenException();
$exception->setCode(500);
$exception->setMessage($message);
$showException = true;
$name = $showException ? 'exception' : 'error';
$code = $exception->getCode();
$format = 'html';
$loader = $this->container->get('twig')->getLoader();
// when not in debug, try to find a template for the specific HTTP status code and format
if (!$showException) {
$template = sprintf('@ChamiloTheme/Exception/%s%s.%s.twig', $name, $code, $format);
if ($loader->exists($template)) {
return $template;
}
}
// try to find a template for the given format
$template = sprintf('@ChamiloTheme/Exception/%s.%s.twig', $name, $format);
if ($loader->exists($template)) {
return $template;
}
// default to a generic HTML exception
//$request->setRequestFormat('html');
$template = sprintf('@ChamiloTheme/Exception/%s.html.twig', $showException ? 'exception_full' : $name);
return $this->render($template, ['exception' => $exception]);
}
}

@ -8,7 +8,7 @@ use Chamilo\CoreBundle\Entity\Course;
use Chamilo\CoreBundle\Entity\Session;
use Chamilo\CoreBundle\Entity\SessionRelUser;
use Chamilo\UserBundle\Entity\User;
use Sonata\CoreBundle\Model\BaseEntityManager;
use Sonata\Doctrine\Entity\BaseEntityManager;
/**
* Class SessionManager.

@ -4,7 +4,7 @@
namespace Chamilo\CoreBundle\Entity\Manager;
use Sonata\CoreBundle\Model\BaseEntityManager;
use Sonata\Doctrine\Entity\BaseEntityManager;
/**
* Class SettingsCurrentRepository.

@ -11,6 +11,7 @@ use Knp\Menu\FactoryInterface;
use Knp\Menu\ItemInterface;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerAwareTrait;
use Symfony\Component\Security\Core\Authorization\AuthorizationChecker;
/**
* Class NavBuilder.
@ -20,10 +21,12 @@ class NavBuilder implements ContainerAwareInterface
use ContainerAwareTrait;
private $factory;
private $checker;
public function __construct(FactoryInterface $factory)
public function __construct(FactoryInterface $factory, AuthorizationChecker $checker)
{
$this->factory = $factory;
$this->checker = $checker;
}
/**
@ -60,7 +63,7 @@ class NavBuilder implements ContainerAwareInterface
public function menuApp(array $options): ItemInterface
{
$container = $this->container;
$checker = $container->get('security.authorization_checker');
$checker = $this->checker;
$translator = $container->get('translator');
$router = $container->get('router');
$factory = $this->factory;

@ -217,6 +217,9 @@ services:
chamilo_core.menu.nav_builder:
class: Chamilo\CoreBundle\Menu\NavBuilder
arguments:
- '@knp_menu.factory'
- '@security.authorization_checker'
calls:
- [setContainer, ['@service_container']]
tags:

@ -1,54 +0,0 @@
<?php
/* For licensing terms, see /license.txt */
namespace Chamilo\ThemeBundle\Controller;
use Symfony\Bundle\TwigBundle\Controller\ExceptionController as BaseExceptionController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Templating\TemplateReference;
/**
* Class ExceptionController.
*/
class ExceptionController extends BaseExceptionController
{
/**
* @param string $format
* @param int $code
* @param bool $showException
*
* @return TemplateReference
*/
protected function findTemplate(Request $request, $format, $code, $showException)
{
// Only show custom error when APP_DEBUG = 0
if ($showException) {
return parent::findTemplate($request, $format, $code, $showException);
}
$name = $showException ? 'exception' : 'error';
if ($showException && 'html' == $format) {
$name = 'exception_full';
}
// when not in debug, try to find a template for the specific HTTP status code and format
if (!$showException) {
$template = sprintf('@ChamiloTheme/Exception/%s%s.%s.twig', $name, $code, $format);
if ($this->templateExists($template)) {
return $template;
}
}
// try to find a template for the given format
$template = sprintf('@ChamiloTheme/Exception/%s.%s.twig', $name, $format);
if ($this->templateExists($template)) {
return $template;
}
// default to a generic HTML exception
$request->setRequestFormat('html');
return sprintf('@ChamiloTheme/Exception/%s.html.twig', $showException ? 'exception_full' : $name);
}
}

@ -1,4 +1,5 @@
{% extends '@ChamiloTheme/Layout/base-layout.html.twig' %}
{% block page_title %} Error {% endblock %}
{% block page_subtitle %} {{ status_code }} {% endblock %}
{% block page_content %}

@ -4,8 +4,7 @@
<nav class="sidebar-nav">
{% set menu = knp_menu_get('menuApp') %}
{{ knp_menu_render(menu, {'ancestorClass': 'current_open open', 'template': '@ChamiloTheme/Menu/left_menu.html.twig'}) }}
</nav>
{#<button class="sidebar-minimizer brand-minimizer" type="button"></button>#}
</nav>
</div>
{% endif %}
{% endautoescape %}
Loading…
Cancel
Save