Merge remote-tracking branch 'origin/support/2.7' into support/3.0

# Conflicts:
#	application/dashlet.class.inc.php
#	pages/ajax.render.php
#	pages/csvimport.php
#	test/phpunit.xml.dist
This commit is contained in:
Benjamin Dalsass
2022-05-18 10:38:50 +02:00
13 changed files with 91 additions and 25 deletions

View File

@@ -262,7 +262,7 @@ abstract class Dashlet
} }
} catch (OqlException $e) { } catch (OqlException $e) {
$oDashletContainer->AddCSSClass("dashlet-content"); $oDashletContainer->AddCSSClass("dashlet-content");
$oDashletContainer->AddHtml('<p>'.$e->GetUserFriendlyDescription().'</p>'); $oDashletContainer->AddHtml('<p>'.utils::HtmlEntities($e->GetUserFriendlyDescription()).'</p>');
} catch (Exception $e) { } catch (Exception $e) {
$oDashletContainer->AddCSSClass("dashlet-content"); $oDashletContainer->AddCSSClass("dashlet-content");
$oDashletContainer->AddHtml('<p>'.$e->getMessage().'</p>'); $oDashletContainer->AddHtml('<p>'.$e->getMessage().'</p>');

View File

@@ -454,6 +454,11 @@ class utils
$retValue = preg_replace('/[^a-zA-Z0-9_]/', '', $value); $retValue = preg_replace('/[^a-zA-Z0-9_]/', '', $value);
break; break;
// For URL
case 'url':
$retValue = filter_var($value, FILTER_SANITIZE_URL);
break;
default: default:
case static::ENUM_SANITIZATION_FILTER_RAW_DATA: case static::ENUM_SANITIZATION_FILTER_RAW_DATA:
$retValue = $value; $retValue = $value;

View File

@@ -277,7 +277,7 @@ class ActionEmail extends ActionNotification
protected function FindRecipients($sRecipAttCode, $aArgs) protected function FindRecipients($sRecipAttCode, $aArgs)
{ {
$sOQL = $this->Get($sRecipAttCode); $sOQL = $this->Get($sRecipAttCode);
if (strlen($sOQL) == '') return ''; if (strlen($sOQL) === 0) return '';
try try
{ {

View File

@@ -2026,9 +2026,9 @@ abstract class DBObject implements iDisplay
/** /**
* check attributes together * check attributes together
* *
* @overwritable-hook You can extend this method in order to provide your own logic. * @overwritable-hook You can extend this method in order to provide your own logic.
* *
* @return bool * @return true|string true if successful, the error description otherwise
*/ */
public function CheckConsistency() public function CheckConsistency()
{ {

View File

@@ -1195,8 +1195,10 @@ class DisplayableGraph extends SimpleGraph
* @param float $xMax Right coordinate of the bounding box to display the graph * @param float $xMax Right coordinate of the bounding box to display the graph
* @param float $yMin Top coordinate of the bounding box to display the graph * @param float $yMin Top coordinate of the bounding box to display the graph
* @param float $yMax Bottom coordinate of the bounding box to display the graph * @param float $yMax Bottom coordinate of the bounding box to display the graph
*
* @since 2.7.7 3.0.2 3.1.0 N°4985 $sComments param is no longer optional
*/ */
function RenderAsPDF(PDFPage $oPage, $sComments = '', $sContextKey, $xMin = -1, $xMax = -1, $yMin = -1, $yMax = -1) function RenderAsPDF(PDFPage $oPage, $sComments, $sContextKey, $xMin = -1, $xMax = -1, $yMin = -1, $yMax = -1)
{ {
$aContextDefs = static::GetContextDefinitions($sContextKey, false); // No need to develop the parameters $aContextDefs = static::GetContextDefinitions($sContextKey, false); // No need to develop the parameters
$oPdf = $oPage->get_tcpdf(); $oPdf = $oPage->get_tcpdf();

View File

@@ -162,12 +162,20 @@ class BrickCollection
// - Home // - Home
$this->aHomeOrdering = $this->aAllowedBricks; $this->aHomeOrdering = $this->aAllowedBricks;
usort($this->aHomeOrdering, function (PortalBrick $a, PortalBrick $b) { usort($this->aHomeOrdering, function (PortalBrick $a, PortalBrick $b) {
return $a->GetRankHome() > $b->GetRankHome(); if ($a->GetRankHome() === $b->GetRankHome()) {
return 0;
}
return $a->GetRankHome() > $b->GetRankHome() ? 1 : -1;
}); });
// - Navigation menu // - Navigation menu
$this->aNavigationMenuOrdering = $this->aAllowedBricks; $this->aNavigationMenuOrdering = $this->aAllowedBricks;
usort($this->aNavigationMenuOrdering, function (PortalBrick $a, PortalBrick $b) { usort($this->aNavigationMenuOrdering, function (PortalBrick $a, PortalBrick $b) {
return $a->GetRankNavigationMenu() > $b->GetRankNavigationMenu(); if ($a->GetRankNavigationMenu() === $b->GetRankNavigationMenu()) {
return 0;
}
return $a->GetRankNavigationMenu() > $b->GetRankNavigationMenu() ? 1 : -1;
}); });
} }

View File

@@ -485,7 +485,11 @@ class ManageBrick extends PortalBrick
if (!$this->IsGroupingByDistinctValues($sName)) if (!$this->IsGroupingByDistinctValues($sName))
{ {
usort($this->aGrouping[$sName]['groups'], function ($a, $b) { usort($this->aGrouping[$sName]['groups'], function ($a, $b) {
return $a['rank'] > $b['rank']; if ($a['rank'] === $b['rank']) {
return 0;
}
return $a['rank'] > $b['rank'] ? 1 : -1;
}); });
} }

View File

@@ -91,7 +91,10 @@ class Lists extends AbstractConfiguration
} }
// - Sorting list items by rank // - Sorting list items by rank
usort($aListItems, function ($a, $b) { usort($aListItems, function ($a, $b) {
return $a['rank'] > $b['rank']; if ($a['rank'] == $b['rank']) {
return 0;
}
return $a['rank'] > $b['rank'] ? 1 : -1;
}); });
$aClassLists[$sListId] = $aListItems; $aClassLists[$sListId] = $aListItems;
} }

View File

@@ -703,7 +703,7 @@ class ObjectFormManager extends FormManager
/** @var Field $oField */ /** @var Field $oField */
$oField = null; $oField = null;
if (is_callable(get_class($oAttDef).'::MakeFormField')) if (is_callable([$oAttDef, 'MakeFormField']))
{ {
$oField = $oAttDef->MakeFormField($this->oObject); $oField = $oAttDef->MakeFormField($this->oObject);
} }

View File

@@ -932,7 +932,7 @@ try
$aExtraParams = utils::ReadParam('extra_params', array(), false, 'raw_data'); $aExtraParams = utils::ReadParam('extra_params', array(), false, 'raw_data');
$sDashboardFile = utils::ReadParam('file', '', false, 'raw_data'); $sDashboardFile = utils::ReadParam('file', '', false, 'raw_data');
$sReloadURL = utils::ReadParam('reload_url', '', false, 'raw_data'); $sReloadURL = utils::ReadParam('reload_url', '', false, 'url');
$oDashboard = RuntimeDashboard::GetDashboard($sDashboardFile, $sDashboardId); $oDashboard = RuntimeDashboard::GetDashboard($sDashboardFile, $sDashboardId);
$aResult = array('error' => ''); $aResult = array('error' => '');
if (!is_null($oDashboard)) if (!is_null($oDashboard))
@@ -950,7 +950,7 @@ try
$sDashboardId = utils::ReadParam('dashboard_id', '', false, 'raw_data'); $sDashboardId = utils::ReadParam('dashboard_id', '', false, 'raw_data');
$aExtraParams = utils::ReadParam('extra_params', array(), false, 'raw_data'); $aExtraParams = utils::ReadParam('extra_params', array(), false, 'raw_data');
$sDashboardFile = utils::ReadParam('file', '', false, 'raw_data'); $sDashboardFile = utils::ReadParam('file', '', false, 'raw_data');
$sReloadURL = utils::ReadParam('reload_url', '', false, 'raw_data'); $sReloadURL = utils::ReadParam('reload_url', '', false, 'url');
$oDashboard = RuntimeDashboard::GetDashboard($sDashboardFile, $sDashboardId); $oDashboard = RuntimeDashboard::GetDashboard($sDashboardFile, $sDashboardId);
$aResult = array('error' => ''); $aResult = array('error' => '');
if (!is_null($oDashboard)) if (!is_null($oDashboard))
@@ -967,7 +967,7 @@ try
$sDashboardId = utils::ReadParam('dashboard_id', '', false, 'context_param'); $sDashboardId = utils::ReadParam('dashboard_id', '', false, 'context_param');
$aExtraParams = utils::ReadParam('extra_params', array(), false, 'raw_data'); $aExtraParams = utils::ReadParam('extra_params', array(), false, 'raw_data');
$sReloadURL = utils::ReadParam('reload_url', '', false, 'raw_data'); $sReloadURL = utils::ReadParam('reload_url', '', false, 'url');
appUserPreferences::SetPref('display_original_dashboard_'.$sDashboardId, false); appUserPreferences::SetPref('display_original_dashboard_'.$sDashboardId, false);
$sJSExtraParams = json_encode($aExtraParams); $sJSExtraParams = json_encode($aExtraParams);
$aParams = array(); $aParams = array();
@@ -1009,7 +1009,7 @@ JS
case 'revert_dashboard': case 'revert_dashboard':
$sDashboardId = utils::ReadParam('dashboard_id', '', false, 'raw_data'); $sDashboardId = utils::ReadParam('dashboard_id', '', false, 'raw_data');
$sReloadURL = utils::ReadParam('reload_url', '', false, 'raw_data'); $sReloadURL = utils::ReadParam('reload_url', '', false, 'url');
appUserPreferences::UnsetPref('display_original_dashboard_'.$sDashboardId); appUserPreferences::UnsetPref('display_original_dashboard_'.$sDashboardId);
$oDashboard = new RuntimeDashboard($sDashboardId); $oDashboard = new RuntimeDashboard($sDashboardId);
$oDashboard->Revert(); $oDashboard->Revert();
@@ -1039,7 +1039,7 @@ EOF
$aParams['cells'] = utils::ReadParam('cells', array(), false, 'raw_data'); $aParams['cells'] = utils::ReadParam('cells', array(), false, 'raw_data');
$aParams['auto_reload'] = utils::ReadParam('auto_reload', false); $aParams['auto_reload'] = utils::ReadParam('auto_reload', false);
$aParams['auto_reload_sec'] = utils::ReadParam('auto_reload_sec', 300); $aParams['auto_reload_sec'] = utils::ReadParam('auto_reload_sec', 300);
$sReloadURL = utils::ReadParam('reload_url', '', false, 'raw_data'); $sReloadURL = utils::ReadParam('reload_url', '', false, 'url');
$oDashboard = new RuntimeDashboard($sDashboardId); $oDashboard = new RuntimeDashboard($sDashboardId);
$oDashboard->FromParams($aParams); $oDashboard->FromParams($aParams);
$oDashboard->SetReloadURL($sReloadURL); $oDashboard->SetReloadURL($sReloadURL);
@@ -1051,7 +1051,7 @@ EOF
$aExtraParams = utils::ReadParam('extra_params', array(), false, 'raw_data'); $aExtraParams = utils::ReadParam('extra_params', array(), false, 'raw_data');
$aExtraParams['dashboard_div_id'] = utils::Sanitize($sId, '', 'element_identifier'); $aExtraParams['dashboard_div_id'] = utils::Sanitize($sId, '', 'element_identifier');
$sDashboardFile = utils::ReadParam('file', '', false, 'string'); $sDashboardFile = utils::ReadParam('file', '', false, 'string');
$sReloadURL = utils::ReadParam('reload_url', '', false, 'raw_data'); $sReloadURL = utils::ReadParam('reload_url', '', false, 'url');
$oDashboard = RuntimeDashboard::GetDashboardToEdit($sDashboardFile, $sId); $oDashboard = RuntimeDashboard::GetDashboardToEdit($sDashboardFile, $sId);
if (!is_null($oDashboard)) { if (!is_null($oDashboard)) {
if (!empty($sReloadURL)) { if (!empty($sReloadURL)) {

View File

@@ -237,6 +237,11 @@ try {
throw new CoreException(Dict::S('UI:ActionNotAllowed')); throw new CoreException(Dict::S('UI:ActionNotAllowed'));
} }
// CSRF transaction id verification
if(!$bSimulate && !utils::IsTransactionValid(utils::ReadPostedParam('transaction_id', '', 'raw_data'))){
throw new CoreException(Dict::S('UI:Error:InvalidToken'));
}
$aResult = array(); $aResult = array();
$sCSVData = utils::ReadParam('csvdata', '', false, 'raw_data'); $sCSVData = utils::ReadParam('csvdata', '', false, 'raw_data');
$sCSVDataTruncated = utils::ReadParam('csvdata_truncated', '', false, 'raw_data'); $sCSVDataTruncated = utils::ReadParam('csvdata_truncated', '', false, 'raw_data');
@@ -523,6 +528,7 @@ try {
$oForm = FormUIBlockFactory::MakeStandard('wizForm'); $oForm = FormUIBlockFactory::MakeStandard('wizForm');
$oContainer->AddSubBlock($oForm); $oContainer->AddSubBlock($oForm);
$oForm->AddSubBlock(InputUIBlockFactory::MakeForHidden("transaction_id", utils::GetNewTransactionId()));
$oForm->AddSubBlock(InputUIBlockFactory::MakeForHidden("step", ($iCurrentStep + 1))); $oForm->AddSubBlock(InputUIBlockFactory::MakeForHidden("step", ($iCurrentStep + 1)));
$oForm->AddSubBlock(InputUIBlockFactory::MakeForHidden("separator", htmlentities($sSeparator, ENT_QUOTES, 'UTF-8'))); $oForm->AddSubBlock(InputUIBlockFactory::MakeForHidden("separator", htmlentities($sSeparator, ENT_QUOTES, 'UTF-8')));
$oForm->AddSubBlock(InputUIBlockFactory::MakeForHidden("text_qualifier", htmlentities($sTextQualifier, ENT_QUOTES, 'UTF-8'))); $oForm->AddSubBlock(InputUIBlockFactory::MakeForHidden("text_qualifier", htmlentities($sTextQualifier, ENT_QUOTES, 'UTF-8')));
@@ -682,7 +688,7 @@ EOF
// Add graphs dependencies // Add graphs dependencies
WebResourcesHelper::EnableC3JSToWebPage($oPage); WebResourcesHelper::EnableC3JSToWebPage($oPage);
$oPage->add_script( $oPage->add_script(
<<< EOF <<< EOF
function CSVGoBack() function CSVGoBack()
{ {
@@ -1179,7 +1185,7 @@ EOF
} }
$aGuesses = GuessParameters($sUTF8Data); // Try to predict the parameters, based on the input data $aGuesses = GuessParameters($sUTF8Data); // Try to predict the parameters, based on the input data
$iSkippedLines = utils::ReadParam('nb_skipped_lines', ''); $iSkippedLines = utils::ReadParam('nb_skipped_lines', '');
$bBoxSkipLines = utils::ReadParam('box_skiplines', 0); $bBoxSkipLines = utils::ReadParam('box_skiplines', 0);
$sTextQualifier = utils::ReadParam('text_qualifier', '', false, 'raw_data'); $sTextQualifier = utils::ReadParam('text_qualifier', '', false, 'raw_data');

View File

@@ -44,12 +44,8 @@
<testsuite name="Application"> <testsuite name="Application">
<directory>application</directory> <directory>application</directory>
</testsuite> </testsuite>
<!-- OQL : taking too long (20min+)... we should move this to nightlies ! See N°4655 --> <testsuite name="Setup">
<!--testsuite name="OQL"> <directory>setup</directory>
<directory>OQL</directory>
</testsuite-->
<testsuite name="Sources">
<directory>sources</directory>
</testsuite> </testsuite>
<testsuite name="Status"> <testsuite name="Status">
<directory>status</directory> <directory>status</directory>

View File

@@ -0,0 +1,42 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/8.5/phpunit.xsd"
bootstrap="unittestautoload.php"
backupGlobals="true"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnError="false"
stopOnFailure="false"
stopOnIncomplete="false"
stopOnRisky="false"
stopOnSkipped="false"
verbose="true"
>
<php>
<ini name="error_reporting" value="E_ALL"/>
<ini name="display_errors" value="On"/>
<ini name="log_errors" value="On"/>
<ini name="html_errors" value="On"/>
</php>
<testsuites>
<testsuite name="OQL">
<directory>OQL</directory>
</testsuite>
</testsuites>
<!-- Code coverage white list -->
<filter>
<whitelist>
<file>../core/apc-emulation.php</file>
<file>../core/ormlinkset.class.inc.php</file>
<file>../datamodels/2.x/itop-tickets/main.itop-tickets.php</file>
</whitelist>
</filter>
</phpunit>