From 76326a3873309700f611c2462099cbabaf0b28a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Anne?= Date: Mon, 6 May 2024 14:48:05 +0200 Subject: [PATCH] Mutualize lists --- inc/define.php | 21 ++------ .../update_10.0.x_to_11.0.0/assets.php | 23 ++++++-- install/mysql/glpi-empty.sql | 14 ++++- src/Item_DeviceSimcard.php | 16 ++++++ tests/functional/CommonDBTM.php | 18 +++---- tests/functional/Dropdown.php | 52 +++++++++---------- 6 files changed, 85 insertions(+), 59 deletions(-) diff --git a/inc/define.php b/inc/define.php index 6be448d1c8cf..d6e53fe9ae97 100644 --- a/inc/define.php +++ b/inc/define.php @@ -259,25 +259,14 @@ 'Peripheral', 'Phone', 'Printer', 'Software', 'Rack' ]; -$CFG_GLPI["linkuser_types"] = ['Computer', 'Monitor', 'NetworkEquipment', +// FIXME: Merge these configurations +$CFG_GLPI["linkuser_types"] = ['Computer', 'CartridgeItem', 'ConsumableItem', 'Monitor', 'NetworkEquipment', 'Peripheral', 'Phone', 'Printer', 'Software', 'SoftwareLicense', 'Certificate', 'Appliance', 'Item_DeviceSimcard', 'Line' ]; - -$CFG_GLPI["linkgroup_types"] = ['Computer', 'Monitor', 'NetworkEquipment', - 'Peripheral', 'Phone', 'Printer', 'Software', - 'SoftwareLicense', 'Certificate', 'Appliance', 'Item_DeviceSimcard', 'Line' -]; - -$CFG_GLPI["linkuser_tech_types"] = ['Computer', 'ConsumableItem', 'Monitor', 'NetworkEquipment', - 'Peripheral', 'Phone', 'Printer', 'Software', - 'SoftwareLicense', 'Certificate', 'Appliance', 'DatabaseInstance' -]; - -$CFG_GLPI["linkgroup_tech_types"] = ['Computer', 'ConsumableItem', 'Monitor', 'NetworkEquipment', - 'Peripheral', 'Phone', 'Printer', 'Software', - 'SoftwareLicense', 'Certificate', 'Appliance', 'DatabaseInstance' -]; +$CFG_GLPI["linkgroup_types"] = $CFG_GLPI["linkuser_types"]; +$CFG_GLPI["linkuser_tech_types"] = $CFG_GLPI["linkuser_types"]; +$CFG_GLPI["linkgroup_tech_types"] = $CFG_GLPI["linkuser_types"]; $CFG_GLPI["location_types"] = ['Budget', 'CartridgeItem', 'ConsumableItem', 'Computer', 'Monitor', "Glpi\\Socket", diff --git a/install/migrations/update_10.0.x_to_11.0.0/assets.php b/install/migrations/update_10.0.x_to_11.0.0/assets.php index 756f5c65e57e..c6150f64c089 100644 --- a/install/migrations/update_10.0.x_to_11.0.0/assets.php +++ b/install/migrations/update_10.0.x_to_11.0.0/assets.php @@ -213,6 +213,23 @@ } } +// Add missing fields on assignable items +$migration->addField('glpi_cartridgeitems', 'users_id', 'fkey'); +$migration->addKey('glpi_cartridgeitems', 'users_id'); +$migration->addField('glpi_cartridgeitems', 'groups_id', 'fkey'); +$migration->addKey('glpi_cartridgeitems', 'groups_id'); + +$migration->addField('glpi_consumableitems', 'users_id', 'fkey'); +$migration->addKey('glpi_consumableitems', 'users_id'); +$migration->addField('glpi_consumableitems', 'groups_id', 'fkey'); +$migration->addKey('glpi_consumableitems', 'groups_id'); + +$migration->addField('glpi_items_devicesimcards', 'users_id_tech', 'fkey'); +$migration->addKey('glpi_items_devicesimcards', 'users_id_tech'); +$migration->addField('glpi_items_devicesimcards', 'groups_id_tech', 'fkey'); +$migration->addKey('glpi_items_devicesimcards', 'groups_id_tech'); + +// Add assignable assets rights $assignable_asset_rights = [ 'computer', 'monitor', 'software', 'networking', 'printer', 'cartridge', 'consumable', 'phone', 'peripheral' @@ -220,8 +237,6 @@ foreach ($assignable_asset_rights as $rightname) { $migration->addRight($rightname, READ_ASSIGNED, [$rightname => READ]); $migration->addRight($rightname, UPDATE_ASSIGNED, [$rightname => UPDATE]); - if ($rightname !== 'cartdrige' && $rightname !== 'consumable') { - $migration->addRight($rightname, READ_OWNED, [$rightname => READ]); - $migration->addRight($rightname, UPDATE_OWNED, [$rightname => UPDATE]); - } + $migration->addRight($rightname, READ_OWNED, [$rightname => READ]); + $migration->addRight($rightname, UPDATE_OWNED, [$rightname => UPDATE]); } diff --git a/install/mysql/glpi-empty.sql b/install/mysql/glpi-empty.sql index fc90be348884..dd639d773e32 100644 --- a/install/mysql/glpi-empty.sql +++ b/install/mysql/glpi-empty.sql @@ -433,7 +433,9 @@ CREATE TABLE `glpi_cartridgeitems` ( `locations_id` int unsigned NOT NULL DEFAULT '0', `cartridgeitemtypes_id` int unsigned NOT NULL DEFAULT '0', `manufacturers_id` int unsigned NOT NULL DEFAULT '0', + `users_id` int unsigned NOT NULL DEFAULT '0', `users_id_tech` int unsigned NOT NULL DEFAULT '0', + `groups_id` int unsigned NOT NULL DEFAULT '0', `groups_id_tech` int unsigned NOT NULL DEFAULT '0', `is_deleted` tinyint NOT NULL DEFAULT '0', `comment` text, @@ -448,10 +450,12 @@ CREATE TABLE `glpi_cartridgeitems` ( KEY `is_recursive` (`is_recursive`), KEY `manufacturers_id` (`manufacturers_id`), KEY `locations_id` (`locations_id`), + KEY `users_id` (`users_id`), KEY `users_id_tech` (`users_id_tech`), KEY `cartridgeitemtypes_id` (`cartridgeitemtypes_id`), KEY `is_deleted` (`is_deleted`), KEY `alarm_threshold` (`alarm_threshold`), + KEY `groups_id` (`groups_id`), KEY `groups_id_tech` (`groups_id_tech`), KEY `date_mod` (`date_mod`), KEY `date_creation` (`date_creation`) @@ -1321,7 +1325,9 @@ CREATE TABLE `glpi_consumableitems` ( `locations_id` int unsigned NOT NULL DEFAULT '0', `consumableitemtypes_id` int unsigned NOT NULL DEFAULT '0', `manufacturers_id` int unsigned NOT NULL DEFAULT '0', + `users_id` int unsigned NOT NULL DEFAULT '0', `users_id_tech` int unsigned NOT NULL DEFAULT '0', + `groups_id` int unsigned NOT NULL DEFAULT '0', `groups_id_tech` int unsigned NOT NULL DEFAULT '0', `is_deleted` tinyint NOT NULL DEFAULT '0', `comment` text, @@ -1337,10 +1343,12 @@ CREATE TABLE `glpi_consumableitems` ( KEY `is_recursive` (`is_recursive`), KEY `manufacturers_id` (`manufacturers_id`), KEY `locations_id` (`locations_id`), + KEY `users_id` (`users_id`), KEY `users_id_tech` (`users_id_tech`), KEY `consumableitemtypes_id` (`consumableitemtypes_id`), KEY `is_deleted` (`is_deleted`), KEY `alarm_threshold` (`alarm_threshold`), + KEY `groups_id` (`groups_id`), KEY `groups_id_tech` (`groups_id_tech`), KEY `date_mod` (`date_mod`), KEY `date_creation` (`date_creation`), @@ -2463,7 +2471,9 @@ CREATE TABLE `glpi_items_devicesimcards` ( `locations_id` int unsigned NOT NULL DEFAULT '0', `lines_id` int unsigned NOT NULL DEFAULT '0', `users_id` int unsigned NOT NULL DEFAULT '0', + `users_id_tech` int unsigned NOT NULL DEFAULT '0', `groups_id` int unsigned NOT NULL DEFAULT '0', + `groups_id_tech` int unsigned NOT NULL DEFAULT '0', `pin` varchar(255) NOT NULL DEFAULT '', `pin2` varchar(255) NOT NULL DEFAULT '', `puk` varchar(255) NOT NULL DEFAULT '', @@ -2483,7 +2493,9 @@ CREATE TABLE `glpi_items_devicesimcards` ( KEY `locations_id` (`locations_id`), KEY `lines_id` (`lines_id`), KEY `users_id` (`users_id`), - KEY `groups_id` (`groups_id`) + KEY `users_id_tech` (`users_id_tech`), + KEY `groups_id` (`groups_id`), + KEY `groups_id_tech` (`groups_id_tech`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=DYNAMIC; diff --git a/src/Item_DeviceSimcard.php b/src/Item_DeviceSimcard.php index 7d250f4ecfd5..5da5086a776d 100644 --- a/src/Item_DeviceSimcard.php +++ b/src/Item_DeviceSimcard.php @@ -123,6 +123,22 @@ public static function getSpecificities($specif = '') 'id' => 22, 'datatype' => 'dropdown' ], + 'users_id_tech' => [ + 'long name' => __('Technician in charge'), + 'short name' => __('Technician in charge'), + 'size' => 20, + 'id' => 23, + 'datatype' => 'dropdown', + 'dropdown_options' => ['right' => 'own_ticket'] + ], + 'groups_id_tech' => [ + 'long name' => __('Group in charge'), + 'short name' => __('Group in charge'), + 'size' => 20, + 'id' => 24, + 'datatype' => 'dropdown', + 'dropdown_options' => ['condition' => ['is_assign' => 1]] + ], ]; } diff --git a/tests/functional/CommonDBTM.php b/tests/functional/CommonDBTM.php index 06828f1a6fb4..4728d322150c 100644 --- a/tests/functional/CommonDBTM.php +++ b/tests/functional/CommonDBTM.php @@ -1814,16 +1814,14 @@ public function testCanViewItemAssignableAssets($itemtype) ])); $this->boolean($item->canViewItem())->isTrue(); - if ($itemtype !== \CartridgeItem::class && $itemtype !== \ConsumableItem::class) { - $this->boolean($item->canViewItem())->isTrue(); - $_SESSION['glpiactiveprofile'][$itemtype::$rightname] = READ_OWNED; - $this->boolean($item->canViewItem())->isFalse(); - $this->boolean($item->update([ - 'id' => $item->getID(), - 'users_id' => $_SESSION['glpiID'], - ])); - $this->boolean($item->canViewItem())->isTrue(); - } + $this->boolean($item->canViewItem())->isTrue(); + $_SESSION['glpiactiveprofile'][$itemtype::$rightname] = READ_OWNED; + $this->boolean($item->canViewItem())->isFalse(); + $this->boolean($item->update([ + 'id' => $item->getID(), + 'users_id' => $_SESSION['glpiID'], + ])); + $this->boolean($item->canViewItem())->isTrue(); // Create group for the user $group = new \Group(); diff --git a/tests/functional/Dropdown.php b/tests/functional/Dropdown.php index 12fa54eec1dc..323f558cdb17 100644 --- a/tests/functional/Dropdown.php +++ b/tests/functional/Dropdown.php @@ -2070,14 +2070,12 @@ public function testGetDropdownFindNumAssignableAssets($itemtype) 'entities_id' => $this->getTestRootEntity(true), 'groups_id_tech' => $groups_id ]))->isGreaterThan(0); - // Create an item with a user as the owner if not a CartridgeItem/ConsumableItem - if (!in_array($itemtype, [\CartridgeItem::class, \ConsumableItem::class], true)) { - $this->integer($item->add([ - 'name' => __FUNCTION__ . '4', - 'entities_id' => $this->getTestRootEntity(true), - 'users_id' => $_SESSION['glpiID'] - ]))->isGreaterThan(0); - } + // Create an item with a user as the owner + $this->integer($item->add([ + 'name' => __FUNCTION__ . '4', + 'entities_id' => $this->getTestRootEntity(true), + 'users_id' => $_SESSION['glpiID'] + ]))->isGreaterThan(0); $results = \Dropdown::getDropdownFindNum([ 'itemtype' => $itemtype, @@ -2113,26 +2111,24 @@ public function testGetDropdownFindNumAssignableAssets($itemtype) $this->array(array_column($results, 'text'))->containsValues($expected); $this->array(array_column($results, 'text'))->notContainsValues($not_expected); - if (!in_array($itemtype, [\CartridgeItem::class, \ConsumableItem::class], true)) { - $_SESSION['glpiactiveprofile'][$itemtype::$rightname] = READ_OWNED; - $results = \Dropdown::getDropdownFindNum([ - 'itemtype' => $itemtype, - 'table' => $itemtype::getTable(), - '_idor_token' => \Session::getNewIDORToken($itemtype, [ - 'table' => $itemtype::getTable() - ]) - ], false)['results']; - $expected = [ - __FUNCTION__ . '4' - ]; - $not_expected = [ - __FUNCTION__ . '1', - __FUNCTION__ . '2', - __FUNCTION__ . '3' - ]; - $this->array(array_column($results, 'text'))->containsValues($expected); - $this->array(array_column($results, 'text'))->notContainsValues($not_expected); - } + $_SESSION['glpiactiveprofile'][$itemtype::$rightname] = READ_OWNED; + $results = \Dropdown::getDropdownFindNum([ + 'itemtype' => $itemtype, + 'table' => $itemtype::getTable(), + '_idor_token' => \Session::getNewIDORToken($itemtype, [ + 'table' => $itemtype::getTable() + ]) + ], false)['results']; + $expected = [ + __FUNCTION__ . '4' + ]; + $not_expected = [ + __FUNCTION__ . '1', + __FUNCTION__ . '2', + __FUNCTION__ . '3' + ]; + $this->array(array_column($results, 'text'))->containsValues($expected); + $this->array(array_column($results, 'text'))->notContainsValues($not_expected); // Remove permission to read assigned items $_SESSION['glpiactiveprofile'][$itemtype::$rightname] = 0;