Skip to content

Commit

Permalink
Merge configurations and add missing itemtypes
Browse files Browse the repository at this point in the history
  • Loading branch information
cedric-anne committed May 22, 2024
1 parent 30776be commit 0fc09a1
Show file tree
Hide file tree
Showing 13 changed files with 117 additions and 148 deletions.
14 changes: 9 additions & 5 deletions inc/define.php
Original file line number Diff line number Diff line change
Expand Up @@ -259,9 +259,9 @@
'Peripheral', 'Phone', 'Printer', 'Software', 'Rack'
];

// FIXME: Merge these configurations
$CFG_GLPI["linkuser_types"] = [
$CFG_GLPI["assignable_types"] = [
'Appliance',
'Cable',
'CartridgeItem',
'Certificate',
'Cluster',
Expand All @@ -275,6 +275,8 @@
'Line',
'Monitor',
'NetworkEquipment',
'PassiveDCEquipment',
'PDU',
'Peripheral',
'Phone',
'Printer',
Expand All @@ -283,9 +285,11 @@
'SoftwareLicense',
'Unmanaged',
];
$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"];
// FIXME: Deprecate these configurations
$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
43 changes: 29 additions & 14 deletions inc/relation.constant.php
Original file line number Diff line number Diff line change
Expand Up @@ -717,10 +717,6 @@
'glpi_groups' => [
'_glpi_changes_groups' => 'groups_id',
'glpi_changetasks' => 'groups_id_tech',
'glpi_clusters' => 'groups_id_tech',
'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',
Expand All @@ -730,8 +726,6 @@
'_glpi_groups_tickets' => 'groups_id',
'_glpi_groups_users' => 'groups_id',
'glpi_itilcategories' => 'groups_id',
'glpi_passivedcequipments' => 'groups_id_tech',
'glpi_pdus' => 'groups_id_tech',
'glpi_planningexternalevents' => 'groups_id',
'glpi_problemtasks' => 'groups_id_tech',
'glpi_projects' => 'groups_id',
Expand Down Expand Up @@ -1468,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 @@ -1491,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 @@ -1507,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 @@ -1552,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 @@ -1802,7 +1817,7 @@
}

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

Expand Down
10 changes: 6 additions & 4 deletions install/mysql/glpi-empty.sql
Original file line number Diff line number Diff line change
Expand Up @@ -4449,6 +4449,7 @@ CREATE TABLE `glpi_cables` (
`color` varchar(255) DEFAULT NULL,
`otherserial` varchar(255) DEFAULT NULL,
`states_id` int unsigned NOT NULL DEFAULT '0',
`users_id` int unsigned NOT NULL DEFAULT '0',
`users_id_tech` int unsigned NOT NULL DEFAULT '0',
`cabletypes_id` int unsigned NOT NULL DEFAULT '0',
`comment` text,
Expand All @@ -4470,6 +4471,7 @@ CREATE TABLE `glpi_cables` (
KEY `complete` (`entities_id`,`name`),
KEY `is_recursive` (`is_recursive`),
KEY `is_template` (`is_template`),
KEY `users_id` (`users_id`),
KEY `users_id_tech` (`users_id_tech`),
KEY `cabletypes_id` (`cabletypes_id`),
KEY `date_mod` (`date_mod`),
Expand Down Expand Up @@ -5151,8 +5153,8 @@ CREATE TABLE `glpi_passivedcequipments` (
`otherserial` varchar(255) DEFAULT NULL,
`passivedcequipmentmodels_id` int unsigned DEFAULT NULL,
`passivedcequipmenttypes_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_tech` int unsigned NOT NULL DEFAULT '0',
`is_template` tinyint NOT NULL DEFAULT '0',
`template_name` varchar(255) DEFAULT NULL,
`is_deleted` tinyint NOT NULL DEFAULT '0',
Expand All @@ -5168,8 +5170,8 @@ CREATE TABLE `glpi_passivedcequipments` (
KEY `locations_id` (`locations_id`),
KEY `passivedcequipmentmodels_id` (`passivedcequipmentmodels_id`),
KEY `passivedcequipmenttypes_id` (`passivedcequipmenttypes_id`),
KEY `users_id` (`users_id`),
KEY `users_id_tech` (`users_id_tech`),
KEY `group_id_tech` (`groups_id_tech`),
KEY `is_template` (`is_template`),
KEY `is_deleted` (`is_deleted`),
KEY `states_id` (`states_id`),
Expand Down Expand Up @@ -8429,8 +8431,8 @@ CREATE TABLE `glpi_pdus` (
`serial` varchar(255) DEFAULT NULL,
`otherserial` varchar(255) DEFAULT NULL,
`pdumodels_id` int unsigned DEFAULT NULL,
`users_id` int unsigned NOT NULL DEFAULT '0',
`users_id_tech` int unsigned NOT NULL DEFAULT '0',
`groups_id_tech` int unsigned NOT NULL DEFAULT '0',
`is_template` tinyint NOT NULL DEFAULT '0',
`template_name` varchar(255) DEFAULT NULL,
`is_deleted` tinyint NOT NULL DEFAULT '0',
Expand All @@ -8446,8 +8448,8 @@ CREATE TABLE `glpi_pdus` (
KEY `is_recursive` (`is_recursive`),
KEY `locations_id` (`locations_id`),
KEY `pdumodels_id` (`pdumodels_id`),
KEY `users_id` (`users_id`),
KEY `users_id_tech` (`users_id_tech`),
KEY `group_id_tech` (`groups_id_tech`),
KEY `is_template` (`is_template`),
KEY `is_deleted` (`is_deleted`),
KEY `states_id` (`states_id`),
Expand Down
3 changes: 1 addition & 2 deletions src/Api/HL/Controller/AdministrationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -704,8 +704,7 @@ private function getUsedOrManagedItems(int $users_id, bool $is_managed, array $r
/** @var array $CFG_GLPI */
global $CFG_GLPI;
// Create a union schema with all relevant item types
$types = $is_managed ? $CFG_GLPI['linkuser_tech_types'] : $CFG_GLPI['linkuser_types'];
$schema = Doc\Schema::getUnionSchemaForItemtypes($types);
$schema = Doc\Schema::getUnionSchemaForItemtypes($CFG_GLPI['assignable_types']);
$rsql_filter = $request_params['filter'] ?? '';
if (!empty($rsql_filter)) {
$rsql_filter = "($rsql_filter);";
Expand Down
131 changes: 53 additions & 78 deletions src/Api/HL/Controller/AssetController.php
Original file line number Diff line number Diff line change
Expand Up @@ -390,100 +390,75 @@ class: $model_class,
);
}

if (in_array($asset_type, $CFG_GLPI['linkuser_types'], true)) {
if (in_array($asset_type, $CFG_GLPI['assignable_types'], true)) {
$schemas[$schema_name]['properties']['user'] = self::getDropdownTypeSchema(
class: User::class,
field: 'users_id',
full_schema: 'User'
);
}
if (in_array($asset_type, $CFG_GLPI['linkuser_tech_types'], true)) {
$schemas[$schema_name]['properties']['user_tech'] = self::getDropdownTypeSchema(
class: User::class,
field: 'users_id_tech',
full_schema: 'User'
);
}

if (\Toolbox::hasTrait($asset_type, AssignableItem::class)) {
// Assignable assets all support multiple groups and the group links are in a separate table
if (in_array($asset_type, $CFG_GLPI['linkgroup_types'], true)) {
$schemas[$schema_name]['properties']['group'] = [
'type' => Doc\Schema::TYPE_ARRAY,
'items' => [
'type' => Doc\Schema::TYPE_OBJECT,
'x-full-schema' => 'Group',
'x-join' => [
'table' => 'glpi_groups', // The table with the desired data
'fkey' => 'groups_id',
'field' => 'id',
'ref-join' => [
'table' => 'glpi_groups_items',
'fkey' => 'id',
'field' => 'items_id',
'condition' => [
'itemtype' => $asset_type,
'type' => Group_Item::GROUP_TYPE_NORMAL,
]
$schemas[$schema_name]['properties']['group'] = [
'type' => Doc\Schema::TYPE_ARRAY,
'items' => [
'type' => Doc\Schema::TYPE_OBJECT,
'x-full-schema' => 'Group',
'x-join' => [
'table' => 'glpi_groups', // The table with the desired data
'fkey' => 'groups_id',
'field' => 'id',
'ref-join' => [
'table' => 'glpi_groups_items',
'fkey' => 'id',
'field' => 'items_id',
'condition' => [
'itemtype' => $asset_type,
'type' => Group_Item::GROUP_TYPE_NORMAL,
]
],
'properties' => [
'id' => [
'type' => Doc\Schema::TYPE_INTEGER,
'format' => Doc\Schema::FORMAT_INTEGER_INT64,
'description' => 'ID',
],
'name' => ['type' => Doc\Schema::TYPE_STRING],
]
],
'properties' => [
'id' => [
'type' => Doc\Schema::TYPE_INTEGER,
'format' => Doc\Schema::FORMAT_INTEGER_INT64,
'description' => 'ID',
],
'name' => ['type' => Doc\Schema::TYPE_STRING],
]
];
}
if (in_array($asset_type, $CFG_GLPI['linkgroup_tech_types'], true)) {
$schemas[$schema_name]['properties']['group_tech'] = [
'type' => Doc\Schema::TYPE_ARRAY,
'items' => [
'type' => Doc\Schema::TYPE_OBJECT,
'x-full-schema' => 'Group',
'x-join' => [
'table' => 'glpi_groups', // The table with the desired data
'fkey' => 'groups_id',
'field' => 'id',
'ref-join' => [
'table' => 'glpi_groups_items',
'fkey' => 'id',
'field' => 'items_id',
'condition' => [
'itemtype' => $asset_type,
'type' => Group_Item::GROUP_TYPE_TECH,
]
]
];
$schemas[$schema_name]['properties']['group_tech'] = [
'type' => Doc\Schema::TYPE_ARRAY,
'items' => [
'type' => Doc\Schema::TYPE_OBJECT,
'x-full-schema' => 'Group',
'x-join' => [
'table' => 'glpi_groups', // The table with the desired data
'fkey' => 'groups_id',
'field' => 'id',
'ref-join' => [
'table' => 'glpi_groups_items',
'fkey' => 'id',
'field' => 'items_id',
'condition' => [
'itemtype' => $asset_type,
'type' => Group_Item::GROUP_TYPE_TECH,
]
],
'properties' => [
'id' => [
'type' => Doc\Schema::TYPE_INTEGER,
'format' => Doc\Schema::FORMAT_INTEGER_INT64,
'description' => 'ID',
],
'name' => ['type' => Doc\Schema::TYPE_STRING],
]
],
'properties' => [
'id' => [
'type' => Doc\Schema::TYPE_INTEGER,
'format' => Doc\Schema::FORMAT_INTEGER_INT64,
'description' => 'ID',
],
'name' => ['type' => Doc\Schema::TYPE_STRING],
]
];
}
} else {
if (in_array($asset_type, $CFG_GLPI['linkgroup_types'], true)) {
$schemas[$schema_name]['properties']['group'] = self::getDropdownTypeSchema(
class: Group::class,
field: 'groups_id',
full_schema: 'Group'
);
}
if (in_array($asset_type, $CFG_GLPI['linkgroup_tech_types'], true)) {
$schemas[$schema_name]['properties']['group_tech'] = self::getDropdownTypeSchema(
class: Group::class,
field: 'groups_id_tech',
full_schema: 'Group'
);
}
]
];
}

if ($asset->isField('contact')) {
Expand Down
11 changes: 4 additions & 7 deletions src/Api/HL/Controller/ManagementController.php
Original file line number Diff line number Diff line change
Expand Up @@ -197,10 +197,9 @@ protected static function getRawKnownSchemas(): array
$schemas[$m_name]['properties']['environment'] = self::getDropdownTypeSchema($env_class);
}

if (in_array($m_class, $CFG_GLPI['linkuser_tech_types'], true)) {
if (in_array($m_class, $CFG_GLPI['assignable_types'], true)) {
$schemas[$m_name]['properties']['user_tech'] = self::getDropdownTypeSchema(class: User::class, field: 'users_id_tech', full_schema: 'User');
}
if (in_array($m_class, $CFG_GLPI['linkgroup_tech_types'], true)) {

$schemas[$m_name]['properties']['group_tech'] = [
'type' => Doc\Schema::TYPE_ARRAY,
'items' => [
Expand Down Expand Up @@ -230,11 +229,9 @@ protected static function getRawKnownSchemas(): array
]
]
];
}
if (in_array($m_class, $CFG_GLPI['linkuser_types'], true)) {

$schemas[$m_name]['properties']['user'] = self::getDropdownTypeSchema(class: User::class, full_schema: 'User');
}
if (in_array($m_class, $CFG_GLPI['linkgroup_types'], true)) {

$schemas[$m_name]['properties']['group'] = [
'type' => Doc\Schema::TYPE_ARRAY,
'items' => [
Expand Down
5 changes: 1 addition & 4 deletions src/Asset/AssetDefinitionManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,7 @@ private function boostrapConcreteClass(AssetDefinition $definition): void
// Register asset into configuration entries related to the capacities that cannot be disabled
$config_keys = [
'asset_types',
'linkuser_types',
'linkgroup_types',
'linkuser_tech_types',
'linkgroup_tech_types',
'assignable_types',
'location_types',
'state_types',
'ticket_types',
Expand Down
Loading

0 comments on commit 0fc09a1

Please sign in to comment.