Skip to content

Commit

Permalink
multiple ruleright fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
cconard96 committed Jan 7, 2024
1 parent c04505d commit eb25c2f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 19 deletions.
11 changes: 8 additions & 3 deletions src/RuleCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class RuleCollection extends CommonDBTM
public $use_output_rule_process_as_next_input = false;
/// Rule collection can be replay (for dictionary)
public $can_replay_rules = false;
/// List of rules of the rule collection
/** @var SingletonRuleList $RuleList List of rules of the rule collection */
public $RuleList = null;
/// Menu type
public $menu_type = "rule";
Expand Down Expand Up @@ -1694,14 +1694,15 @@ public function showRulesEnginePreviewCriteriasForm($target, array $values, $con
$input = $this->prepareInputDataForTestProcess($condition);

if (count($input)) {
/** @var Rule $rule */
$rule = $this->getRuleClass();
$criterias = $rule->getAllCriteria();
echo "<form name='testrule_form' id='testrulesengine_form' method='post' action='$target'>";
echo "\n<div class='center'>";
echo "<table class='tab_cadre_fixe'>";
echo "<tr><th colspan='2'>" . _n('Criterion', 'Criteria', Session::getPluralNumber()) . "</th></tr>\n";

//Brower all criterias
//Brower all criterias
foreach ($input as $criteria) {
echo "<tr class='tab_bg_1'>";

Expand Down Expand Up @@ -1953,7 +1954,11 @@ public function showRulesEnginePreviewResultsForm($target, array $input, $condit

$output = $this->cleanTestOutputCriterias($output);
unset($output["result"]);
$global_result = (count($output) ? 1 : 0);
if (count($output) === 1 && ($output['_no_rule_matches'] ?? false)) {
$global_result = 0;
} else {
$global_result = (count($output) ? 1 : 0);
}

echo "<br><table class='tab_cadrehov'>";
$this->showTestResults($rule, $output, $global_result);
Expand Down
26 changes: 11 additions & 15 deletions src/RuleRightCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,10 @@ public function showTestResults($rule, array $output, $global_result)
if (isset($output["_ldap_rules"]["rules_entities"])) {
echo "<tr class='tab_bg_2'>";
echo "<td class='center' colspan='4'>" . __('Entities assignment') . "</td>";
foreach ($output["_ldap_rules"]["rules_entities"] as $entities) {
foreach ($entities as $entity) {
$this->displayActionByName("entity", $entity[0]);
if (isset($entity[1])) {
$this->displayActionByName("recursive", $entity[1]);
}
foreach ($output["_ldap_rules"]["rules_entities"] as $entity) {
$this->displayActionByName("entity", $entity[0]);
if (isset($entity[1])) {
$this->displayActionByName("recursive", $entity[1]);
}
}
}
Expand Down Expand Up @@ -232,23 +230,21 @@ public function prepareInputDataForProcess($input, $params)
$params_lower = array_change_key_case($params, CASE_LOWER);

//common parameters
$rule_parameters = [
$rule_parameters = array_merge($params_lower, [
'TYPE' => $params_lower["type"] ?? "",
'LOGIN' => $params_lower["login"] ?? "",
'MAIL_EMAIL' => $params_lower["email"] ?? $params_lower["mail_email"] ?? "",
'_groups_id' => $groups
];
]);

//IMAP/POP login method
if ($params_lower["type"] == Auth::MAIL) {
if ($rule_parameters["TYPE"] == Auth::MAIL) {
$rule_parameters["MAIL_SERVER"] = $params_lower["mail_server"] ?? "";
}

//LDAP type method
if ($params_lower["type"] == Auth::LDAP) {
//Get all the field to retrieve to be able to process rule matching
$rule_fields = $this->getFieldsToLookFor();

//LDAP type method
//Get all the field to retrieve to be able to process rule matching
$rule_fields = $this->getFieldsToLookFor();
if ($rule_parameters["TYPE"] == Auth::LDAP && count($rule_fields)) {
//Get all the data we need from ldap to process the rules
$sz = @ldap_read(
$params_lower["connection"],
Expand Down
2 changes: 1 addition & 1 deletion src/SingletonRuleList.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

class SingletonRuleList
{
/// Items list
/** @var Rule[] $list Rule list */
public $list = [];
/// Items loaded ?
public $load = 0;
Expand Down

0 comments on commit eb25c2f

Please sign in to comment.