Skip to content

Commit

Permalink
Fix parent status overhide with rule using followup template action a…
Browse files Browse the repository at this point in the history
…nd status (#18773)

* Fix parent status overhide before rule

* Update src/CommonITILObject.php

Co-authored-by: Stanislas <[email protected]>

* Update src/Features/ParentStatus.php

Co-authored-by: Stanislas <[email protected]>

* Fix unit tests

* Fix unit tests

* Fix units tests

* Add new units tests

* Increase unit test

* Fix comments

---------

Co-authored-by: Stanislas <[email protected]>
  • Loading branch information
Lainow and stonebuzz authored Jan 24, 2025
1 parent 8b77042 commit abd6066
Show file tree
Hide file tree
Showing 4 changed files with 179 additions and 10 deletions.
100 changes: 100 additions & 0 deletions phpunit/functional/RuleTicketTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@

namespace tests\units;

use CommonITILObject;
use CommonITILValidation;
use Contract;
use ContractType;
Expand Down Expand Up @@ -3652,4 +3653,103 @@ public function testWriterCriterion()
$this->assertEquals($user_id, (int)$ticket->getField('users_id_recipient'));
$this->assertEquals($requesttypes_id, (int)$ticket->getField('requesttypes_id'));
}

public function testDoNotComputeStatusFollowupWithRule()
{
$this->login('glpi', 'glpi');

$followuptemplate = new \ITILFollowupTemplate();
$templateid = $followuptemplate->add($templateinput = [
'name' => 'followuptemplate_' . __FUNCTION__,
'content' => 'Test',
]);
$this->checkInput($followuptemplate, $templateid, $templateinput);

// Create the rule to change status and add a followup template
$ruleticket = new \RuleTicket();
$rulecrit = new \RuleCriteria();
$ruleaction = new \RuleAction();

$ruletid = $ruleticket->add($ruletinput = [
'name' => 'test do not compute status followup',
'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' => 'name',
'condition' => \Rule::PATTERN_CONTAIN,
'pattern' => 'test',
]);
$this->checkInput($rulecrit, $crit_id, $crit_input);

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

$act2_id = $ruleaction->add($act2_input = [
'rules_id' => $ruletid,
'action_type' => 'append',
'field' => 'itilfollowup_template',
'value' => $templateid,
]);
$this->checkInput($ruleaction, $act2_id, $act2_input);

$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();
// Create ticket with two actors (requester and technician)
$tickets_id = $ticket->add([
'name' => 'test ticket ' . __FUNCTION__,
'content' => __FUNCTION__,
'_actors' => [
'requester' => [
[
'items_id' => $user1->getID(),
'itemtype' => 'User'
]
],
'assign' => [
[
'items_id' => $user2->getID(),
'itemtype' => 'User'
]
],
]
]);
$this->assertGreaterThan(0, $tickets_id);

$ticket = new \Ticket();
$ticket->getFromDB($tickets_id);

$this->assertEquals(\CommonITILObject::WAITING, $ticket->fields['status']);

// Create followup without _do_not_compute_status
$this->createItem('ITILFollowup', [
'itemtype' => $ticket::getType(),
'items_id' => $tickets_id,
'content' => 'simple followup content',
'date' => '2015-01-01 00:00:00',
]);

$ticket = new \Ticket();
$ticket->getFromDB($tickets_id);

$this->assertEquals(\CommonITILObject::ASSIGNED, $ticket->fields['status']);
}
}
61 changes: 61 additions & 0 deletions phpunit/functional/TicketTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7813,4 +7813,65 @@ public function testCanAssign()
$ticket->loadActors();
$this->assertEquals(0, $ticket->countUsers(\CommonITILActor::ASSIGN));
}

public function testDoNotComputeStatusFollowup()
{
$this->login('glpi', 'glpi');

$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();
// Create ticket with two actors (requester and technician)
$tickets_id = $ticket->add([
'name' => __FUNCTION__,
'content' => __FUNCTION__,
'status' => \CommonITILObject::WAITING,
'_actors' => [
'requester' => [
[
'items_id' => $user1->getID(),
'itemtype' => 'User'
]
],
'assign' => [
[
'items_id' => $user2->getID(),
'itemtype' => 'User'
]
],
]
]);
$this->assertGreaterThan(0, $tickets_id);

$this->createItem('ITILFollowup', [
'itemtype' => $ticket::getType(),
'items_id' => $tickets_id,
'content' => 'do not compute status followup content',
'date' => '2015-01-01 00:00:00',
'_do_not_compute_status' => 1
]);

$ticket = new \Ticket();
$ticket->getFromDB($tickets_id);

$this->assertEquals(\CommonITILObject::WAITING, $ticket->fields['status']);

$this->createItem('ITILFollowup', [
'itemtype' => $ticket::getType(),
'items_id' => $tickets_id,
'content' => 'simple followup content',
'date' => '2015-01-01 00:00:00',
]);

$ticket = new \Ticket();
$ticket->getFromDB($tickets_id);

$this->assertEquals(\CommonITILObject::ASSIGNED, $ticket->fields['status']);
}
}
10 changes: 6 additions & 4 deletions src/CommonITILObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -8206,14 +8206,16 @@ public function handleITILFollowupTemplateInput(): void

// Add tasks in itilfollowup template if defined in itiltemplate
foreach ($this->input['_itilfollowuptemplates_id'] as $fup_templates_id) {
// Insert new followup from template
$fup = new ITILFollowup();
$fup->add([
$values = [
'_itilfollowuptemplates_id' => $fup_templates_id,
'itemtype' => $this->getType(),
'items_id' => $this->getID(),
'_disablenotif' => true,
]);
'_do_not_compute_status' => $this->input['_do_not_compute_status'] ?? 0,
];
// Insert new followup from template
$fup = new ITILFollowup();
$fup->add($values);
}
}

Expand Down
18 changes: 12 additions & 6 deletions src/Features/ParentStatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,12 @@ public function updateParentStatus(CommonITILObject $parentitem, array $input):
) {
//check if lifecycle allowed new status
if (
Session::isCron()
|| Session::getCurrentInterface() == "helpdesk"
|| $parentitem::isAllowedStatus($parentitem->fields["status"], CommonITILObject::ASSIGNED)
(
Session::isCron()
|| Session::getCurrentInterface() == "helpdesk"
|| $parentitem::isAllowedStatus($parentitem->fields["status"], CommonITILObject::ASSIGNED)
)
&& (!isset($input['_do_not_compute_status']) || !$input['_do_not_compute_status'])
) {
$needupdateparent = true;
// If begin date is defined, the status must be planned if it exists, rather than assigned.
Expand All @@ -150,9 +153,12 @@ public function updateParentStatus(CommonITILObject $parentitem, array $input):
} else {
//check if lifecycle allowed new status
if (
Session::isCron()
|| Session::getCurrentInterface() == "helpdesk"
|| $parentitem::isAllowedStatus($parentitem->fields["status"], CommonITILObject::INCOMING)
(
Session::isCron()
|| Session::getCurrentInterface() == "helpdesk"
|| $parentitem::isAllowedStatus($parentitem->fields["status"], CommonITILObject::INCOMING)
)
&& (!isset($input['_do_not_compute_status']) || !$input['_do_not_compute_status'])
) {
$needupdateparent = true;
$update['status'] = CommonITILObject::INCOMING;
Expand Down

0 comments on commit abd6066

Please sign in to comment.