Skip to content

Commit

Permalink
Fix status changes on create ticket when have only append assined (us… (
Browse files Browse the repository at this point in the history
#32)

* Fix status changes on create ticket when have only append assined (user|group|supplier) in rules.
  • Loading branch information
ddurieux authored Feb 20, 2024
1 parent cf07e50 commit 1cb3244
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 11 deletions.
55 changes: 44 additions & 11 deletions inc/ticket.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -1770,17 +1770,24 @@ function prepareInputForAdd($input) {

// Replay setting auto assign if set in rules engine or by auto_assign_mode
// Do not force status if status has been set by rules
if (((isset($input["_users_id_assign"])
&& ((!is_array($input['_users_id_assign']) && $input["_users_id_assign"] > 0)
|| is_array($input['_users_id_assign']) && count($input['_users_id_assign']) > 0))
|| (isset($input["_groups_id_assign"])
&& ((!is_array($input['_groups_id_assign']) && $input["_groups_id_assign"] > 0)
|| is_array($input['_groups_id_assign']) && count($input['_groups_id_assign']) > 0))
|| (isset($input["_suppliers_id_assign"])
&& ((!is_array($input['_suppliers_id_assign']) && $input["_suppliers_id_assign"] > 0)
|| is_array($input['_suppliers_id_assign']) && count($input['_suppliers_id_assign']) > 0)))
&& (in_array($input['status'], $this->getNewStatusArray()))
&& !$this->isStatusComputationBlocked($input)) {
if ((
$this->isSomeoneAssigned($input, '_users_id_assign')
||
$this->isSomeoneAssigned($input, '_groups_id_assign')
||
$this->isSomeoneAssigned($input, '_suppliers_id_assign')
||
$this->isSomeoneAssigned($input, '_additional_assigns')
||
$this->isSomeoneAssigned($input, '_additional_groups_assigns')
||
$this->isSomeoneAssigned($input, '_additional_suppliers_assigns')
)
&&
(
in_array($input['status'], $this->getNewStatusArray())
)
&& !$this->isStatusComputationBlocked($input)) {
$input["status"] = self::ASSIGNED;
}

Expand Down Expand Up @@ -7440,4 +7447,30 @@ static function getIcon() {
public static function getItemLinkClass(): string {
return Item_Ticket::class;
}

/**
* Check if input contains a person or a group assigned.
*
* @param array $input
*
* @return boolean
*/
private function isSomeoneAssigned(array $input, $key) {
return (
isset($input[$key])
&&
(
(
!is_array($input[$key])
&& $input[$key] > 0
)
||
(
is_array($input[$key])
&& count($input[$key]) > 0
)
)
);
}

}
21 changes: 21 additions & 0 deletions tests/functionnal/Ticket.php
Original file line number Diff line number Diff line change
Expand Up @@ -2502,6 +2502,27 @@ protected function statusComputationOnCreateProvider() {
],
'expected' => \CommonITILObject::WAITING, // status not changed as not "new"
],
[
'input' => [
'_additional_assigns' => ['4'], // "tech"
'status' => \CommonITILObject::INCOMING,
],
'expected' => \CommonITILObject::ASSIGNED, // incoming changed to assign as actors are set
],
[
'input' => [
'_additional_groups_assigns' => [$group_id], // "group"
'status' => \CommonITILObject::INCOMING,
],
'expected' => \CommonITILObject::ASSIGNED, // incoming changed to assign as groups are set
],
[
'input' => [
'_additional_suppliers_assigns' => ['1'], // "supplier"
'status' => \CommonITILObject::INCOMING,
],
'expected' => \CommonITILObject::ASSIGNED, // incoming changed to assign as suppliers are set
],
];
}

Expand Down

0 comments on commit 1cb3244

Please sign in to comment.