Skip to content

Commit 02cf893

Browse files
ArthurMinfotelcedric-anne
authored andcommitted
Feature : targeted private saved searches
1 parent b145dcb commit 02cf893

23 files changed

+1167
-194
lines changed

ajax/subvisibility.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@
5353
if (Session::canViewAllEntities()) {
5454
$params['toadd'] = [-1 => __('No restriction')];
5555
}
56+
if (isset($_POST['entity']) && $_POST['entity'] >= 0) {
57+
$params['entity'] = $_POST['entity'];
58+
$params['entity_sons'] = $_POST['is_recursive'] ?? false;
59+
}
5660
echo "<table class='tab_format'><tr><td>";
5761
echo htmlescape(Entity::getTypeName(1));
5862
echo "</td><td>";

ajax/visibility.php

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,7 @@
4343

4444
Session::checkCentralAccess();
4545

46-
if (
47-
isset($_POST['type']) && !empty($_POST['type'])
48-
&& isset($_POST['right'])
49-
) {
46+
if (isset($_POST['type']) && !empty($_POST['type'])) {
5047
$display = false;
5148
$rand = mt_rand();
5249
$prefix = '';
@@ -61,10 +58,16 @@
6158
echo "<div class='d-flex'>";
6259
switch ($_POST['type']) {
6360
case 'User':
64-
$params = [
65-
'right' => isset($_POST['allusers']) ? 'all' : $_POST['right'],
66-
'name' => $prefix . 'users_id' . $suffix
67-
];
61+
$params = ['name' => $prefix . 'users_id' . $suffix];
62+
if (isset($_POST['right'])) {
63+
$params['right'] = isset($_POST['allusers']) ? 'all' : $_POST['right'];
64+
} else {
65+
$params['right'] = 'all';
66+
}
67+
if (isset($_POST['entity']) && $_POST['entity'] >= 0) {
68+
$params['entity'] = $_POST['entity'];
69+
$params['entity_sons'] = $_POST['is_recursive'] ?? false;
70+
}
6871
User::dropdown($params);
6972
$display = true;
7073
break;
@@ -82,6 +85,12 @@
8285
'prefix' => $_POST['prefix']
8386
]
8487
];
88+
if (isset($_POST['entity']) && $_POST['entity'] >= 0) {
89+
$params['entity'] = $_POST['entity'];
90+
$params['toupdate']['moreparams']['entity'] = $_POST['entity'];
91+
$params['entity_sons'] = $_POST['is_recursive'] ?? false;
92+
$params['toupdate']['moreparams']['entity_sons'] = $_POST['is_recursive'] ?? false;
93+
}
8594

8695
Group::dropdown($params);
8796
echo "<span id='subvisibility$rand'></span>";

front/savedsearch.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,13 @@
4545
isset($_GET['action']) && $_GET["action"] == "load"
4646
&& isset($_GET["id"]) && ($_GET["id"] > 0)
4747
) {
48-
$savedsearch->check($_GET["id"], READ);
49-
$savedsearch->load($_GET["id"]);
48+
$savedsearch->getFromDB($_GET['ID']);
49+
if ($savedsearch->canViewItem()) {
50+
$savedsearch->load($_GET["id"]);
51+
} else {
52+
$info = "User can not access the SavedSearch " . $_GET['id'];
53+
throw new \Glpi\Exception\Http\AccessDeniedHttpException($info);
54+
}
5055
return;
5156
}
5257

inc/relation.constant.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,7 @@
589589
'_glpi_entities_knowbaseitems' => 'entities_id',
590590
'_glpi_entities_reminders' => 'entities_id',
591591
'_glpi_entities_rssfeeds' => 'entities_id',
592+
'_glpi_entities_savedsearches' => 'entities_id',
592593
'glpi_fieldblacklists' => 'entities_id',
593594
'glpi_fieldunicities' => 'entities_id',
594595
'glpi_forms_forms' => 'entities_id',
@@ -598,6 +599,7 @@
598599
'glpi_groups_knowbaseitems' => 'entities_id',
599600
'glpi_groups_reminders' => 'entities_id',
600601
'glpi_groups_rssfeeds' => 'entities_id',
602+
'glpi_groups_savedsearches' => 'entities_id',
601603
'glpi_holidays' => 'entities_id',
602604
'glpi_imageformats' => 'entities_id',
603605
'glpi_imageresolutions' => 'entities_id',
@@ -739,6 +741,7 @@
739741
'_glpi_groups_problems' => 'groups_id',
740742
'_glpi_groups_reminders' => 'groups_id',
741743
'_glpi_groups_rssfeeds' => 'groups_id',
744+
'_glpi_groups_savedsearches' => 'groups_id',
742745
'_glpi_groups_tickets' => 'groups_id',
743746
'_glpi_groups_users' => 'groups_id',
744747
'glpi_itilcategories' => 'groups_id',
@@ -1263,8 +1266,11 @@
12631266
],
12641267

12651268
'glpi_savedsearches' => [
1266-
'_glpi_savedsearches_alerts' => 'savedsearches_id',
1267-
'_glpi_savedsearches_users' => 'savedsearches_id',
1269+
'_glpi_entities_savedsearches' => 'savedsearches_id',
1270+
'_glpi_groups_savedsearches' => 'savedsearches_id',
1271+
'_glpi_savedsearches_alerts' => 'savedsearches_id',
1272+
'_glpi_savedsearches_users' => 'savedsearches_id',
1273+
'_glpi_savedsearches_usertargets' => 'savedsearches_id',
12681274
],
12691275

12701276
'glpi_slalevels' => [
@@ -1625,6 +1631,7 @@
16251631
'_glpi_rssfeeds_users' => 'users_id',
16261632
'_glpi_savedsearches' => 'users_id',
16271633
'_glpi_savedsearches_users' => 'users_id',
1634+
'_glpi_savedsearches_usertargets' => 'users_id',
16281635
'glpi_softwarelicenses' => [
16291636
'users_id_tech',
16301637
'users_id',
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?php
2+
3+
/**
4+
* ---------------------------------------------------------------------
5+
*
6+
* GLPI - Gestionnaire Libre de Parc Informatique
7+
*
8+
* http://glpi-project.org
9+
*
10+
* @copyright 2015-2025 Teclib' and contributors.
11+
* @copyright 2003-2014 by the INDEPNET Development Team.
12+
* @licence https://www.gnu.org/licenses/gpl-3.0.html
13+
*
14+
* ---------------------------------------------------------------------
15+
*
16+
* LICENSE
17+
*
18+
* This file is part of GLPI.
19+
*
20+
* This program is free software: you can redistribute it and/or modify
21+
* it under the terms of the GNU General Public License as published by
22+
* the Free Software Foundation, either version 3 of the License, or
23+
* (at your option) any later version.
24+
*
25+
* This program is distributed in the hope that it will be useful,
26+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
27+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28+
* GNU General Public License for more details.
29+
*
30+
* You should have received a copy of the GNU General Public License
31+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
32+
*
33+
* ---------------------------------------------------------------------
34+
*/
35+
36+
/**
37+
* @var \DBmysql $DB
38+
* @var \Migration $migration
39+
*/
40+
41+
$default_charset = DBConnection::getDefaultCharset();
42+
$default_collation = DBConnection::getDefaultCollation();
43+
$default_key_sign = DBConnection::getDefaultPrimaryKeySignOption();
44+
45+
if (!$DB->tableExists('glpi_entities_savedsearches')) {
46+
$query = "CREATE TABLE `glpi_entities_savedsearches` (
47+
`id` int {$default_key_sign} NOT NULL AUTO_INCREMENT,
48+
`savedsearches_id` int {$default_key_sign} NOT NULL DEFAULT '0',
49+
`entities_id` int {$default_key_sign} NOT NULL DEFAULT '0',
50+
`is_recursive` tinyint NOT NULL DEFAULT '0',
51+
PRIMARY KEY (`id`),
52+
KEY `savedsearches_id` (`savedsearches_id`),
53+
KEY `entities_id` (`entities_id`),
54+
KEY `is_recursive` (`is_recursive`)
55+
) ENGINE = InnoDB ROW_FORMAT = DYNAMIC DEFAULT CHARSET = {$default_charset} COLLATE = {$default_collation};";
56+
$DB->doQuery($query);
57+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?php
2+
3+
/**
4+
* ---------------------------------------------------------------------
5+
*
6+
* GLPI - Gestionnaire Libre de Parc Informatique
7+
*
8+
* http://glpi-project.org
9+
*
10+
* @copyright 2015-2025 Teclib' and contributors.
11+
* @copyright 2003-2014 by the INDEPNET Development Team.
12+
* @licence https://www.gnu.org/licenses/gpl-3.0.html
13+
*
14+
* ---------------------------------------------------------------------
15+
*
16+
* LICENSE
17+
*
18+
* This file is part of GLPI.
19+
*
20+
* This program is free software: you can redistribute it and/or modify
21+
* it under the terms of the GNU General Public License as published by
22+
* the Free Software Foundation, either version 3 of the License, or
23+
* (at your option) any later version.
24+
*
25+
* This program is distributed in the hope that it will be useful,
26+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
27+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28+
* GNU General Public License for more details.
29+
*
30+
* You should have received a copy of the GNU General Public License
31+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
32+
*
33+
* ---------------------------------------------------------------------
34+
*/
35+
36+
/**
37+
* @var \DBmysql $DB
38+
* @var \Migration $migration
39+
*/
40+
41+
$default_charset = DBConnection::getDefaultCharset();
42+
$default_collation = DBConnection::getDefaultCollation();
43+
$default_key_sign = DBConnection::getDefaultPrimaryKeySignOption();
44+
45+
if (!$DB->tableExists('glpi_groups_savedsearches')) {
46+
$query = "CREATE TABLE `glpi_groups_savedsearches` (
47+
`id` int {$default_key_sign} NOT NULL AUTO_INCREMENT,
48+
`savedsearches_id` int {$default_key_sign} NOT NULL DEFAULT '0',
49+
`groups_id` int {$default_key_sign} NOT NULL DEFAULT '0',
50+
`entities_id` int {$default_key_sign} DEFAULT NULL,
51+
`is_recursive` tinyint NOT NULL DEFAULT '0',
52+
`no_entity_restriction` tinyint NOT NULL DEFAULT '0',
53+
PRIMARY KEY (`id`),
54+
KEY `savedsearches_id` (`savedsearches_id`),
55+
KEY `groups_id` (`groups_id`),
56+
KEY `entities_id` (`entities_id`),
57+
KEY `is_recursive` (`is_recursive`)
58+
) ENGINE = InnoDB ROW_FORMAT = DYNAMIC DEFAULT CHARSET = {$default_charset} COLLATE = {$default_collation};";
59+
$DB->doQuery($query);
60+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
3+
/**
4+
* ---------------------------------------------------------------------
5+
*
6+
* GLPI - Gestionnaire Libre de Parc Informatique
7+
*
8+
* http://glpi-project.org
9+
*
10+
* @copyright 2015-2025 Teclib' and contributors.
11+
* @copyright 2003-2014 by the INDEPNET Development Team.
12+
* @licence https://www.gnu.org/licenses/gpl-3.0.html
13+
*
14+
* ---------------------------------------------------------------------
15+
*
16+
* LICENSE
17+
*
18+
* This file is part of GLPI.
19+
*
20+
* This program is free software: you can redistribute it and/or modify
21+
* it under the terms of the GNU General Public License as published by
22+
* the Free Software Foundation, either version 3 of the License, or
23+
* (at your option) any later version.
24+
*
25+
* This program is distributed in the hope that it will be useful,
26+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
27+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28+
* GNU General Public License for more details.
29+
*
30+
* You should have received a copy of the GNU General Public License
31+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
32+
*
33+
* ---------------------------------------------------------------------
34+
*/
35+
36+
/**
37+
* @var \DBmysql $DB
38+
* @var \Migration $migration
39+
* @var array $DELFROMDISPLAYPREF
40+
*/
41+
42+
$table = SavedSearch::getTable();
43+
$field = 'is_private';
44+
if ($DB->fieldExists($table, $field)) {
45+
$query = 'INSERT INTO glpi_entities_savedsearches (savedsearches_id, entities_id, is_recursive)
46+
SELECT id, entities_id, is_recursive
47+
FROM glpi_savedsearches WHERE is_private = 0;';
48+
$DB->doQuery($query);
49+
50+
$migration->dropField($table, $field);
51+
52+
$DELFROMDISPLAYPREF['SavedSearch'] = 4;
53+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php
2+
3+
/**
4+
* ---------------------------------------------------------------------
5+
*
6+
* GLPI - Gestionnaire Libre de Parc Informatique
7+
*
8+
* http://glpi-project.org
9+
*
10+
* @copyright 2015-2025 Teclib' and contributors.
11+
* @copyright 2003-2014 by the INDEPNET Development Team.
12+
* @licence https://www.gnu.org/licenses/gpl-3.0.html
13+
*
14+
* ---------------------------------------------------------------------
15+
*
16+
* LICENSE
17+
*
18+
* This file is part of GLPI.
19+
*
20+
* This program is free software: you can redistribute it and/or modify
21+
* it under the terms of the GNU General Public License as published by
22+
* the Free Software Foundation, either version 3 of the License, or
23+
* (at your option) any later version.
24+
*
25+
* This program is distributed in the hope that it will be useful,
26+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
27+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28+
* GNU General Public License for more details.
29+
*
30+
* You should have received a copy of the GNU General Public License
31+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
32+
*
33+
* ---------------------------------------------------------------------
34+
*/
35+
36+
/**
37+
* @var \DBmysql $DB
38+
* @var \Migration $migration
39+
*/
40+
41+
$default_charset = DBConnection::getDefaultCharset();
42+
$default_collation = DBConnection::getDefaultCollation();
43+
$default_key_sign = DBConnection::getDefaultPrimaryKeySignOption();
44+
45+
if (!$DB->tableExists('glpi_savedsearches_usertargets')) {
46+
$query = "CREATE TABLE `glpi_savedsearches_usertargets` (
47+
`id` int {$default_key_sign} NOT NULL AUTO_INCREMENT,
48+
`savedsearches_id` int {$default_key_sign} NOT NULL DEFAULT '0',
49+
`users_id` int {$default_key_sign} NOT NULL DEFAULT '0',
50+
PRIMARY KEY (`id`),
51+
KEY `savedsearches_id` (`savedsearches_id`),
52+
KEY `users_id` (`users_id`)
53+
) ENGINE = InnoDB ROW_FORMAT = DYNAMIC DEFAULT CHARSET = {$default_charset} COLLATE = {$default_collation};";
54+
$DB->doQuery($query);
55+
}

0 commit comments

Comments
 (0)