N°5620 - Hide the organization filter with a conf parameter

This commit is contained in:
odain
2022-11-15 09:49:36 +01:00
parent 1c705bdb94
commit 0ef5e9d3ff
3 changed files with 93 additions and 7 deletions

View File

@@ -1254,6 +1254,14 @@ class Config
'source_of_value' => '',
'show_in_conf_sample' => false,
],
'navigation_menu.show_organization_filter' => [
'type' => 'bool',
'description' => 'Display organization filter in menu',
'default' => true,
'value' => true,
'source_of_value' => '',
'show_in_conf_sample' => false,
],
'quick_create.enabled' => [
'type' => 'bool',
'description' => 'Whether or not the quick create is enabled',
@@ -1885,7 +1893,7 @@ class Config
}
if (strlen($sNoise) > 0)
{
// Note: sNoise is an html output, but so far it was ok for me (e.g. showing the entire call stack)
// Note: sNoise is an html output, but so far it was ok for me (e.g. showing the entire call stack)
throw new ConfigException('Syntax error in configuration file',
array('file' => $sConfigFile, 'error' => '<tt>'.utils::EscapeHtml($sNoise, ENT_QUOTES).'</tt>'));
}
@@ -2695,7 +2703,7 @@ class ConfigPlaceholdersResolver
}
$sPattern = '/\%(env|server)\((\w+)\)(?:\?:(\w*))?\%/'; //3 capturing groups, ie `%env(HTTP_PORT)?:8080%` produce: `env` `HTTP_PORT` and `8080`.
if (! preg_match_all($sPattern, $rawValue, $aMatchesCollection, PREG_SET_ORDER))
{
return $rawValue;

View File

@@ -19,7 +19,6 @@
namespace Combodo\iTop\Application\UI\Base\Layout\NavigationMenu;
use ApplicationContext;
use ApplicationMenu;
use appUserPreferences;
@@ -196,7 +195,7 @@ class NavigationMenu extends UIBlock implements iKeyboardShortcut
}
return '';
}
/**
* @return array
*/
@@ -290,6 +289,14 @@ class NavigationMenu extends UIBlock implements iKeyboardShortcut
}
}
/**
* @return True if the silo selection is enabled, false otherwise
* @since 3.1.0
*/
public function IsSiloSelectionEnabled() : bool {
return MetaModel::GetConfig()->Get('navigation_menu.show_organization_filter');
}
/**
* @return void
* @throws \CoreException
@@ -301,6 +308,10 @@ class NavigationMenu extends UIBlock implements iKeyboardShortcut
$this->bHasSiloSelected = false;
$this->sSiloLabel = null;
if (! $this->IsSiloSelectionEnabled()){
return;
}
//TODO 3.0 Use components if we have the time to build select/autocomplete components before release
// List of visible Organizations
$iCount = 0;
@@ -343,7 +354,7 @@ class NavigationMenu extends UIBlock implements iKeyboardShortcut
$this->aSiloSelection['html'] = '<form data-role="ibo-navigation-menu--silo-selection--form" action="'.utils::GetAbsoluteUrlAppRoot().'pages/UI.php">'; //<select class="org_combo" name="c[org_id]" title="Pick an organization" onChange="this.form.submit();">';
$oPage = new \CaptureWebPage();
$oWidget = new UIExtKeyWidget('Organization', 'org_id', '', true /* search mode */);
$iMaxComboLength = MetaModel::GetConfig()->Get('max_combo_length');
$this->aSiloSelection['html'] .= $oWidget->DisplaySelect($oPage, $iMaxComboLength, false, Dict::S('UI:Layout:NavigationMenu:Silo:Label'), $oSet, $iCurrentOrganization, false, 'c[org_id]', '',
@@ -376,7 +387,7 @@ $sAddClearButton
JS;
}
}
/**
* Compute if the menu is expanded or collapsed
*
@@ -479,4 +490,4 @@ JS;
{
return "[data-role='".static::BLOCK_CODE."']";
}
}
}

View File

@@ -0,0 +1,67 @@
<?php
namespace UI\Base\Layout;
use ApplicationContext;
use Combodo\iTop\Application\UI\Base\Component\PopoverMenu\PopoverMenu;
use Combodo\iTop\Application\UI\Base\Layout\NavigationMenu\NavigationMenu;
use Combodo\iTop\Test\UnitTest\ItopDataTestCase;
/**
*
* @runTestsInSeparateProcesses
* @preserveGlobalState disabled
* @backupGlobals disabled
* Class NavigationMenuTest
*
* @package UI\Base\Layout
*/
class NavigationMenuTest extends ItopDataTestCase {
public function IsAllowedProvider(){
return [
'show menu' => [ true ],
'hide menu' => [ false ],
];
}
/**
* @dataProvider IsAllowedProvider
* test used to make sure backward compatibility is ensured
*/
public function testIsAllowed($bExpectedIsAllowed=true){
\MetaModel::GetConfig()->Set('navigation_menu.show_organization_filter', $bExpectedIsAllowed);
$oNavigationMenu = new NavigationMenu(
$this->createMock(ApplicationContext::class),
$this->createMock(PopoverMenu::class));
$isAllowed = $oNavigationMenu->IsSiloSelectionEnabled();
$this->assertEquals($bExpectedIsAllowed, $isAllowed);
}
public function testIsAllowed_BackwardCompatibility_NoVariableInConfFile(){
\MetaModel::GetConfig()->Set('navigation_menu.show_organization_filter', false);
$sTmpFilePath = tempnam(sys_get_temp_dir(), 'test_');
$oInitConfig = \MetaModel::GetConfig();
$oInitConfig->WriteToFile($sTmpFilePath);
//remove variable for the test
$aLines = file($sTmpFilePath);
$aRows = array();
foreach ($aLines as $key => $sLine) {
if (!preg_match('/navigation_menu.show_organization_filter/', $sLine)) {
$aRows[] = $sLine;
}
}
file_put_contents($sTmpFilePath, implode("\n", $aRows));
$oTempConfig = new \Config($sTmpFilePath);
$isAllowed = $oTempConfig->Get('navigation_menu.show_organization_filter');
$this->assertEquals(true, $isAllowed);
unlink($sTmpFilePath);
}
}