Skip to content

Commit

Permalink
Multiple groups for assets
Browse files Browse the repository at this point in the history
  • Loading branch information
cconard96 authored and cedric-anne committed May 13, 2024
1 parent df69399 commit b4fd04a
Show file tree
Hide file tree
Showing 59 changed files with 2,233 additions and 691 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,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 @@ -137,6 +138,11 @@ The present file will list all changes made to the project; according to the
- `Lock::getLocksQueryInfosByItemType()` has been made private.
- `DBmysql::request()`, `DBmysqlIterator::buildQuery()` and `DBmysqlIterator::execute()` methods signatures changed.
- Some values for the `$type` parameters of several `Stat` methods have changed to match English spelling (technicien -> technician).
- Any class added to `$CFG_GLPI['directconnect_types']` must now use the `Glpi\Features\AssignableItem` 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_items`.
- `Group::getDataItems()` signature changed. The two first parameters `$types` and `$field` were replaced
by a unique boolean `$tech` parameter that is used to compute the `$types` and `$field` values automatically.

#### Deprecated
- Usage of `MAIL_SMTPSSL` and `MAIL_SMTPTLS` constants.
Expand Down
25 changes: 22 additions & 3 deletions inc/define.php
Original file line number Diff line number Diff line change
Expand Up @@ -260,9 +260,28 @@
];

// FIXME: Merge these configurations
$CFG_GLPI["linkuser_types"] = ['Computer', 'CartridgeItem', 'ConsumableItem', 'Monitor', 'NetworkEquipment',
'Peripheral', 'Phone', 'Printer', 'Software',
'SoftwareLicense', 'Certificate', 'Appliance', 'DatabaseInstance', 'Item_DeviceSimcard', 'Line'
$CFG_GLPI["linkuser_types"] = [
'Appliance',
'CartridgeItem',
'Certificate',
'Cluster',
'Computer',
'ConsumableItem',
'DatabaseInstance',
'Domain',
'DomainRecord',
'Enclosure',
'Item_DeviceSimcard',
'Line',
'Monitor',
'NetworkEquipment',
'Peripheral',
'Phone',
'Printer',
'Rack',
'Software',
'SoftwareLicense',
'Unmanaged',
];
$CFG_GLPI["linkgroup_types"] = $CFG_GLPI["linkuser_types"];
$CFG_GLPI["linkuser_tech_types"] = $CFG_GLPI["linkuser_types"];
Expand Down
82 changes: 10 additions & 72 deletions inc/relation.constant.php
Original file line number Diff line number Diff line change
Expand Up @@ -715,99 +715,28 @@
],

'glpi_groups' => [
'glpi_appliances' => [
'groups_id_tech',
'groups_id',
],
'glpi_assets_assets' => [
'groups_id_tech',
'groups_id',
],
'glpi_cartridgeitems' => [
'groups_id_tech',
'groups_id',
],
'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',
'groups_id',
],
'glpi_databaseinstances' => [
'groups_id_tech',
'groups_id',
],
'glpi_domains' => 'groups_id_tech',
'glpi_domainrecords' => 'groups_id_tech',
'glpi_enclosures' => 'groups_id_tech',
'glpi_groups' => 'groups_id',
'_glpi_groups_items' => 'groups_id',
'_glpi_groups_knowbaseitems' => 'groups_id',
'_glpi_groups_problems' => 'groups_id',
'_glpi_groups_reminders' => 'groups_id',
'_glpi_groups_rssfeeds' => 'groups_id',
'_glpi_groups_tickets' => 'groups_id',
'_glpi_groups_users' => 'groups_id',
'glpi_items_devicesimcards' => [
'groups_id_tech',
'groups_id',
],
'glpi_itilcategories' => 'groups_id',
'glpi_lines' => [
'groups_id_tech',
'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' => [
'groups_id_tech',
'groups_id',
],
'glpi_softwarelicenses' => [
'groups_id_tech',
'groups_id',
],
'glpi_softwares' => [
'groups_id_tech',
'groups_id',
],
'glpi_tasktemplates' => 'groups_id_tech',
'glpi_tickettasks' => 'groups_id_tech',
'glpi_unmanageds' => [
'groups_id_tech',
'groups_id',
],
'glpi_users' => 'groups_id',
'glpi_itilvalidationtemplates_targets' => 'groups_id',
],
Expand Down Expand Up @@ -1871,3 +1800,12 @@
$define_mapping_entry($source_table, $target_table_key);
$RELATION[$source_table][$target_table_key][] = ['itemtype_asset', 'items_id_asset'];
}

// Multiple groups assignments
$assignable_itemtypes = array_unique(array_merge($CFG_GLPI['linkgroup_types'], $CFG_GLPI['linkgroup_tech_types']));
foreach ($assignable_itemtypes as $assignable_itemtype) {
$source_table_key = $assignable_itemtype::getTable();

$define_mapping_entry($source_table_key, '_glpi_groups_items');
$RELATION[$source_table_key]['_glpi_groups_items'][] = ['itemtype', 'items_id'];
}
46 changes: 4 additions & 42 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 @@ -86,9 +86,7 @@
`contact` varchar(255) DEFAULT NULL,
`contact_num` varchar(255) DEFAULT NULL,
`users_id` int {$default_key_sign} NOT NULL DEFAULT '0',
`groups_id` int {$default_key_sign} NOT NULL DEFAULT '0',
`users_id_tech` int {$default_key_sign} NOT NULL DEFAULT '0',
`groups_id_tech` int {$default_key_sign} NOT NULL DEFAULT '0',
`locations_id` int {$default_key_sign} NOT NULL DEFAULT '0',
`manufacturers_id` int {$default_key_sign} NOT NULL DEFAULT '0',
`states_id` int {$default_key_sign} NOT NULL DEFAULT '0',
Expand All @@ -105,9 +103,7 @@
KEY `assets_assettypes_id` (`assets_assettypes_id`),
KEY `name` (`name`),
KEY `users_id` (`users_id`),
KEY `groups_id` (`groups_id`),
KEY `users_id_tech` (`users_id_tech`),
KEY `groups_id_tech` (`groups_id_tech`),
KEY `locations_id` (`locations_id`),
KEY `manufacturers_id` (`manufacturers_id`),
KEY `states_id` (`states_id`),
Expand All @@ -128,6 +124,10 @@
$migration->addField('glpi_assets_assets', 'is_template', 'bool');
$migration->addKey('glpi_assets_assets', 'is_template');
$migration->addField('glpi_assets_assets', 'template_name', 'string');
$migration->dropKey('glpi_assets_assets', 'groups_id');
$migration->dropField('glpi_assets_assets', 'groups_id');
$migration->dropKey('glpi_assets_assets', 'groups_id_tech');
$migration->dropField('glpi_assets_assets', 'groups_id_tech');
}

if (!$DB->tableExists('glpi_assets_assetmodels')) {
Expand Down Expand Up @@ -212,41 +212,3 @@
]);
}
}

// 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_databaseinstances', 'users_id', 'fkey');
$migration->addKey('glpi_databaseinstances', 'users_id');
$migration->addField('glpi_databaseinstances', 'groups_id', 'fkey');
$migration->addKey('glpi_databaseinstances', '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');

$migration->addField('glpi_lines', 'users_id_tech', 'fkey');
$migration->addKey('glpi_lines', 'users_id_tech');
$migration->addField('glpi_lines', 'groups_id_tech', 'fkey');
$migration->addKey('glpi_lines', '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]);
$migration->addRight($rightname, READ_OWNED, [$rightname => READ]);
$migration->addRight($rightname, UPDATE_OWNED, [$rightname => UPDATE]);
}

0 comments on commit b4fd04a

Please sign in to comment.