diff --git a/CHANGELOG.md b/CHANGELOG.md index 968b5968..e06b2e79 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ### Fixed +- Fix accidental deletion of new users when adding to a ticket - Redirect users without ticket rights after escalation. ## [2.9.10] - 2024-11-27 diff --git a/inc/ticket.class.php b/inc/ticket.class.php index 6785dea7..ede3c024 100644 --- a/inc/ticket.class.php +++ b/inc/ticket.class.php @@ -29,6 +29,7 @@ */ use Glpi\Application\View\TemplateRenderer; +use Symfony\Component\VarDumper\VarDumper; if (!defined('GLPI_ROOT')) { die("Sorry. You can't access directly to this file"); @@ -108,6 +109,8 @@ function ($carry, $type) use ($item) { } } } + + self::removeAssignUsers($item); return $item; } } @@ -587,7 +590,6 @@ public static function removeAssignUsers($item, $keep_users_id = false, $type = //delete user $ticket_user->delete(['id' => $id]); - if (isset($item->input['_actors'])) { foreach ($item->input['_actors'][$types[$type]] as $key => $actor) { if ( @@ -622,7 +624,6 @@ public static function item_add_user(Ticket_User $item, $type = CommonITILActor: $ticket->getFromDB($tickets_id); $groups_id = []; - self::removeAssignUsers($ticket, $users_id, $type); // == Add user groups on modification == //check this plugin config diff --git a/tests/units/UserEscalationTest.php b/tests/units/UserEscalationTest.php new file mode 100644 index 00000000..dcc1d097 --- /dev/null +++ b/tests/units/UserEscalationTest.php @@ -0,0 +1,127 @@ +. + * ------------------------------------------------------------------------- + * @copyright Copyright (C) 2015-2023 by Escalade plugin team. + * @license GPLv2 https://www.gnu.org/licenses/gpl-2.0.html + * @link https://github.com/pluginsGLPI/escalade + * ------------------------------------------------------------------------- + */ + +namespace GlpiPlugin\Escalade\Tests\Units; + +use GlpiPlugin\Escalade\Tests\EscaladeTestCase; +use PluginEscaladeConfig; + +final class UserEscalationTest extends EscaladeTestCase +{ + public function testUserEscalationRemoveTech() + { + $this->login(); + + $config = new PluginEscaladeConfig(); + $conf = $config->find(); + $conf = reset($conf); + $config->getFromDB($conf['id']); + $this->assertGreaterThan(0, $conf['id']); + $this->assertTrue($config->update([ + 'remove_tech' => 1 + ] + $conf)); + + PluginEscaladeConfig::loadInSession(); + + $user1 = new \User(); + $user1->getFromDBbyName('glpi'); + $this->assertGreaterThan(0, $user1->getID()); + $user2 = new \User(); + $user2->getFromDBbyName('tech'); + $this->assertGreaterThan(0, $user2->getID()); + + $ticket = new \Ticket(); + $t_id = $ticket->add([ + 'name' => 'Task User change Escalation Test', + 'content' => '', + '_actors' => [ + 'assign' => [ + [ + 'items_id' => $user1->getID(), + 'itemtype' => 'User' + ] + ], + ] + ]); + + $ticket_user = new \Ticket_User(); + $this->assertEquals(1, count($ticket_user->find(['tickets_id' => $t_id, 'type' => \CommonITILActor::ASSIGN]))); + + // Update ticket with just one group + $this->assertTrue($ticket->update( + [ + 'id' => $t_id, + '_actors' => [ + 'assign' => [ + [ + 'items_id' => $user1->getID(), + 'itemtype' => 'User' + ], + [ + 'items_id' => $user2->getID(), + 'itemtype' => 'User' + ] + ], + ], + ] + )); + + $ticket_user = new \Ticket_User(); + $this->assertEquals(1, count($ticket_user->find(['tickets_id' => $t_id, 'type' => \CommonITILActor::ASSIGN]))); + $this->assertEquals(1, count($ticket_user->find(['tickets_id' => $t_id, 'type' => \CommonITILActor::ASSIGN, 'users_id' => $user2->getID()]))); + + $this->assertTrue($config->update([ + 'remove_tech' => 0 + ] + $conf)); + + PluginEscaladeConfig::loadInSession(); + + $this->assertTrue($ticket->update( + [ + 'id' => $t_id, + '_actors' => [ + 'assign' => [ + [ + 'items_id' => $user1->getID(), + 'itemtype' => 'User' + ], + [ + 'items_id' => $user2->getID(), + 'itemtype' => 'User' + ] + ], + ], + ] + )); + + $ticket_user2 = new \Ticket_User(); + $this->assertEquals(2, count($ticket_user2->find(['tickets_id' => $t_id, 'type' => \CommonITILActor::ASSIGN]))); + } +}