mirror of
https://github.com/Combodo/iTop.git
synced 2026-08-22 14:18:18 +02:00
N°9861 - Check user can go to audit step only when keep current choice button has been clicked (#1013)
* N°9861 - Check user can go to audit step only when keep current choice button has been clicked * Rename variable to improve clarity
This commit is contained in:
@@ -57,9 +57,9 @@ class WizardController
|
||||
|
||||
/**
|
||||
* Removes information about the previous step from the stack
|
||||
* @return array{'class': string, 'state': string}
|
||||
* @return null|array{'class': string, 'state': string}
|
||||
*/
|
||||
public function PopStep(): array
|
||||
public function PopStep(): ?array
|
||||
{
|
||||
$aStep = array_pop($this->aWizardSteps);
|
||||
$this->SetParameter('_steps', $this->aWizardSteps);
|
||||
@@ -343,11 +343,8 @@ EOF
|
||||
*/
|
||||
public function GetLatestWizardStateFromStepClass(string $sStepClass): WizardState
|
||||
{
|
||||
$iCountModulesChoiceSteps = count(array_filter($this->aWizardSteps, fn (array $step): bool => $step['class'] === $sStepClass && $step['state'] !== ''));
|
||||
$sStepState = $iCountModulesChoiceSteps > 0 ? (string) ($iCountModulesChoiceSteps - 1) : '';
|
||||
|
||||
// Pop the latest step from the stack, since we are going back to it
|
||||
$this->PopStep();
|
||||
$iStepStateOccurrences = count(array_filter($this->aWizardSteps, fn (array $step): bool => $step['class'] === $sStepClass && $step['state'] !== ''));
|
||||
$sStepState = $iStepStateOccurrences > 0 ? (string) ($iStepStateOccurrences - 1) : '';
|
||||
|
||||
return new WizardState($sStepClass, $sStepState);
|
||||
}
|
||||
|
||||
@@ -82,15 +82,19 @@ class WizStepLandingBeforeAudit extends WizStepModulesChoice
|
||||
}
|
||||
|
||||
$bForceUninstall = (bool)$this->oWizard->GetParameter('force-uninstall', false);
|
||||
if (!$bForceUninstall) {
|
||||
if ($bSkipWizard && !$bForceUninstall) {
|
||||
// Check if the current choices allow going to the data audit step
|
||||
$aOptions = $this->oExtensionsMap->GetAllExtensionsOptionInfo();
|
||||
foreach ($aOptions as $index => $aChoice) {
|
||||
$sChoiceId = self::$SEP.$index;
|
||||
$aFlags = $this->ComputeChoiceFlags($aChoice, $sChoiceId, $aSelectedComponents, false, false, true);
|
||||
$oLatestWizardState = $this->oWizard->GetLatestWizardStateFromStepClass(WizStepModulesChoice::class);
|
||||
$aFlags = $this->ComputeChoiceFlags($aChoice, $sChoiceId, $aSelectedComponents[$oLatestWizardState->GetState()], false, false);
|
||||
if (!$this->CanMoveForwardFromChoiceFlags($aFlags)) {
|
||||
// Pop the latest step from the stack, since we are going back to it
|
||||
$this->oWizard->PopStep();
|
||||
|
||||
// If the user has selected incompatible modules, we need to go back to the extension choices step, which is the last module choices step in the wizard
|
||||
return $this->oWizard->GetLatestWizardStateFromStepClass(WizStepModulesChoice::class);
|
||||
return $oLatestWizardState;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1715,13 +1715,9 @@ HTML,
|
||||
['class' => 'WizStepModulesChoice', 'state' => '4'],
|
||||
['class' => 'WizStepModulesChoice', 'state' => '5'],
|
||||
];
|
||||
$this->oWizard->SetParameter('_steps', $aSteps);
|
||||
$this->oWizard->SetWizardSteps($aSteps);
|
||||
|
||||
$oWizardState = $this->oWizard->GetLatestWizardStateFromStepClass($sStepClass);
|
||||
$this->assertEquals(new WizardState($sStepClass, $sExpectedState), $oWizardState);
|
||||
|
||||
$aNewSteps = $this->oWizard->GetParameter('_steps', []);
|
||||
$this->assertCount(count($aSteps) - 1, $aNewSteps);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user