Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions phpunit/functional/WebhookTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -297,4 +297,17 @@ public function testWithHLAPIDisabled(): void
// The main purpose is to test the internal authentication middleware.
$this->assertNotNull($webhook->getResultForPath('/Administration/User/' . $users_id, 'new', 'User', $users_id));
}

public function testGetMonacoSuggestions()
{
$itemtypes = \Webhook::getItemtypesDropdownValues();

foreach ($itemtypes as $types) {
$this->assertIsArray($types);
foreach ($types as $itemtype => $label) {
$suggestions = \Webhook::getMonacoSuggestions($itemtype);
$this->assertNotEmpty($suggestions, "Missing suggestions for $itemtype");
}
}
}
}
26 changes: 20 additions & 6 deletions src/Webhook.php
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,6 @@ public static function getAPIItemtypeData(): array
ChangeTask::class => ['parent' => Change::class],
ProblemTask::class => ['parent' => Problem::class],
ITILFollowup::class => [], // All main types can be the parent
Document_Item::class => [],
ITILSolution::class => [],
TicketValidation::class => ['parent' => Ticket::class],
],
Expand All @@ -385,6 +384,9 @@ public static function getAPIItemtypeData(): array
Contract::class, Database::class, Datacenter::class, Document::class, Domain::class,
SoftwareLicense::class, Line::class, Supplier::class,
],
'subtypes' => [
Document_Item::class => ['parent' => Document::class],
],
],
];

Expand Down Expand Up @@ -438,9 +440,9 @@ public static function getAPIItemtypeData(): array
}

/**
* Return a list of GLPI itemtypes availabel through HL API.
* Return a list of GLPI itemtypes available through HL API.
*
* @return array
* @return array<array>
*/
public static function getItemtypesDropdownValues(): array
{
Expand Down Expand Up @@ -917,10 +919,19 @@ public static function getAPISchemaBySupportedItemtype(string $itemtype): ?array
$controller_class = $controller;
break;
}

if (isset($categories['subtypes']) && array_key_exists($itemtype, $categories['subtypes'])) {
$schema_name = $categories['subtypes'][$itemtype]['name'];
$schema_name = $categories['main'][$categories['subtypes'][$itemtype]['parent']]['name'] . $schema_name;
$controller_class = $controller;
$schema_name = $categories['subtypes'][$itemtype]['name'];

if (
array_key_exists('parent', $categories['subtypes'][$itemtype])
&& array_key_exists($categories['subtypes'][$itemtype]['parent'], $categories['main'])
&& array_key_exists('name', $categories['main'][$categories['subtypes'][$itemtype]['parent']])
) {
$schema_name = $categories['main'][$categories['subtypes'][$itemtype]['parent']]['name'] . $schema_name;
}

break;
}
}
Expand All @@ -939,6 +950,9 @@ public static function getMonacoSuggestions(?string $itemtype): array
return [];
}
$schema = self::getAPISchemaBySupportedItemtype($itemtype);
if (is_null($schema)) {
return [];
}
$props = Doc\Schema::flattenProperties($schema['properties'], 'item.');
$parent_schema = self::getParentItemSchema($itemtype);
$parent_props = $parent_schema !== [] ? Doc\Schema::flattenProperties($parent_schema['properties'], 'parent_item.') : [];
Expand All @@ -953,7 +967,7 @@ public static function getMonacoSuggestions(?string $itemtype): array
$subtype_labels = [];
if (isset($parent_schema['x-subtypes'])) {
foreach ($parent_schema['x-subtypes'] as $subtype) {
$subtype_labels[$subtype] = $subtype['itemtype']::getTypeName(1);
$subtype_labels[$subtype['itemtype']] = $subtype['itemtype']::getTypeName(1);
}
}
foreach ($props as $prop_name => $prop_data) {
Expand Down