N°478 - Customizable access to the 'Admin Tools'

SVN:trunk[5364]
This commit is contained in:
Eric Espié
2018-02-23 11:13:07 +00:00
parent b952f9da4a
commit d65bd97956
29 changed files with 738 additions and 264 deletions

View File

@@ -740,7 +740,7 @@ EOF
// Relative to the module
if ($bIsUrl)
{
$sPHP = "utils::GetAbsoluteUrlAppRoot().".self::QuoteForPHP($sModuleRelativeDir.''.$sPath);
$sPHP = "utils::GetAbsoluteUrlModulePage('$sModuleRelativeDir', ".self::QuoteForPHP($sPath).")";
}
else
{
@@ -1817,12 +1817,32 @@ EOF;
}
$fRank = (float) $oMenu->GetChildText('rank');
$sEnablePermission = 'UR_ALLOWED_YES';
if ($sEnableClass = $oMenu->GetChildText('enable_class'))
{
$sEnableAction = $oMenu->GetChildText('enable_action', 'UR_ACTION_MODIFY');
$sEnablePermission = $oMenu->GetChildText('enable_permission', 'UR_ALLOWED_YES');
$sEnableStimulus = $oMenu->GetChildText('enable_stimulus');
if ($sEnableStimulus != null)
{
$sOptionalEnableParams = ", '$sEnableClass', $sEnableAction, $sEnablePermission, '$sEnableStimulus'";
}
else
{
$sOptionalEnableParams = ", '$sEnableClass', $sEnableAction, $sEnablePermission, null";
}
}
else
{
$sOptionalEnableParams = ", null, UR_ACTION_MODIFY, UR_ALLOWED_YES, null";
}
switch($sMenuClass)
{
case 'WebPageMenuNode':
$sUrl = $oMenu->GetChildText('url');
$sUrlSpec = $this->PathToPHP($sUrl, $sModuleRelativeDir, true /* Url */);
$sNewMenu = "new WebPageMenuNode('$sMenuId', $sUrlSpec, $sParentSpec, $fRank);";
$sNewMenu = "new WebPageMenuNode('$sMenuId', $sUrlSpec, $sParentSpec, $fRank {$sOptionalEnableParams});";
break;
case 'DashboardMenuNode':
@@ -1855,11 +1875,11 @@ EOF;
}
$oXMLDoc->save($sTempTargetDir.'/'.$sModuleRelativeDir.'/'.$sFileName);
}
$sNewMenu = "new DashboardMenuNode('$sMenuId', $sTemplateSpec, $sParentSpec, $fRank);";
$sNewMenu = "new DashboardMenuNode('$sMenuId', $sTemplateSpec, $sParentSpec, $fRank {$sOptionalEnableParams});";
break;
case 'ShortcutContainerMenuNode':
$sNewMenu = "new ShortcutContainerMenuNode('$sMenuId', $sParentSpec, $fRank);";
$sNewMenu = "new ShortcutContainerMenuNode('$sMenuId', $sParentSpec, $fRank {$sOptionalEnableParams});";
break;
case 'OQLMenuNode':
@@ -1879,64 +1899,28 @@ EOF;
default:
$sSearchFormOpen = 'null'; // Actual open/close status depend on the config
}
$sSearchFormOpen = ($oMenu->GetChildText('search_form_open') == '') ? 'null' : 'false';
$sNewMenu = "new OQLMenuNode('$sMenuId', $sOQL, $sParentSpec, $fRank, $bSearch, $sSearchFormOpen);";
$sNewMenu = "new OQLMenuNode('$sMenuId', $sOQL, $sParentSpec, $fRank, $bSearch {$sOptionalEnableParams}, $sSearchFormOpen);";
break;
case 'NewObjectMenuNode':
$sClass = $oMenu->GetChildText('class');
$sNewMenu = "new NewObjectMenuNode('$sMenuId', '$sClass', $sParentSpec, $fRank);";
$sNewMenu = "new NewObjectMenuNode('$sMenuId', '$sClass', $sParentSpec, $fRank {$sOptionalEnableParams});";
break;
case 'SearchMenuNode':
$sClass = $oMenu->GetChildText('class');
$sNewMenu = "new SearchMenuNode('$sMenuId', '$sClass', $sParentSpec, $fRank);";
$sNewMenu = "new SearchMenuNode('$sMenuId', '$sClass', $sParentSpec, $fRank, null {$sOptionalEnableParams});";
break;
case 'TemplateMenuNode':
$sTemplateFile = $oMenu->GetChildText('template_file');
$sTemplateSpec = $this->PathToPHP($sTemplateFile, $sModuleRelativeDir);
if ($sEnableClass = $oMenu->GetChildText('enable_class'))
{
$sEnableAction = $oMenu->GetChildText('enable_action', 'null');
$sEnablePermission = $oMenu->GetChildText('enable_permission', 'UR_ALLOWED_YES');
$sEnableStimulus = $oMenu->GetChildText('enable_stimulus');
if ($sEnableStimulus != null)
{
$sNewMenu = "new TemplateMenuNode('$sMenuId', $sTemplateSpec, $sParentSpec, $fRank, '$sEnableClass', $sEnableAction, $sEnablePermission, '$sEnableStimulus');";
}
else
{
$sNewMenu = "new TemplateMenuNode('$sMenuId', $sTemplateSpec, $sParentSpec, $fRank, '$sEnableClass', $sEnableAction, $sEnablePermission);";
}
}
else
{
$sNewMenu = "new TemplateMenuNode('$sMenuId', $sTemplateSpec, $sParentSpec, $fRank);";
}
$sNewMenu = "new TemplateMenuNode('$sMenuId', $sTemplateSpec, $sParentSpec, $fRank {$sOptionalEnableParams});";
break;
case 'MenuGroup':
default:
if ($sEnableClass = $oMenu->GetChildText('enable_class'))
{
$sEnableAction = $oMenu->GetChildText('enable_action', 'null');
$sEnablePermission = $oMenu->GetChildText('enable_permission', 'UR_ALLOWED_YES');
$sEnableStimulus = $oMenu->GetChildText('enable_stimulus');
if ($sEnableStimulus != null)
{
$sNewMenu = "new $sMenuClass('$sMenuId', $fRank, '$sEnableClass', $sEnableAction, $sEnablePermission, '$sEnableStimulus');";
}
else
{
$sNewMenu = "new $sMenuClass('$sMenuId', $fRank, '$sEnableClass', $sEnableAction, $sEnablePermission);";
}
}
else
{
$sNewMenu = "new $sMenuClass('$sMenuId', $fRank);";
}
$sNewMenu = "new $sMenuClass('$sMenuId', $fRank {$sOptionalEnableParams});";
}
$aPHPMenu = array("\$__comp_menus__['$sMenuId'] = $sNewMenu");

View File

@@ -35,7 +35,7 @@
* }
*/
define('ITOP_DESIGN_LATEST_VERSION', '1.4'); // iTop >= 2.4.0
define('ITOP_DESIGN_LATEST_VERSION', '1.5'); // iTop >= 2.5.0
class iTopDesignFormat
{
@@ -67,6 +67,12 @@ class iTopDesignFormat
'1.4' => array(
'previous' => '1.3',
'go_to_previous' => 'From14To13',
'next' => '1.5',
'go_to_next' => 'From14To15',
),
'1.5' => array(
'previous' => '1.4',
'go_to_previous' => 'From15To14',
'next' => null,
'go_to_next' => null,
),
@@ -172,8 +178,10 @@ class iTopDesignFormat
}
/**
* An alternative to getNodePath, that gives the id of nodes instead of the position within the children
*/
* An alternative to getNodePath, that gives the id of nodes instead of the position within the children
* @param $oNode
* @return string
*/
public static function GetItopNodePath($oNode)
{
if ($oNode instanceof DOMDocument) return '';
@@ -245,7 +253,6 @@ class iTopDesignFormat
* @param string $sFrom The source format version
* @param string $sTo The desired format version
* @param object $oFactory Full data model (not yet used, aimed at allowing conversion that could not be performed without knowing the whole data model)
* @return bool True on success
*/
protected function DoConvert($sFrom, $sTo, $oFactory = null)
{
@@ -299,6 +306,7 @@ class iTopDesignFormat
/**
* Upgrade the format from version 1.0 to 1.1
* @param $oFactory
* @return void (Errors are logged)
*/
protected function From10To11($oFactory)
@@ -350,9 +358,10 @@ class iTopDesignFormat
}
}
}
/**
* Downgrade the format from version 1.1 to 1.0
* @param $oFactory
* @return void (Errors are logged)
*/
protected function From11To10($oFactory)
@@ -422,6 +431,7 @@ class iTopDesignFormat
/**
* Upgrade the format from version 1.1 to 1.2
* @param $oFactory
* @return void (Errors are logged)
*/
protected function From11To12($oFactory)
@@ -430,6 +440,7 @@ class iTopDesignFormat
/**
* Downgrade the format from version 1.2 to 1.1
* @param $oFactory
* @return void (Errors are logged)
*/
protected function From12To11($oFactory)
@@ -487,6 +498,7 @@ class iTopDesignFormat
/**
* Upgrade the format from version 1.2 to 1.3
* @param $oFactory
* @return void (Errors are logged)
*/
protected function From12To13($oFactory)
@@ -495,6 +507,7 @@ class iTopDesignFormat
/**
* Downgrade the format from version 1.3 to 1.2
* @param $oFactory
* @return void (Errors are logged)
*/
protected function From13To12($oFactory)
@@ -544,17 +557,19 @@ class iTopDesignFormat
$oNode->setAttribute('_delta', 'must_exist');
}
}
/**
* Upgrade the format from version 1.3 to 1.4
* @param $oFactory
* @return void (Errors are logged)
*/
protected function From13To14($oFactory)
{
}
/**
* Downgrade the format from version 1.4 to 1.3
* @param $oFactory
* @return void (Errors are logged)
*/
protected function From14To13($oFactory)
@@ -585,8 +600,34 @@ class iTopDesignFormat
$this->DeleteNode($oNode);
}
}
/**
* Downgrade the format from version 1.5 to 1.4
* @param $oFactory
* @return void (Errors are logged)
*/
protected function From15To14($oFactory)
{
$oXPath = new DOMXPath($this->oDocument);
// Remove nodes on some menus
//
$sPath = "/itop_design/menus/menu[@xsi:type!='MenuGroup' and @xsi:type!='TemplateMenuNode']";
$oNodeList = $oXPath->query("$sPath/enable_class | $sPath/enable_action | $sPath/enable_permission | $sPath/enable_stimulus");
foreach ($oNodeList as $oNode)
{
$this->LogWarning('Node '.self::GetItopNodePath($oNode).' is irrelevant in this version, it will be ignored. Use enable_admin_only instead.');
}
}
/**
* Upgrade the format from version 1.4 to 1.5
* @param $oFactory
* @return void (Errors are logged)
*/
protected function From14To15($oFactory)
{
}
/**
* Delete a node from the DOM and make sure to also remove the immediately following line break (DOMText), if any.