Skip to content

Commit 02084ad

Browse files
committed
Drop unused legacy addVisibilityRestrict methods
Those methods should have been removed since v11.0; no idea why they've been kept
1 parent aee8abb commit 02084ad

5 files changed

Lines changed: 2 additions & 165 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,8 @@ The present file will list all changes made to the project; according to the
123123
- `Toolbox::seems_utf8()`
124124
- `Toolbox::sendFile()`
125125
- `Toolbox::stripslashes_deep()`
126-
126+
- `Reminder::addVisibilityRestrict()`
127+
- `SavedSearch::addVisibilityRestrict()`
127128

128129
## [11.0.7] unreleased
129130

src/Reminder.php

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -185,28 +185,6 @@ public function haveVisibilityAccess()
185185
return parent::haveVisibilityAccess();
186186
}
187187

188-
/**
189-
* Return visibility SQL restriction to add
190-
*
191-
* @return string restrict to add
192-
**/
193-
public static function addVisibilityRestrict()
194-
{
195-
//not deprecated because used in Search
196-
197-
//get and clean criteria
198-
$criteria = self::getVisibilityCriteria();
199-
unset($criteria['LEFT JOIN']);
200-
$criteria['FROM'] = self::getTable();
201-
202-
$it = new DBmysqlIterator(null);
203-
$it->buildQuery($criteria);
204-
$sql = $it->getSql();
205-
$sql = preg_replace('/.*WHERE /', '', $sql);
206-
207-
return $sql;
208-
}
209-
210188
/**
211189
* Return visibility joins to add to DBIterator parameters
212190
*

src/SavedSearch.php

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1176,31 +1176,6 @@ public function createNotif()
11761176
}
11771177
}
11781178

1179-
/**
1180-
* Return visibility SQL restriction to add
1181-
*
1182-
* @return string restrict to add
1183-
**/
1184-
public static function addVisibilityRestrict()
1185-
{
1186-
//not deprecated because used in Search
1187-
if (Session::haveRight('config', UPDATE)) {
1188-
return '';
1189-
}
1190-
1191-
//get and clean criteria
1192-
$criteria = self::getVisibilityCriteria();
1193-
unset($criteria['LEFT JOIN']);
1194-
$criteria['FROM'] = self::getTable();
1195-
1196-
$it = new DBmysqlIterator(null);
1197-
$it->buildQuery($criteria);
1198-
$sql = $it->getSql();
1199-
$sql = preg_replace('/.*WHERE /', '', $sql);
1200-
1201-
return $sql;
1202-
}
1203-
12041179
private static function getVisibilityCriteriaForMine(): array
12051180
{
12061181
$criteria = ['WHERE' => []];

tests/functional/ReminderTest.php

Lines changed: 0 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -40,79 +40,6 @@
4040

4141
class ReminderTest extends DbTestCase
4242
{
43-
public function testAddVisibilityRestrict()
44-
{
45-
$e2e_root = getItemByTypeName('Entity', 'E2ETestEntity', true);
46-
$e2e_test_child1 = getItemByTypeName('Entity', 'E2ETestSubEntity1', true);
47-
$e2e_test_child2 = getItemByTypeName('Entity', 'E2ETestSubEntity2', true);
48-
$test_root = getItemByTypeName('Entity', '_test_root_entity', true);
49-
$test_child_1 = getItemByTypeName('Entity', '_test_child_1', true);
50-
$test_child_2 = getItemByTypeName('Entity', '_test_child_2', true);
51-
$test_child_3 = getItemByTypeName('Entity', '_test_child_3', true);
52-
53-
$all_entities = "'0', '$test_root', '$e2e_root', '$e2e_test_child1', '$e2e_test_child2', '$test_child_1', '$test_child_2', '$test_child_3'";
54-
55-
//first, as a super-admin
56-
$this->login();
57-
$users_id = \Session::getLoginUserID();
58-
$expected = preg_replace('/\s+/', ' ', "(`glpi_reminders`.`users_id` = '$users_id'
59-
OR `glpi_reminders_users`.`users_id` = '$users_id'
60-
OR (`glpi_profiles_reminders`.`profiles_id` = '4'
61-
AND (`glpi_profiles_reminders`.`no_entity_restriction` = '1'
62-
OR ((`glpi_profiles_reminders`.`entities_id` IN ('$test_root', '$test_child_1', '$test_child_2', '$test_child_3')
63-
OR (`glpi_profiles_reminders`.`is_recursive` = '1'
64-
AND `glpi_profiles_reminders`.`entities_id` IN ('0'))))))
65-
OR ((`glpi_entities_reminders`.`entities_id` IN ('$test_root', '$test_child_1', '$test_child_2', '$test_child_3')
66-
OR (`glpi_entities_reminders`.`is_recursive` = '1'
67-
AND `glpi_entities_reminders`.`entities_id` IN ('0')))))");
68-
$this->assertSame(
69-
$expected,
70-
\Reminder::addVisibilityRestrict()
71-
);
72-
73-
$this->login('normal', 'normal');
74-
$expected = preg_replace('/\s+/', ' ', "(`glpi_reminders`.`users_id` = '5'
75-
OR `glpi_reminders_users`.`users_id` = '5'
76-
OR (`glpi_profiles_reminders`.`profiles_id` = '2'
77-
AND (`glpi_profiles_reminders`.`no_entity_restriction` = '1'
78-
OR (`glpi_profiles_reminders`.`entities_id` IN ($all_entities))))
79-
OR (`glpi_entities_reminders`.`entities_id` IN ($all_entities)))");
80-
$this->assertSame(
81-
$expected,
82-
trim(preg_replace('/\s+/', ' ', \Reminder::addVisibilityRestrict()))
83-
);
84-
85-
$this->login('tech', 'tech');
86-
$expected = preg_replace('/\s+/', ' ', "(`glpi_reminders`.`users_id` = '4'
87-
OR `glpi_reminders_users`.`users_id` = '4'
88-
OR (`glpi_profiles_reminders`.`profiles_id` = '6'
89-
AND (`glpi_profiles_reminders`.`no_entity_restriction` = '1'
90-
OR (`glpi_profiles_reminders`.`entities_id` IN ($all_entities))))
91-
OR (`glpi_entities_reminders`.`entities_id` IN ($all_entities)))");
92-
$this->assertSame(
93-
$expected,
94-
trim(preg_replace('/\s+/', ' ', \Reminder::addVisibilityRestrict()))
95-
);
96-
97-
$bkp_groups = $_SESSION['glpigroups'];
98-
$_SESSION['glpigroups'] = [42, 1337];
99-
$str = \Reminder::addVisibilityRestrict();
100-
$_SESSION['glpigroups'] = $bkp_groups;
101-
$expected = preg_replace('/\s+/', ' ', "(`glpi_reminders`.`users_id` = '4'
102-
OR `glpi_reminders_users`.`users_id` = '4'
103-
OR (`glpi_groups_reminders`.`groups_id` IN ('42', '1337')
104-
AND (`glpi_groups_reminders`.`no_entity_restriction` = '1'
105-
OR (`glpi_groups_reminders`.`entities_id` IN ($all_entities))))
106-
OR (`glpi_profiles_reminders`.`profiles_id` = '6'
107-
AND (`glpi_profiles_reminders`.`no_entity_restriction` = '1'
108-
OR (`glpi_profiles_reminders`.`entities_id` IN ($all_entities))))
109-
OR (`glpi_entities_reminders`.`entities_id` IN ($all_entities)))");
110-
$this->assertSame(
111-
$expected,
112-
trim(preg_replace('/\s+/', ' ', $str))
113-
);
114-
}
115-
11643
public function testGetListCriteriaIsValid(): void
11744
{
11845
global $DB;

tests/functional/SavedSearchTest.php

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -56,50 +56,6 @@ public function testGetVisibilityCriteria()
5656
$this->assertNotEmpty(SavedSearch::getVisibilityCriteria()['WHERE']);
5757
}
5858

59-
public function testAddVisibilityRestrict()
60-
{
61-
$test_root = getItemByTypeName('Entity', '_test_root_entity', true);
62-
$test_child_1 = getItemByTypeName('Entity', '_test_child_1', true);
63-
$test_child_2 = getItemByTypeName('Entity', '_test_child_2', true);
64-
$test_child_3 = getItemByTypeName('Entity', '_test_child_3', true);
65-
66-
//first, as a super-admin
67-
$this->login();
68-
$this->assertSame('', SavedSearch::addVisibilityRestrict());
69-
70-
$this->login('normal', 'normal');
71-
$this->assertSame(
72-
"`glpi_savedsearches`.`is_private` = '1' AND `glpi_savedsearches`.`users_id` = '5' AND (true)",
73-
SavedSearch::addVisibilityRestrict()
74-
);
75-
76-
//add public saved searches read right for normal profile
77-
global $DB;
78-
$DB->update(
79-
'glpi_profilerights',
80-
['rights' => 1],
81-
[
82-
'profiles_id' => 2,
83-
'name' => 'bookmark_public',
84-
]
85-
);
86-
87-
//ACLs have changed: login again.
88-
$this->login('normal', 'normal');
89-
90-
$this->assertSame(
91-
"((`glpi_savedsearches`.`is_private` = '1' AND `glpi_savedsearches`.`users_id` = '5') OR (`glpi_savedsearches`.`is_private` = '0')) AND (true)",
92-
SavedSearch::addVisibilityRestrict()
93-
);
94-
95-
// Check entity restriction
96-
$this->setEntity('_test_root_entity', true);
97-
$this->assertSame(
98-
"((`glpi_savedsearches`.`is_private` = '1' AND `glpi_savedsearches`.`users_id` = '5') OR (`glpi_savedsearches`.`is_private` = '0')) AND ((`glpi_savedsearches`.`entities_id` IN ('$test_root', '$test_child_1', '$test_child_2', '$test_child_3') OR (`glpi_savedsearches`.`is_recursive` = '1' AND `glpi_savedsearches`.`entities_id` IN ('0'))))",
99-
SavedSearch::addVisibilityRestrict()
100-
);
101-
}
102-
10359
public function testGetMine()
10460
{
10561
global $DB;

0 commit comments

Comments
 (0)