diff --git a/CHANGELOG.md b/CHANGELOG.md index 132974f5..44f58c6f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,9 +15,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - Fix flaky escalation test on solve/reject-solution data sets - CI: fix Psalm cache directory, drop the stray `glpi-project/tools` composer dependency, declare a unique composer autoloader suffix +- Fix form submission error when 'Use technician group on ticket creation' is enabled - Simplify group reassignment to a single actor diff, relying on GLPI core's status preservation on simultaneous actor removal/addition - ## [2.10.8] 2026-09-11 ### Fixed diff --git a/inc/ticket.class.php b/inc/ticket.class.php index a52b3fe9..77059097 100644 --- a/inc/ticket.class.php +++ b/inc/ticket.class.php @@ -629,9 +629,11 @@ public static function assignUserGroup(Ticket $ticket) return false; } + // `_users_id_assign` may be either a single ID or an array of IDs + $users_id_assign = (int) current(array_filter((array) ($ticket->input['_users_id_assign'] ?? []))); + if ( - isset($ticket->input['_users_id_assign']) - && $ticket->input['_users_id_assign'] > 0 + $users_id_assign > 0 && (!isset($ticket->input['_groups_id_assign']) || empty($ticket->input['_groups_id_assign'])) ) { @@ -640,7 +642,7 @@ public static function assignUserGroup(Ticket $ticket) $ticket->input['_groups_id_assign'] = PluginEscaladeUser::getTechnicianGroup( $ticket->input['entities_id'], - current($ticket->input['_users_id_assign']), + $users_id_assign, true, ); } else { @@ -648,7 +650,7 @@ public static function assignUserGroup(Ticket $ticket) $ticket->input['_groups_id_assign'] = PluginEscaladeUser::getTechnicianGroup( $ticket->input['entities_id'], - current($ticket->input['_users_id_assign']), + $users_id_assign, false, ); } diff --git a/tests/Units/TicketTest.php b/tests/Units/TicketTest.php index 5531912e..019348a5 100644 --- a/tests/Units/TicketTest.php +++ b/tests/Units/TicketTest.php @@ -1724,4 +1724,60 @@ public function testKeepNewAssignUsersFlagIsClearedWhenFollowUpNeverHappens() 'The keep-users flag must not survive past the request when the follow-up group add never happens', ); } + + /** + * When the technician is auto-assigned by the core from the ITIL category, + * `_users_id_assign` is a scalar ID (not an array): the technician group + * must still be assigned on ticket creation. + */ + public function testAssignUserGroupOnCreationWithTechnicianFromCategory() + { + $this->initConfig([ + 'use_assign_user_group' => 1, + 'use_assign_user_group_creation' => 1, + ]); + + $this->updateItem('Entity', 0, [ + 'auto_assign_mode' => Entity::AUTO_ASSIGN_CATEGORY_HARDWARE, + ]); + + $tech = new User(); + $tech->getFromDBbyName('tech'); + $this->assertGreaterThan(0, $tech->getID()); + + $group = $this->createItem('Group', [ + 'name' => 'Technician group', + 'entities_id' => 0, + 'is_recursive' => 1, + ]); + $this->createItem('Group_User', [ + 'users_id' => $tech->getID(), + 'groups_id' => $group->getID(), + ]); + + $itil_cat = $this->createItem('ITILCategory', [ + 'name' => 'Cat with technician', + 'users_id' => $tech->getID(), + 'entities_id' => 0, + ]); + + $ticket = $this->createItem('Ticket', [ + 'name' => 'Ticket without assigned technician', + 'content' => 'Content', + 'entities_id' => 0, + 'itilcategories_id' => $itil_cat->getID(), + ]); + $ticket_id = $ticket->getID(); + + $this->assertEquals( + 1, + countElementsInTable(Ticket_User::getTable(), ['tickets_id' => $ticket_id, 'type' => CommonITILActor::ASSIGN, 'users_id' => $tech->getID()]), + 'Technician from the category should be assigned', + ); + $this->assertEquals( + 1, + countElementsInTable(Group_Ticket::getTable(), ['tickets_id' => $ticket_id, 'type' => CommonITILActor::ASSIGN, 'groups_id' => $group->getID()]), + 'Technician group should be assigned', + ); + } }