Skip to content

Commit

Permalink
Fixed ticket creation with closed status to exclude technician
Browse files Browse the repository at this point in the history
fixes #16381
  • Loading branch information
Lainow authored Mar 4, 2024
1 parent f150b56 commit 09406fa
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 27 deletions.
3 changes: 2 additions & 1 deletion src/CommonITILObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -909,6 +909,7 @@ public function canAssign()
if (
isset($this->fields['is_deleted']) && ($this->fields['is_deleted'] == 1)
|| isset($this->fields['status']) && in_array($this->fields['status'], $this->getClosedStatusArray())
|| isset($this->input['status']) && in_array($this->input['status'], $this->getClosedStatusArray())
) {
return false;
}
Expand Down Expand Up @@ -9797,7 +9798,7 @@ protected function transformActorsInput(array $input): array
) {
foreach (['requester', 'observer', 'assign'] as $actor_type) {
$actor_type_value = constant(CommonITILActor::class . '::' . strtoupper($actor_type));
if ($actor_type_value === CommonITILActor::ASSIGN && !$this->canAssign()) {
if ($actor_type_value === CommonITILActor::ASSIGN && !$this->canAssign() && !$this->isNewItem()) {
continue;
}
if ($actor_type_value !== CommonITILActor::ASSIGN && !$this->isNewItem() && !$this->canUpdateItem()) {
Expand Down
1 change: 1 addition & 0 deletions src/Ticket.php
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ public function canAssign()
if (
isset($this->fields['is_deleted']) && ($this->fields['is_deleted'] == 1)
|| isset($this->fields['status']) && in_array($this->fields['status'], $this->getClosedStatusArray())
|| isset($this->input['status']) && in_array($this->input['status'], $this->getClosedStatusArray())
) {
return false;
}
Expand Down
89 changes: 63 additions & 26 deletions tests/functional/Ticket.php
Original file line number Diff line number Diff line change
Expand Up @@ -5062,35 +5062,17 @@ public function testCronSurveyCreation(): void
}
}

public function testAddAssignWithoutUpdateRight()
public function testAddAssignWhenTicketClosed()
{
$this->login();

$ticket = new \Ticket();
$tickets_id = $ticket->add([
'name' => 'testAddAssignWithoutUpdateRight',
'content' => 'testAddAssignWithoutUpdateRight',
'_skip_auto_assign' => true,
]);
$this->integer($tickets_id)->isGreaterThan(0);

$ticket->loadActors();
$this->integer($ticket->countUsers(\CommonITILActor::ASSIGN))->isEqualTo(0);
$this->integer($ticket->countUsers(\CommonITILActor::REQUESTER))->isEqualTo(0);

$this->changeTechRight(\Ticket::ASSIGN | \Ticket::READALL);
$this->boolean($ticket->canUpdateItem())->isFalse();
$this->boolean((bool) $ticket->canAssign())->isTrue();
$this->boolean($ticket->update([
'id' => $tickets_id,
'name' => 'testAddAssignWhenTicketClosed',
'content' => 'testAddAssignWhenTicketClosed',
'status' => \CommonITILObject::CLOSED,
'_actors' => [
'requester' => [
[
'itemtype' => 'User',
'items_id' => getItemByTypeName('User', 'post-only', true),
'use_notification' => 0,
'alternative_email' => '',
],
[
'itemtype' => 'User',
'items_id' => getItemByTypeName('User', 'tech', true),
Expand All @@ -5107,12 +5089,14 @@ public function testAddAssignWithoutUpdateRight()
]
],
],
]))->isTrue();
]);
$this->integer($tickets_id)->isGreaterThan(0);

$closedticket = $ticket->getFromDB($tickets_id);
$this->boolean($closedticket)->isTrue();
$ticket->loadActors();
// Verify new assignee was added
$this->integer($ticket->countUsers(\CommonITILActor::ASSIGN))->isEqualTo(1);
// Verify new requester wasn't added
$this->integer($ticket->countUsers(\CommonITILActor::REQUESTER))->isEqualTo(0);
$this->integer($ticket->countUsers(\CommonITILActor::REQUESTER))->isEqualTo(1);
}

public function testAddAssignWithoutAssignRight()
Expand Down Expand Up @@ -6886,4 +6870,57 @@ public function testRestrictedDropdownValues()
$this->array($values['results'])->size->isGreaterThan(1);
$this->boolean($fn_dropdown_has_id($values['results'], $not_my_tickets_id))->isTrue();
}

public function testAddAssignWithoutUpdateRight()
{
$this->login();

$ticket = new \Ticket();
$tickets_id = $ticket->add([
'name' => 'testAddAssignWithoutUpdateRight',
'content' => 'testAddAssignWithoutUpdateRight',
'_skip_auto_assign' => true,
]);
$this->integer($tickets_id)->isGreaterThan(0);

$ticket->loadActors();
$this->integer($ticket->countUsers(\CommonITILActor::ASSIGN))->isEqualTo(0);
$this->integer($ticket->countUsers(\CommonITILActor::REQUESTER))->isEqualTo(0);

$this->changeTechRight(\Ticket::ASSIGN | \Ticket::READALL);
$this->boolean($ticket->canUpdateItem())->isFalse();
$this->boolean((bool) $ticket->canAssign())->isTrue();
$this->boolean($ticket->update([
'id' => $tickets_id,
'_actors' => [
'requester' => [
[
'itemtype' => 'User',
'items_id' => getItemByTypeName('User', 'post-only', true),
'use_notification' => 0,
'alternative_email' => '',
],
[
'itemtype' => 'User',
'items_id' => getItemByTypeName('User', 'tech', true),
'use_notification' => 0,
'alternative_email' => '',
]
],
'assign' => [
[
'itemtype' => 'User',
'items_id' => getItemByTypeName('User', 'tech', true),
'use_notification' => 0,
'alternative_email' => '',
]
],
],
]))->isTrue();
$ticket->loadActors();
// Verify new assignee was added
$this->integer($ticket->countUsers(\CommonITILActor::ASSIGN))->isEqualTo(1);
// Verify new requester wasn't added
$this->integer($ticket->countUsers(\CommonITILActor::REQUESTER))->isEqualTo(0);
}
}

0 comments on commit 09406fa

Please sign in to comment.