Skip to content

Commit

Permalink
fix(reminder): not visible on root entity with tree structure
Browse files Browse the repository at this point in the history
fixed #13650
  • Loading branch information
Rom1-B authored Feb 6, 2024
1 parent 6ce9539 commit 9a2c475
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 28 deletions.
14 changes: 12 additions & 2 deletions src/Reminder.php
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,12 @@ public static function getVisibilityCriteria(bool $forceall = false): array
];

$or = ['glpi_groups_reminders.no_entity_restriction' => 1];
$restrict = getEntitiesRestrictCriteria('glpi_groups_reminders', '', '', true);
$restrict = getEntitiesRestrictCriteria(
'glpi_groups_reminders',
'',
$_SESSION['glpiactiveentities'],
true
);
if (count($restrict)) {
$or = $or + $restrict;
}
Expand All @@ -338,7 +343,12 @@ public static function getVisibilityCriteria(bool $forceall = false): array
];

$or = ['glpi_profiles_reminders.no_entity_restriction' => 1];
$restrict = getEntitiesRestrictCriteria('glpi_profiles_reminders', '', '', true);
$restrict = getEntitiesRestrictCriteria(
'glpi_profiles_reminders',
'',
$_SESSION['glpiactiveentities'],
true
);
if (count($restrict)) {
$or = $or + $restrict;
}
Expand Down
73 changes: 47 additions & 26 deletions tests/functional/Reminder.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,34 +43,55 @@ class Reminder extends DbTestCase
{
public function testAddVisibilityRestrict()
{
//first, as a super-admin
$this->login();
$expected = "(`glpi_reminders`.`users_id` = '7' OR `glpi_reminders_users`.`users_id` = '7' OR (`glpi_profiles_reminders`.`profiles_id` = '4' AND (`glpi_profiles_reminders`.`no_entity_restriction` = '1' OR ((`glpi_profiles_reminders`.`entities_id` IN ('1', '2', '3') OR (`glpi_profiles_reminders`.`is_recursive` = '1' AND `glpi_profiles_reminders`.`entities_id` IN ('0')))))) OR ((`glpi_entities_reminders`.`entities_id` IN ('1', '2', '3') OR (`glpi_entities_reminders`.`is_recursive` = '1' AND `glpi_entities_reminders`.`entities_id` IN ('0')))))";
$this->string(\Reminder::addVisibilityRestrict())
->isIdenticalTo($expected);
//first, as a super-admin
$this->login();
$expected = preg_replace('/\s+/', ' ', "(`glpi_reminders`.`users_id` = '7'
OR `glpi_reminders_users`.`users_id` = '7'
OR (`glpi_profiles_reminders`.`profiles_id` = '4'
AND (`glpi_profiles_reminders`.`no_entity_restriction` = '1'
OR ((`glpi_profiles_reminders`.`entities_id` IN ('1', '2', '3')
OR (`glpi_profiles_reminders`.`is_recursive` = '1'
AND `glpi_profiles_reminders`.`entities_id` IN ('0'))))))
OR ((`glpi_entities_reminders`.`entities_id` IN ('1', '2', '3')
OR (`glpi_entities_reminders`.`is_recursive` = '1'
AND `glpi_entities_reminders`.`entities_id` IN ('0')))))");
$this->string(\Reminder::addVisibilityRestrict())
->isIdenticalTo($expected);

$this->login('normal', 'normal');
$this->string(trim(preg_replace('/\s+/', ' ', \Reminder::addVisibilityRestrict())))
->isIdenticalTo("(`glpi_reminders`.`users_id` = '5' OR `glpi_reminders_users`.`users_id` = '5' OR (`glpi_profiles_reminders`.`profiles_id` = '2' AND (`glpi_profiles_reminders`.`no_entity_restriction` = '1')) OR (`glpi_entities_reminders`.`entities_id` IN ('0', '1', '2', '3')))");
$this->login('normal', 'normal');
$expected = preg_replace('/\s+/', ' ', "(`glpi_reminders`.`users_id` = '5'
OR `glpi_reminders_users`.`users_id` = '5'
OR (`glpi_profiles_reminders`.`profiles_id` = '2'
AND (`glpi_profiles_reminders`.`no_entity_restriction` = '1'
OR (`glpi_profiles_reminders`.`entities_id` IN ('0', '1', '2', '3'))))
OR (`glpi_entities_reminders`.`entities_id` IN ('0', '1', '2', '3')))");
$this->string(trim(preg_replace('/\s+/', ' ', \Reminder::addVisibilityRestrict())))
->isIdenticalTo($expected);

$this->login('tech', 'tech');
$this->string(trim(preg_replace('/\s+/', ' ', \Reminder::addVisibilityRestrict())))
->isIdenticalTo(preg_replace('/\s+/', ' ', "(`glpi_reminders`.`users_id` = '4' OR `glpi_reminders_users`.`users_id` = '4' OR (`glpi_profiles_reminders`.`profiles_id`
= '6'
AND (`glpi_profiles_reminders`.`no_entity_restriction` = '1'))
OR (`glpi_entities_reminders`.`entities_id` IN ('0', '1', '2', '3')))"));
$this->login('tech', 'tech');
$expected = preg_replace('/\s+/', ' ', "(`glpi_reminders`.`users_id` = '4'
OR `glpi_reminders_users`.`users_id` = '4'
OR (`glpi_profiles_reminders`.`profiles_id` = '6'
AND (`glpi_profiles_reminders`.`no_entity_restriction` = '1'
OR (`glpi_profiles_reminders`.`entities_id` IN ('0', '1', '2', '3'))))
OR (`glpi_entities_reminders`.`entities_id` IN ('0', '1', '2', '3')))");
$this->string(trim(preg_replace('/\s+/', ' ', \Reminder::addVisibilityRestrict())))
->isIdenticalTo($expected);

$bkp_groups = $_SESSION['glpigroups'];
$_SESSION['glpigroups'] = [42, 1337];
$str = \Reminder::addVisibilityRestrict();
$_SESSION['glpigroups'] = $bkp_groups;
$this->string(trim(preg_replace('/\s+/', ' ', $str)))
->isIdenticalTo(preg_replace('/\s+/', ' ', "(`glpi_reminders`.`users_id` = '4' OR `glpi_reminders_users`.`users_id` = '4' OR (`glpi_groups_reminders`.`groups_id`
IN ('42', '1337')
AND (`glpi_groups_reminders`.`no_entity_restriction` = '1'))
OR (`glpi_profiles_reminders`.`profiles_id`
= '6'
AND (`glpi_profiles_reminders`.`no_entity_restriction` = '1'))
OR (`glpi_entities_reminders`.`entities_id` IN ('0', '1', '2', '3')))"));
$bkp_groups = $_SESSION['glpigroups'];
$_SESSION['glpigroups'] = [42, 1337];
$str = \Reminder::addVisibilityRestrict();
$_SESSION['glpigroups'] = $bkp_groups;
$expected = preg_replace('/\s+/', ' ', "(`glpi_reminders`.`users_id` = '4'
OR `glpi_reminders_users`.`users_id` = '4'
OR (`glpi_groups_reminders`.`groups_id` IN ('42', '1337')
AND (`glpi_groups_reminders`.`no_entity_restriction` = '1'
OR (`glpi_groups_reminders`.`entities_id` IN ('0', '1', '2', '3'))))
OR (`glpi_profiles_reminders`.`profiles_id` = '6'
AND (`glpi_profiles_reminders`.`no_entity_restriction` = '1'
OR (`glpi_profiles_reminders`.`entities_id` IN ('0', '1', '2', '3'))))
OR (`glpi_entities_reminders`.`entities_id` IN ('0', '1', '2', '3')))");
$this->string(trim(preg_replace('/\s+/', ' ', $str)))
->isIdenticalTo($expected);
}
}

0 comments on commit 9a2c475

Please sign in to comment.