Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple groups for assets #16760

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ The present file will list all changes made to the project; according to the
- The `Computer_Item` class has been replaced by the `\Glpi\Asset\Asset_PeripheralAsset` class.
- List of network ports in a VLAN form now shows the NetworkPort link in a breadcrumb manner (MyServer > eth0 where MyServer is a link to the computer and eth0 is a link to the port).
- Running `front/cron.php` or `bin/console` will attempt to check and block execution if running as root.
- `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 @@ -149,6 +150,11 @@ The present file will list all changes made to the project; according to the
- Usage of `ajax/dropdownValidator.php` with the `users_id_validate` parameter is no longer supported. Use `items_id_target` instead.
- `Glpi\Dashboard\Filters\AbstractFilter::field()` method has been made protected.
- Usage of `CommonITILValidation::dropdownValidator()` with the `name` and `users_id_validate` options are no longer supported. Use `prefix` and `itemtype_target`/`items_id_target` respectively instead.
- 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 All @@ -161,6 +167,7 @@ The present file will list all changes made to the project; according to the
- Defining "users_id_validate" field without defining "itemtype_target"/"items_id_target" in "CommonITILValidation".
- Usage of `name` and `users_id_validate` options in `CommonITILValidation::dropdownValidator()`.
- Usage of `verbatim_value` Twig filter.
- `linkuser_types`, `linkgroup_types`, `linkuser_tech_types`, `linkgroup_tech_types` configuration entries have been merged in a unique `assignable_types` configuration entry.
- `Auth::getErr()`
- `AuthLDAP::dropdownUserDeletedActions()`
- `AuthLDAP::getOptions()`
Expand Down
38 changes: 30 additions & 8 deletions inc/define.php
Original file line number Diff line number Diff line change
Expand Up @@ -259,14 +259,36 @@
'Peripheral', 'Phone', 'Printer', 'Software', 'Rack'
];

// 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["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["assignable_types"] = [
'Appliance',
'Cable',
'CartridgeItem',
'Certificate',
'Cluster',
'Computer',
'ConsumableItem',
'DatabaseInstance',
'Domain',
'DomainRecord',
'Enclosure',
'Item_DeviceSimcard',
'Line',
'Monitor',
'NetworkEquipment',
'PassiveDCEquipment',
'PDU',
'Peripheral',
'Phone',
'Printer',
'Rack',
'Software',
'SoftwareLicense',
'Unmanaged',
];
$CFG_GLPI["linkuser_types"] = $CFG_GLPI["assignable_types"];
$CFG_GLPI["linkgroup_types"] = $CFG_GLPI["assignable_types"];
$CFG_GLPI["linkuser_tech_types"] = $CFG_GLPI["assignable_types"];
$CFG_GLPI["linkgroup_tech_types"] = $CFG_GLPI["assignable_types"];

$CFG_GLPI["location_types"] = ['Budget', 'CartridgeItem', 'ConsumableItem',
'Computer', 'Monitor', "Glpi\\Socket",
Expand Down
123 changes: 38 additions & 85 deletions inc/relation.constant.php
Original file line number Diff line number Diff line change
Expand Up @@ -715,99 +715,22 @@
],

'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 @@ -1539,7 +1462,10 @@
'users_id_tech',
'users_id',
],
'glpi_cables' => 'users_id_tech',
'glpi_cables' => [
'users_id_tech',
'users_id',
],
'glpi_cartridgeitems' => [
'users_id_tech',
'users_id',
Expand All @@ -1562,7 +1488,10 @@
'users_id',
'users_id_validate',
],
'glpi_clusters' => 'users_id_tech',
'glpi_clusters' => [
'users_id_tech',
'users_id',
],
'glpi_computers' => [
'users_id_tech',
'users_id',
Expand All @@ -1578,11 +1507,20 @@
'users_id',
],
'_glpi_displaypreferences' => 'users_id',
'glpi_domains' => 'users_id_tech',
'glpi_domainrecords' => 'users_id_tech',
'glpi_domains' => [
'users_id_tech',
'users_id',
],
'glpi_domainrecords' => [
'users_id_tech',
'users_id',
],
'glpi_documents' => 'users_id',
'glpi_documents_items' => 'users_id',
'glpi_enclosures' => 'users_id_tech',
'glpi_enclosures' => [
'users_id_tech',
'users_id',
],
'glpi_forms_answerssets' => 'users_id',
'_glpi_groups_users' => 'users_id',
'glpi_items_devicesimcards' => [
Expand Down Expand Up @@ -1623,8 +1561,14 @@
],
'glpi_notimportedemails' => 'users_id',
'_glpi_objectlocks' => 'users_id',
'glpi_passivedcequipments' => 'users_id_tech',
'glpi_pdus' => 'users_id_tech',
'glpi_passivedcequipments' => [
'users_id_tech',
'users_id',
],
'glpi_pdus' => [
'users_id_tech',
'users_id',
],
'glpi_peripherals' => [
'users_id_tech',
'users_id',
Expand Down Expand Up @@ -1871,3 +1815,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 = $CFG_GLPI['assignable_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]);
}