Skip to content
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 75 additions & 1 deletion phpunit/functional/TicketTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2909,9 +2909,83 @@ public function testAssignChangeStatus()
//check ticket creation
$this->assertTrue($ticket_user->getFromDB($ticket_user->getId()));

// check status (should still be ASSIGNED)
$this->assertTrue($ticket->getFromDB($tickets_id));
$this->assertEquals(\CommonITILObject::ASSIGNED, (int) $ticket->fields['status']);

// remove associated user
$this->assertTrue($ticket->update([
'id' => $tickets_id,
'_actors' => [
'assign' => []
]
]));
// check status (should be INCOMING)
$this->assertTrue($ticket->getFromDB($tickets_id));
$this->assertEquals(\CommonITILObject::INCOMING, (int) $ticket->fields['status']);

// add associated user
$this->assertTrue($ticket->update([
'id' => $tickets_id,
'_actors' => [
'assign' => [
[
'itemtype' => 'User',
'items_id' => 2,
'use_notification' => 0,
'default_email' => '',
'alternative_email' => ''
]
]
]
]));
// check status (should be ASSIGNED)
$this->assertTrue($ticket->getFromDB($tickets_id));
$this->assertEquals(\CommonITILObject::ASSIGNED, (int) $ticket->fields['status']);

// replace associated user
$this->assertTrue($ticket->update([
'id' => $tickets_id,
'_actors' => [
'assign' => [
[
'itemtype' => 'User',
'items_id' => 3,
'use_notification' => 0,
'default_email' => '',
'alternative_email' => ''
]
]
]
]));
// check status (should still be ASSIGNED)
$this->assertTrue($ticket->getFromDB($tickets_id));
$this->assertEquals(\CommonITILObject::ASSIGNED, (int)$ticket->fields['status']);
$this->assertEquals(\CommonITILObject::ASSIGNED, (int) $ticket->fields['status']);

// change status to WAITING
$this->assertTrue($ticket->update([
'id' => $tickets_id,
'status' => \CommonITILObject::WAITING
]));

// replace associated user
$this->assertTrue($ticket->update([
'id' => $tickets_id,
'_actors' => [
'assign' => [
[
'itemtype' => 'User',
'items_id' => 2,
'use_notification' => 0,
'default_email' => '',
'alternative_email' => ''
]
]
]
]));
// check status (should still be WAITING)
$this->assertTrue($ticket->getFromDB($tickets_id));
$this->assertEquals(\CommonITILObject::WAITING, (int) $ticket->fields['status']);
}

public function testClosedTicketTransfer()
Expand Down
9 changes: 9 additions & 0 deletions src/CommonITILActor.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ public function post_deleteFromDB()
&& ($item->countGroups(self::ASSIGN) === 0)
&& ((int) $item->fields['status'] !== CommonITILObject::CLOSED)
&& ((int) $item->fields['status'] !== CommonITILObject::SOLVED)
&& !isset($this->input['_do_not_compute_status'])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure this is related to this PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This prevents the ticket status from changing temporarily to new during the short period when there are no technicians, between deletion and addition.

) {
$status = CommonITILObject::INCOMING;
if (in_array((int) $item->fields['status'], Change::getNewStatusArray(), true)) {
Expand All @@ -161,6 +162,13 @@ public function post_deleteFromDB()
'id' => $this->fields[static::getItilObjectForeignKey()],
'status' => $status
]);
if ($donotif) {
$options = [];
if (isset($this->fields['users_id'])) {
$options = ['_old_user' => $this->fields];
NotificationEvent::raiseEvent('del_assign_user', $item, $options);
}
}
} else {
$item->updateDateMod($this->fields[static::getItilObjectForeignKey()]);

Expand All @@ -170,6 +178,7 @@ public function post_deleteFromDB()
$options = ['_old_user' => $this->fields];
}
NotificationEvent::raiseEvent("update", $item, $options);
NotificationEvent::raiseEvent('del_assign_user', $item, $options);
}
}
}
Expand Down
44 changes: 28 additions & 16 deletions src/CommonITILObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -9320,6 +9320,34 @@ protected function updateActors(bool $disable_notifications = false)
}
}

$do_not_compute_status = false;
foreach ($added as $actor) {
if ($actor['type'] === CommonITILActor::ASSIGN) {
$do_not_compute_status = true;
}
}

// Process deleted actors
foreach ($actor_itemtypes as $actor_itemtype) {
$actor_fkey = getForeignKeyFieldForItemType($actor_itemtype);
$actors_deleted_input_key = sprintf('_%s_%s_deleted', $actor_fkey, $actor_type);

$deleted = array_key_exists($actors_deleted_input_key, $this->input)
? $this->input[$actors_deleted_input_key]
: [];
foreach ($deleted as $actor) {
$actor_obj = $this->getActorObjectForItem($actor['itemtype']);
if ($do_not_compute_status) {
$actor_obj->delete([
'id' => $actor['id'],
'_do_not_compute_status' => $do_not_compute_status,
]);
} else {
$actor_obj->delete(['id' => $actor['id']]);
}
}
}

// Add new actors
foreach ($added as $actor) {
$actor_obj = $this->getActorObjectForItem($actor['itemtype']);
Expand Down Expand Up @@ -9355,22 +9383,6 @@ protected function updateActors(bool $disable_notifications = false)
}
}

// Process deleted actors
foreach ($actor_types as $actor_type) {
foreach ($actor_itemtypes as $actor_itemtype) {
$actor_fkey = getForeignKeyFieldForItemType($actor_itemtype);
$actors_deleted_input_key = sprintf('_%s_%s_deleted', $actor_fkey, $actor_type);

$deleted = array_key_exists($actors_deleted_input_key, $this->input)
? $this->input[$actors_deleted_input_key]
: [];
foreach ($deleted as $actor) {
$actor_obj = $this->getActorObjectForItem($actor['itemtype']);
$actor_obj->delete(['id' => $actor['id']]);
}
}
}

// We just updated actors, clear any cached data
$this->clearLazyLoadedActors();
}
Expand Down
6 changes: 5 additions & 1 deletion src/NotificationTargetCommonITILObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ public function getEvents()
'pendingreason_add' => __('Pending reason added'),
'pendingreason_del' => __('Pending reason removed'),
'pendingreason_close' => __('Pending reason auto close'),
'del_assign_user' => __('Deletion of a user in assignees'),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMHO, we should add a remove_xxx event for all possible actor type (e.g. requester user, requester group, observer user, observer group, assigned user, assigned group and assigned suplier).

If we add this only for assigned users, I am pretty sure that someone will ask for the same feature for another actor type as soon as the feature will be released.

];

asort($events);
Expand Down Expand Up @@ -884,7 +885,10 @@ public function addAdditionalTargets($event = '')
return; // Do not propose more targets
}

if ($event == 'update') {
if (
$event == 'update' ||
$event == 'del_assign_user'
) {
$this->addTarget(
Notification::OLD_TECH_IN_CHARGE,
__('Former technician in charge of the ticket')
Expand Down