mirror of
https://github.com/Combodo/iTop.git
synced 2026-05-19 15:22:17 +02:00
N°2060 - Fix session messages and SCSS compilation services being cached
This commit is contained in:
@@ -48,6 +48,9 @@ $oListsCompat = new Lists($oModuleDesign);
|
|||||||
$oListsCompat->Process($container);
|
$oListsCompat->Process($container);
|
||||||
|
|
||||||
// Generating CSS files
|
// Generating CSS files
|
||||||
|
// Note: We do this here as it is not user dependent and therefore can be cached for everyone.
|
||||||
|
// A dedicated listener 'CssFromSassCompiler' exists to compile files again when by-passing HTTP cache.
|
||||||
|
// This is to keep developers comfort when tuning the SCSS files.
|
||||||
$aImportPaths = array($_ENV['COMBODO_PORTAL_BASE_ABSOLUTE_PATH'].'css/');
|
$aImportPaths = array($_ENV['COMBODO_PORTAL_BASE_ABSOLUTE_PATH'].'css/');
|
||||||
$aPortalConf = $container->getParameter('combodo.portal.instance.conf');
|
$aPortalConf = $container->getParameter('combodo.portal.instance.conf');
|
||||||
foreach ($aPortalConf['properties']['themes'] as $sKey => $value)
|
foreach ($aPortalConf['properties']['themes'] as $sKey => $value)
|
||||||
@@ -69,42 +72,3 @@ foreach ($aPortalConf['properties']['themes'] as $sKey => $value)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
$container->setParameter('combodo.portal.instance.conf', $aPortalConf);
|
$container->setParameter('combodo.portal.instance.conf', $aPortalConf);
|
||||||
|
|
||||||
//TODO: The following needs to be refactored
|
|
||||||
// Session messages
|
|
||||||
// Note: We keep this system instead of following the Symfony system to make it simpler for extension developers to use them accross the admin. console and the portal.
|
|
||||||
$aAllMessages = array();
|
|
||||||
if ((array_key_exists('obj_messages', $_SESSION)) && (!empty($_SESSION['obj_messages'])))
|
|
||||||
{
|
|
||||||
foreach ($_SESSION['obj_messages'] as $sMessageKey => $aMessageObjectData)
|
|
||||||
{
|
|
||||||
$aObjectMessages = array();
|
|
||||||
$aRanks = array();
|
|
||||||
foreach ($aMessageObjectData as $sMessageId => $aMessageData)
|
|
||||||
{
|
|
||||||
$sMsgClass = 'alert alert-dismissible alert-';
|
|
||||||
switch ($aMessageData['severity'])
|
|
||||||
{
|
|
||||||
case 'info':
|
|
||||||
$sMsgClass .= 'info';
|
|
||||||
break;
|
|
||||||
case 'error':
|
|
||||||
$sMsgClass .= 'danger';
|
|
||||||
break;
|
|
||||||
case 'ok':
|
|
||||||
default:
|
|
||||||
$sMsgClass .= 'success';
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
$aObjectMessages[] = array('css_classes' => $sMsgClass, 'message' => $aMessageData['message']);
|
|
||||||
$aRanks[] = $aMessageData['rank'];
|
|
||||||
}
|
|
||||||
//unset($_SESSION['obj_messages'][$sMessageKey]);
|
|
||||||
array_multisort($aRanks, $aObjectMessages);
|
|
||||||
foreach ($aObjectMessages as $aObjectMessage)
|
|
||||||
{
|
|
||||||
$aAllMessages[] = $aObjectMessage;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$container->setParameter('combodo.current_user.session_messages', $aAllMessages);
|
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
# Copyright (C) 2010-2020 Combodo SARL
|
||||||
|
#
|
||||||
|
# This file is part of iTop.
|
||||||
|
#
|
||||||
|
# iTop is free software; you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU Affero General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# iTop is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU Affero General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU Affero General Public License
|
||||||
|
# along with iTop. If not, see <http://www.gnu.org/licenses/>
|
||||||
|
|
||||||
|
p_session_message_add:
|
||||||
|
path: '/session-message/add'
|
||||||
|
defaults:
|
||||||
|
_controller: 'Combodo\iTop\Portal\Controller\SessionMessageController::AddMessageAction'
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
# Copyright (C) 2010-2018 Combodo SARL
|
# Copyright (C) 2010-2020 Combodo SARL
|
||||||
#
|
#
|
||||||
# This file is part of iTop.
|
# This file is part of iTop.
|
||||||
#
|
#
|
||||||
@@ -74,6 +74,8 @@ services:
|
|||||||
tags: [{ name: 'kernel.event_listener', event: 'kernel.request', priority: 400 }]
|
tags: [{ name: 'kernel.event_listener', event: 'kernel.request', priority: 400 }]
|
||||||
Combodo\iTop\Portal\EventListener\ApplicationContextSetPluginPropertyClass:
|
Combodo\iTop\Portal\EventListener\ApplicationContextSetPluginPropertyClass:
|
||||||
tags: [{ name: 'kernel.event_listener', event: 'kernel.request', priority: 300 }]
|
tags: [{ name: 'kernel.event_listener', event: 'kernel.request', priority: 300 }]
|
||||||
|
Combodo\iTop\Portal\EventListener\CssFromSassCompiler:
|
||||||
|
tags: [{ name: 'kernel.event_listener', event: 'kernel.request', priority: 200 }]
|
||||||
|
|
||||||
# Add more service definitions when explicit configuration is needed
|
# Add more service definitions when explicit configuration is needed
|
||||||
# Please note that last definitions always *replace* previous ones
|
# Please note that last definitions always *replace* previous ones
|
||||||
@@ -142,3 +144,6 @@ services:
|
|||||||
brick_controller_helper:
|
brick_controller_helper:
|
||||||
alias: Combodo\iTop\Portal\Helper\BrickControllerHelper
|
alias: Combodo\iTop\Portal\Helper\BrickControllerHelper
|
||||||
public: true
|
public: true
|
||||||
|
session_message_helper:
|
||||||
|
alias: Combodo\iTop\Portal\Helper\SessionMessageHelper
|
||||||
|
public: true
|
||||||
@@ -0,0 +1,67 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Copyright (C) 2013-2020 Combodo SARL
|
||||||
|
*
|
||||||
|
* This file is part of iTop.
|
||||||
|
*
|
||||||
|
* iTop is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* iTop is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Combodo\iTop\Portal\Controller;
|
||||||
|
|
||||||
|
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||||
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
|
use Symfony\Component\HttpKernel\Exception\HttpException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class SessionMessageController
|
||||||
|
*
|
||||||
|
* @author Guillaume Lajarige <guillaume.lajarige@combodo.com>
|
||||||
|
* @package Combodo\iTop\Portal\Controller
|
||||||
|
* @since 2.7.0
|
||||||
|
*/
|
||||||
|
class SessionMessageController extends AbstractController
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @param \Symfony\Component\HttpFoundation\Request $oRequest
|
||||||
|
*
|
||||||
|
* @return \Symfony\Component\HttpFoundation\Response
|
||||||
|
*/
|
||||||
|
public function AddMessageAction(Request $oRequest)
|
||||||
|
{
|
||||||
|
$aData = array();
|
||||||
|
|
||||||
|
/** @var \Combodo\iTop\Portal\Helper\RequestManipulatorHelper $oRequestManipulator */
|
||||||
|
$oRequestManipulator = $this->get('request_manipulator');
|
||||||
|
/** @var \Combodo\iTop\Portal\Helper\SessionMessageHelper $oSessionMessageHelper */
|
||||||
|
$oSessionMessageHelper = $this->get('session_message_helper');
|
||||||
|
|
||||||
|
// Retrieve parameters
|
||||||
|
$sMessageSeverity = $oRequestManipulator->ReadParam('sSeverity');
|
||||||
|
$sMessageContent = $oRequestManipulator->ReadParam('sContent');
|
||||||
|
|
||||||
|
// Check parameters consistency
|
||||||
|
if (empty($sMessageSeverity) || empty($sMessageContent))
|
||||||
|
{
|
||||||
|
throw new HttpException(Response::HTTP_BAD_REQUEST, 'Message must have a severity and a content, make sure both sSeverity & sContent parameters are sent.');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add message
|
||||||
|
$oSessionMessageHelper->AddMessage(uniqid(), $sMessageContent, $sMessageSeverity);
|
||||||
|
|
||||||
|
return new JsonResponse($aData);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,76 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Copyright (C) 2013-2020 Combodo SARL
|
||||||
|
*
|
||||||
|
* This file is part of iTop.
|
||||||
|
*
|
||||||
|
* iTop is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* iTop is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Combodo\iTop\Portal\EventListener;
|
||||||
|
|
||||||
|
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
|
||||||
|
use utils;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class CssFromSassCompiler
|
||||||
|
*
|
||||||
|
* This class is mostly here for developers comfort. SCSS files are already compiled when Symfony is creating its cache, but we need them to re-compile
|
||||||
|
* when tuning the SCSS files during development. To do so, just by pass the HTTP cache by hitting Ctrl + F5
|
||||||
|
*
|
||||||
|
* @package Combodo\iTop\Portal\EventListener
|
||||||
|
* @since 2.7.0
|
||||||
|
*/
|
||||||
|
class CssFromSassCompiler
|
||||||
|
{
|
||||||
|
/** @var array $aCombodoPortalInstanceConf */
|
||||||
|
private $aCombodoPortalInstanceConf;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* CssFromSassCompiler constructor.
|
||||||
|
*
|
||||||
|
* @param array $aCombodoPortalInstanceConf
|
||||||
|
*/
|
||||||
|
public function __construct($aCombodoPortalInstanceConf)
|
||||||
|
{
|
||||||
|
$this->aCombodoPortalInstanceConf = $aCombodoPortalInstanceConf;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param \Symfony\Component\HttpKernel\Event\GetResponseEvent $oGetResponseEvent
|
||||||
|
*/
|
||||||
|
public function onKernelRequest(GetResponseEvent $oGetResponseEvent)
|
||||||
|
{
|
||||||
|
// Force compilation need only when by-passing cache to limit server load.
|
||||||
|
if (isset($_SERVER['HTTP_CACHE_CONTROL']) && ($_SERVER['HTTP_CACHE_CONTROL'] !== 'no-cache'))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$aImportPaths = array($_ENV['COMBODO_PORTAL_BASE_ABSOLUTE_PATH'].'css/');
|
||||||
|
foreach ($this->aCombodoPortalInstanceConf['properties']['themes'] as $sKey => $value)
|
||||||
|
{
|
||||||
|
if (!is_array($value))
|
||||||
|
{
|
||||||
|
utils::GetCSSFromSASS('env-'.utils::GetCurrentEnvironment().'/'.$value, $aImportPaths);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
foreach ($value as $sSubValue)
|
||||||
|
{
|
||||||
|
utils::GetCSSFromSASS('env-'.utils::GetCurrentEnvironment().'/'.$sSubValue, $aImportPaths);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -325,25 +325,20 @@
|
|||||||
<div class="container-fluid" id="main-wrapper">
|
<div class="container-fluid" id="main-wrapper">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-xs-12 col-sm-9 col-md-10 col-sm-offset-3 col-md-offset-2">
|
<div class="col-xs-12 col-sm-9 col-md-10 col-sm-offset-3 col-md-offset-2">
|
||||||
|
<section class="row" id="session-messages">
|
||||||
{% if app['combodo.current_user.session_messages']|length > 0 %}
|
<div class="col-xs-12">
|
||||||
<section class="row" id="session-messages">
|
{% for aSessionMessage in app['session_message_helper'] %}
|
||||||
<div class="col-xs-12">
|
<div class="{{ aSessionMessage['css_classes'] }}">
|
||||||
{% for aSessionMessage in app['combodo.current_user.session_messages'] %}
|
<button type="button" class="close" data-dismiss="alert" aria-label="X"><span class="fas fa-times"></span></button>
|
||||||
<div class="{{ aSessionMessage['css_classes'] }}">
|
{{ aSessionMessage['message'] }}
|
||||||
<button type="button" class="close" data-dismiss="alert" aria-label="X"><span class="fas fa-times"></span></button>
|
</div>
|
||||||
{{ aSessionMessage['message'] }}
|
{% endfor %}
|
||||||
</div>
|
</div>
|
||||||
{% endfor %}
|
</section>
|
||||||
</div>
|
|
||||||
</section>
|
|
||||||
{% endif %}
|
|
||||||
|
|
||||||
<section class="row" id="main-header">
|
<section class="row" id="main-header">
|
||||||
{% block pMainHeader %}
|
{% block pMainHeader %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
<section class="row" id="main-content">
|
<section class="row" id="main-content">
|
||||||
{% block pMainContent %}
|
{% block pMainContent %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|||||||
Reference in New Issue
Block a user