Skip to content

Commit

Permalink
Fix(rule ticket): User_id_recipient criterion
Browse files Browse the repository at this point in the history
  • Loading branch information
Rom1-B authored and trasher committed Sep 16, 2024
1 parent a7d2e12 commit f9a88ab
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 5 deletions.
51 changes: 51 additions & 0 deletions install/migrations/update_10.0.16_to_10.0.17/rule_tickets.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

/**
* ---------------------------------------------------------------------
*
* GLPI - Gestionnaire Libre de Parc Informatique
*
* http://glpi-project.org
*
* @copyright 2015-2024 Teclib' and contributors.
* @copyright 2003-2014 by the INDEPNET Development Team.
* @licence https://www.gnu.org/licenses/gpl-3.0.html
*
* ---------------------------------------------------------------------
*
* LICENSE
*
* This file is part of GLPI.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* ---------------------------------------------------------------------
*/

/**
* @var \DBmysql $DB
* @var \Migration $migration
*/

$migration->addPostQuery(
$DB->buildUpdate(
'glpi_rulecriterias',
[
'criteria' => 'users_id_recipient',
],
[
'criteria' => '_users_id_recipient',
]
)
);
55 changes: 55 additions & 0 deletions phpunit/functional/RuleTicketTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3597,4 +3597,59 @@ public function testDefaultProfileCriterion(): void
// Check if the location "Test location" is assigned
$this->assertEquals($location2->getID(), $ticket->fields['locations_id']);
}

/**
* Test writer criterion in rules.
*/
public function testWriterCriterion()
{
$this->login();

$user_id = (int) getItemByTypeName('User', '_test_user', true);

$requesttypes_id = $this->createItem('RequestType', [
'name' => 'requesttype_' . __METHOD__,
])->getID();

// Create rule
$ruleticket = new \RuleTicket();
$rulecrit = new \RuleCriteria();
$ruleaction = new \RuleAction();

$ruletid = $ruleticket->add($ruletinput = [
'name' => 'test writer criterion',
'match' => 'AND',
'is_active' => 1,
'sub_type' => 'RuleTicket',
'condition' => \RuleTicket::ONADD,
'is_recursive' => 1,
]);
$this->checkInput($ruleticket, $ruletid, $ruletinput);

$crit_id = $rulecrit->add($crit_input = [
'rules_id' => $ruletid,
'criteria' => 'users_id_recipient',
'condition' => \Rule::PATTERN_IS,
'pattern' => $user_id,
]);
$this->checkInput($rulecrit, $crit_id, $crit_input);

$act_id = $ruleaction->add($act_input = [
'rules_id' => $ruletid,
'action_type' => 'assign',
'field' => 'requesttypes_id',
'value' => $requesttypes_id,
]);
$this->checkInput($ruleaction, $act_id, $act_input);

// Check ticket that trigger rule on creation
$ticket = new \Ticket();
$tickets_id = $ticket->add($ticket_input = [
'name' => __METHOD__,
'content' => __METHOD__,
]);
$this->checkInput($ticket, $tickets_id, $ticket_input);
$this->assertEquals($user_id, (int)$ticket->getField('users_id_recipient'));
$this->assertEquals($requesttypes_id, (int)$ticket->getField('requesttypes_id'));
}
}
10 changes: 5 additions & 5 deletions src/RuleTicket.php
Original file line number Diff line number Diff line change
Expand Up @@ -579,11 +579,11 @@ public function getCriterias()
$criterias['type']['linkfield'] = 'type';
$criterias['type']['type'] = 'dropdown_tickettype';

$criterias['_users_id_recipient']['table'] = 'glpi_users';
$criterias['_users_id_recipient']['field'] = 'name';
$criterias['_users_id_recipient']['name'] = __('Writer');
$criterias['_users_id_recipient']['linkfield'] = '_users_id_recipient';
$criterias['_users_id_recipient']['type'] = 'dropdown_users';
$criterias['users_id_recipient']['table'] = 'glpi_users';
$criterias['users_id_recipient']['field'] = 'name';
$criterias['users_id_recipient']['name'] = __('Writer');
$criterias['users_id_recipient']['linkfield'] = 'users_id_recipient';
$criterias['users_id_recipient']['type'] = 'dropdown_users';

$criterias['_users_id_requester']['table'] = 'glpi_users';
$criterias['_users_id_requester']['field'] = 'name';
Expand Down

0 comments on commit f9a88ab

Please sign in to comment.