Merge branch 'feature/allow-to-disable-stacktraces-9113'

resolves #9113
This commit is contained in:
Johannes Meyer 2015-08-24 14:48:28 +02:00
commit 0bf701a373
5 changed files with 88 additions and 30 deletions

View File

@ -25,6 +25,20 @@ class ApplicationConfigForm extends Form
*/ */
public function createElements(array $formData) public function createElements(array $formData)
{ {
$this->addElement(
'checkbox',
'global_show_stacktraces',
array(
'required' => true,
'value' => true,
'label' => $this->translate('Show Stacktraces'),
'description' => $this->translate(
'Set whether to show an exception\'s stacktrace by default. This can also'
. ' be set in a user\'s preferences with the appropriate permission.'
)
)
);
$this->addElement( $this->addElement(
'text', 'text',
'global_module_path', 'global_module_path',

View File

@ -5,6 +5,7 @@ namespace Icinga\Forms;
use Exception; use Exception;
use DateTimeZone; use DateTimeZone;
use Icinga\Application\Config;
use Icinga\Application\Logger; use Icinga\Application\Logger;
use Icinga\Authentication\Auth; use Icinga\Authentication\Auth;
use Icinga\User\Preferences; use Icinga\User\Preferences;
@ -178,6 +179,19 @@ class PreferenceForm extends Form
) )
); );
if (Auth::getInstance()->hasPermission('application/stacktraces')) {
$this->addElement(
'checkbox',
'show_stacktraces',
array(
'required' => true,
'value' => $this->getDefaultShowStacktraces(),
'label' => $this->translate('Show Stacktraces'),
'description' => $this->translate('Set whether to show an exception\'s stacktrace.')
)
);
}
$this->addElement( $this->addElement(
'checkbox', 'checkbox',
'show_benchmark', 'show_benchmark',
@ -269,4 +283,14 @@ class PreferenceForm extends Form
$locale = Translator::getPreferredLocaleCode($_SERVER['HTTP_ACCEPT_LANGUAGE']); $locale = Translator::getPreferredLocaleCode($_SERVER['HTTP_ACCEPT_LANGUAGE']);
return $locale; return $locale;
} }
/**
* Return the default global setting for show_stacktraces
*
* @return bool
*/
protected function getDefaultShowStacktraces()
{
return Config::app()->get('global', 'show_stacktraces', true);
}
} }

View File

@ -20,9 +20,26 @@ class RoleForm extends ConfigForm
* *
* @var array * @var array
*/ */
protected $providedPermissions = array( protected $providedPermissions;
'*' => 'Allow everything (*)',
'config/*' => 'Allow config access (config/*)', /**
* Provided restrictions by currently loaded modules
*
* @var array
*/
protected $providedRestrictions = array();
/**
* {@inheritdoc}
*/
public function init()
{
$this->providedPermissions = array(
'*' => $this->translate('Allow everything') . ' (*)',
'application/stacktraces' => $this->translate(
'Allow to adjust in the preferences whether to show stacktraces'
) . ' (application/stacktraces)',
'config/*' => $this->translate('Allow config access') . ' (config/*)',
/* /*
// [tg] seems excessive for me, hidden for rc1, tbd // [tg] seems excessive for me, hidden for rc1, tbd
'config/application/*' => 'config/application/*', 'config/application/*' => 'config/application/*',
@ -50,18 +67,7 @@ class RoleForm extends ConfigForm
*/ */
); );
/**
* Provided restrictions by currently loaded modules
*
* @var array
*/
protected $providedRestrictions = array();
/**
* {@inheritdoc}
*/
public function init()
{
$helper = new Zend_Form_Element('bogus'); $helper = new Zend_Form_Element('bogus');
$mm = Icinga::app()->getModuleManager(); $mm = Icinga::app()->getModuleManager();
foreach ($mm->listInstalledModules() as $moduleName) { foreach ($mm->listInstalledModules() as $moduleName) {

View File

@ -212,9 +212,19 @@ class Web extends EmbeddedWeb
$this->frontController = Zend_Controller_Front::getInstance(); $this->frontController = Zend_Controller_Front::getInstance();
$this->frontController->setRequest($this->getRequest()); $this->frontController->setRequest($this->getRequest());
$this->frontController->setControllerDirectory($this->getApplicationDir('/controllers')); $this->frontController->setControllerDirectory($this->getApplicationDir('/controllers'));
$displayExceptions = $this->config->get('global', 'show_stacktraces', true);
if ($this->user !== null && $this->user->can('application/stacktraces')) {
$displayExceptions = $this->user->getPreferences()->getValue(
'icingaweb',
'show_stacktraces',
$displayExceptions
);
}
$this->frontController->setParams( $this->frontController->setParams(
array( array(
'displayExceptions' => true 'displayExceptions' => $displayExceptions
) )
); );
return $this; return $this;

View File

@ -53,6 +53,10 @@ class GeneralConfigStep extends Step
$generalHtml = '' $generalHtml = ''
. '<ul>' . '<ul>'
. '<li>' . ($this->data['generalConfig']['global_show_stacktraces']
? t('An exception\'s stacktrace is shown to every user by default.')
: t('An exception\'s stacktrace is hidden from every user by default.')
) . '</li>'
. '<li>' . sprintf( . '<li>' . sprintf(
$this->data['generalConfig']['global_config_backend'] === 'ini' ? sprintf( $this->data['generalConfig']['global_config_backend'] === 'ini' ? sprintf(
t('Preferences will be stored per user account in INI files at: %s'), t('Preferences will be stored per user account in INI files at: %s'),