diff --git a/src/CommonITILObject.php b/src/CommonITILObject.php index 19792970ee0..e5154fb91c0 100644 --- a/src/CommonITILObject.php +++ b/src/CommonITILObject.php @@ -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; } @@ -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()) { diff --git a/src/Ticket.php b/src/Ticket.php index db613edabed..1fc9f03a738 100644 --- a/src/Ticket.php +++ b/src/Ticket.php @@ -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; } diff --git a/tests/functional/Ticket.php b/tests/functional/Ticket.php index 0645862105e..4063b7a7d8a 100644 --- a/tests/functional/Ticket.php +++ b/tests/functional/Ticket.php @@ -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), @@ -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() @@ -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); + } }