Skip to content

Commit

Permalink
Mutualize lists
Browse files Browse the repository at this point in the history
  • Loading branch information
cedric-anne committed May 6, 2024
1 parent a6c3b2e commit 76326a3
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 59 deletions.
21 changes: 5 additions & 16 deletions inc/define.php
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
23 changes: 19 additions & 4 deletions install/migrations/update_10.0.x_to_11.0.0/assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -213,15 +213,30 @@
}
}

// 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'
];
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]);
}
14 changes: 13 additions & 1 deletion install/mysql/glpi-empty.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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`)
Expand Down Expand Up @@ -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,
Expand All @@ -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`),
Expand Down Expand Up @@ -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 '',
Expand All @@ -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;


Expand Down
16 changes: 16 additions & 0 deletions src/Item_DeviceSimcard.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]]
],
];
}

Expand Down
18 changes: 8 additions & 10 deletions tests/functional/CommonDBTM.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
52 changes: 24 additions & 28 deletions tests/functional/Dropdown.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 76326a3

Please sign in to comment.