Skip to content

Commit

Permalink
Multiple groups for assets
Browse files Browse the repository at this point in the history
  • Loading branch information
cconard96 committed Apr 15, 2024
1 parent 84dc8b6 commit 49e7e5f
Show file tree
Hide file tree
Showing 40 changed files with 2,185 additions and 232 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ The present file will list all changes made to the project; according to the
- External Links `Link or filename` and `File content` fields now use Twig templates instead of a custom tag syntax.
- Itemtypes associated with External links are now in the main form rather than a separate tab.
- The `Computer_Item` class has been replaced by the `\Glpi\Asset\Asset_PeripheralAsset` class.
- `Group` and `Group in charge` fields for assets may now contain multiple groups.

### Deprecated
- Survey URL tags `TICKETCATEGORY_ID` and `TICKETCATEGORY_NAME` are deprecated and replaced by `ITILCATEGORY_ID` and `ITILCATEGORY_NAME` respectively.
Expand Down Expand Up @@ -135,6 +136,9 @@ The present file will list all changes made to the project; according to the
- Specifying the `ranking` of a rule during add/update now triggers `RuleCollection::moveRule` to manage the rankings of other rules to try to keep them valid and in order.
- `Lock::getLocksQueryInfosByItemType()` has been made private.
- `DBmysql::request()`, `DBmysqlIterator::buildQuery()` and `DBmysqlIterator::execute()` methods signatures changed.
- Any class added to `$CFG_GLPI['directconnect_types']` must now use the `Glpi\Features\AssignableAsset` trait as multi-group support is required.
- For assets, `groups_id` and `groups_id_tech` fields were changed from integers to arrays and are loaded into the `fields` array after `getFromDB`/`getEmpty`.
If reading directly from the DB, you need to query the new linking table `glpi_groups_assets`.

#### Deprecated
- Usage of `MAIL_SMTPSSL` and `MAIL_SMTPTLS` constants.
Expand Down
32 changes: 2 additions & 30 deletions inc/relation.constant.php
Original file line number Diff line number Diff line change
Expand Up @@ -722,24 +722,20 @@
'groups_id_tech',
'groups_id',
],
'glpi_cartridgeitems' => 'groups_id_tech',
'glpi_certificates' => [
'groups_id_tech',
'groups_id',
],
'_glpi_changes_groups' => 'groups_id',
'glpi_changetasks' => 'groups_id_tech',
'glpi_clusters' => 'groups_id_tech',
'glpi_computers' => [
'groups_id_tech',
'groups_id',
],
'glpi_consumableitems' => 'groups_id_tech',
'glpi_databaseinstances' => 'groups_id_tech',
'glpi_domains' => 'groups_id_tech',
'glpi_domainrecords' => 'groups_id_tech',
'glpi_enclosures' => 'groups_id_tech',
'glpi_groups' => 'groups_id',
//FIXME I guess cleanup should be manual, or an actual class is needed.
//'_glpi_groups_assets' => 'groups_id',
'_glpi_groups_knowbaseitems' => 'groups_id',
'_glpi_groups_problems' => 'groups_id',
'_glpi_groups_reminders' => 'groups_id',
Expand All @@ -749,29 +745,9 @@
'glpi_items_devicesimcards' => 'groups_id',
'glpi_itilcategories' => 'groups_id',
'glpi_lines' => 'groups_id',
'glpi_monitors' => [
'groups_id_tech',
'groups_id',
],
'glpi_networkequipments' => [
'groups_id_tech',
'groups_id',
],
'glpi_passivedcequipments' => 'groups_id_tech',
'glpi_pdus' => 'groups_id_tech',
'glpi_peripherals' => [
'groups_id_tech',
'groups_id',
],
'glpi_planningexternalevents' => 'groups_id',
'glpi_phones' => [
'groups_id_tech',
'groups_id',
],
'glpi_printers' => [
'groups_id_tech',
'groups_id',
],
'glpi_problemtasks' => 'groups_id_tech',
'glpi_projects' => 'groups_id',
'glpi_racks' => [
Expand All @@ -782,10 +758,6 @@
'groups_id_tech',
'groups_id',
],
'glpi_softwares' => [
'groups_id_tech',
'groups_id',
],
'glpi_tasktemplates' => 'groups_id_tech',
'glpi_tickettasks' => 'groups_id_tech',
'glpi_unmanageds' => [
Expand Down
100 changes: 94 additions & 6 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,11 +213,99 @@
}
}

$assignable_asset_rights = [
'computer', 'monitor', 'software', 'networking', 'printer',
'cartridge', 'consumable', 'phone', 'peripheral'
$assignable_assets = [
'Computer' => [
'table' => 'glpi_computers',
'rightname' => 'computer'
],
'Monitor' => [
'table' => 'glpi_monitors',
'rightname' => 'monitor'
],
'Software' => [
'table' => 'glpi_softwares',
'rightname' => 'software'
],
'NetworkEquipment' => [
'table' => 'glpi_networkequipments',
'rightname' => 'networking'
],
'Printer' => [
'table' => 'glpi_printers',
'rightname' => 'printer'
],
'CartridgeItem' => [
'table' => 'glpi_cartridgeitems',
'rightname' => 'cartridge'
],
'ConsumableItem' => [
'table' => 'glpi_consumableitems',
'rightname' => 'consumable'
],
'Phone' => [
'table' => 'glpi_phones',
'rightname' => 'phone'
],
'Peripheral' => [
'table' => 'glpi_peripherals',
'rightname' => 'peripheral'
]
];
foreach ($assignable_asset_rights as $rightname) {
$migration->addRight($rightname, READ_ASSIGNED, [$rightname => READ]);
$migration->addRight($rightname, UPDATE_ASSIGNED, [$rightname => UPDATE]);

if (!$DB->tableExists('glpi_groups_assets')) {
$query = <<<SQL
CREATE TABLE `glpi_groups_assets` (
`id` int unsigned NOT NULL AUTO_INCREMENT,
`groups_id` int {$default_key_sign} NOT NULL DEFAULT '0',
`itemtype` varchar(255) NOT NULL DEFAULT '',
`items_id` int {$default_key_sign} NOT NULL DEFAULT '0',
`type` tinyint NOT NULL DEFAULT '0',
PRIMARY KEY (`id`),
UNIQUE KEY `unicity` (`groups_id`,`itemtype`,`items_id`, `type`),
KEY `item` (`itemtype`, `items_id`)
) ENGINE=InnoDB DEFAULT CHARSET={$default_charset} COLLATE={$default_collation} ROW_FORMAT=DYNAMIC;
SQL;
$DB->doQueryOrDie($query);
}

foreach ($assignable_assets as $asset_class => $asset) {
$migration->addRight($asset['rightname'], READ_ASSIGNED, [$asset['rightname'] => READ]);
$migration->addRight($asset['rightname'], UPDATE_ASSIGNED, [$asset['rightname'] => UPDATE]);

// move groups to the new link table
if ($DB->fieldExists($asset['table'], 'groups_id')) {
$DB->insert('glpi_groups_assets', new \Glpi\DBAL\QuerySubQuery([
'SELECT' => [
new \Glpi\DBAL\QueryExpression('NULL', 'id'),
new \Glpi\DBAL\QueryExpression('0', 'type'),
'id AS items_id',
'groups_id',
new \Glpi\DBAL\QueryExpression($DB::quoteValue($asset_class), 'itemtype')
],
'FROM' => $asset['table'],
'WHERE' => [
'groups_id' => ['>', 0]
]
]));
}
if ($DB->fieldExists($asset['table'], 'groups_id_tech')) {
$DB->insert('glpi_groups_assets', new \Glpi\DBAL\QuerySubQuery([
'SELECT' => [
new \Glpi\DBAL\QueryExpression('NULL', 'id'),
new \Glpi\DBAL\QueryExpression('1', 'type'),
'id AS items_id',
'groups_id_tech AS groups_id',
new \Glpi\DBAL\QueryExpression($DB::quoteValue($asset_class), 'itemtype')
],
'FROM' => $asset['table'],
'WHERE' => [
'groups_id_tech' => ['>', 0]
]
]));
}

$migration->dropKey($asset['table'], 'groups_id');
$migration->dropKey($asset['table'], 'groups_id_tech');
$migration->dropField($asset['table'], 'groups_id');
$migration->dropField($asset['table'], 'groups_id_tech');
}

0 comments on commit 49e7e5f

Please sign in to comment.