Skip to content

fix(ticket): auto-assign tech with ITIL category launch rule #19694

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: 10.0/bugfixes
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
98 changes: 98 additions & 0 deletions phpunit/functional/TicketTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
use Profile;
use Profile_User;
use ProfileRight;
use RuleTicket;
use Search;
use Supplier;
use Supplier_Ticket;
Expand Down Expand Up @@ -6445,6 +6446,103 @@ public function testAssignFromCategoryOrItem(): void
}
}

public function testAssignFromCategoryOrItemExecuteRule(): void
{
$tech_id = getItemByTypeName('User', 'tech', true);

$entity_id = getItemByTypeName('Entity', '_test_root_entity', true);
$this->login();

$this->updateItem(
\Entity::class,
$entity_id,
[
'auto_assign_mode' => Entity::AUTO_ASSIGN_HARDWARE_CATEGORY,
]
);

$group_tech = $this->createItem(
Group::class,
[
'name' => 'Group TECH',
'entities_id' => $entity_id,
]
);

$group_observer = $this->createItem(
Group::class,
[
'name' => 'Group Observer',
'entities_id' => $entity_id,
]
);

$itilcategory = $this->createItem(
ITILCategory::class,
[
'name' => 'Cat1',
'entities_id' => $entity_id,
'users_id' => $tech_id,
'groups_id' => $group_tech->getID(),
]
);

$rule = $this->createItem(
\Rule::class,
[
'name' => RuleTicket::class,
'sub_type' => RuleTicket::class,
'match' => \Rule::AND_MATCHING,
'is_active' => 1,
'condition' => 1,
'entities_id' => $entity_id,
]
);

$this->createItem(
\RuleAction::class,
[
'rules_id' => $rule->getID(),
'action_type' => 'assign',
'field' => '_groups_id_observer',
'value' => $group_observer->getID(),
]
);

$this->createItem(
\RuleCriteria::class,
[
'rules_id' => $rule->getID(),
'criteria' => '_groups_id_assign',
'condition' => \Rule::PATTERN_EXISTS,
'pattern' => $group_tech->getID(),
]
);

$ticket = $this->createItem(
Ticket::class,
[
'name' => 'Ticket',
'content' => 'content',
'entities_id' => $entity_id,
'itilcategories_id' => $itilcategory->getID(),
]
);

$group_ticket = new Group_Ticket();
$this->assertEquals(1, count($group_ticket->find([
'tickets_id' => $ticket->getID(),
'groups_id' => $group_tech->getID(),
'type' => CommonITILActor::ASSIGN,
])));

$this->assertEquals(1, count($group_ticket->find([
'tickets_id' => $ticket->getID(),
'groups_id' => $group_observer->getID(),
'type' => CommonITILActor::OBSERVER,
])));
}

protected function requestersEntitiesProvider(): iterable
{
$this->login();
Expand Down
48 changes: 24 additions & 24 deletions src/Ticket.php
Original file line number Diff line number Diff line change
Expand Up @@ -1920,6 +1920,30 @@ public function prepareInputForAdd($input)
}
}

if (!isset($input['_skip_auto_assign']) || $input['_skip_auto_assign'] === false) {
// Manage auto assign
$auto_assign_mode = Entity::getUsedConfig('auto_assign_mode', $input['entities_id']);

switch ($auto_assign_mode) {
case Entity::CONFIG_NEVER:
break;

case Entity::AUTO_ASSIGN_HARDWARE_CATEGORY:
// Auto assign tech/group from hardware
$input = $this->setTechAndGroupFromHardware($input, $item);
// Auto assign tech/group from Category
$input = $this->setTechAndGroupFromItilCategory($input);
break;

case Entity::AUTO_ASSIGN_CATEGORY_HARDWARE:
// Auto assign tech/group from Category
$input = $this->setTechAndGroupFromItilCategory($input);
// Auto assign tech/group from hardware
$input = $this->setTechAndGroupFromHardware($input, $item);
break;
}
}

$skip_rules = isset($input['_skip_rules']) && $input['_skip_rules'] !== false;
$tmprequester = 0;
if (!$skip_rules) {
Expand Down Expand Up @@ -1992,30 +2016,6 @@ public function prepareInputForAdd($input)
}
}

if (!isset($input['_skip_auto_assign']) || $input['_skip_auto_assign'] === false) {
// Manage auto assign
$auto_assign_mode = Entity::getUsedConfig('auto_assign_mode', $input['entities_id']);

switch ($auto_assign_mode) {
case Entity::CONFIG_NEVER:
break;

case Entity::AUTO_ASSIGN_HARDWARE_CATEGORY:
// Auto assign tech/group from hardware
$input = $this->setTechAndGroupFromHardware($input, $item);
// Auto assign tech/group from Category
$input = $this->setTechAndGroupFromItilCategory($input);
break;

case Entity::AUTO_ASSIGN_CATEGORY_HARDWARE:
// Auto assign tech/group from Category
$input = $this->setTechAndGroupFromItilCategory($input);
// Auto assign tech/group from hardware
$input = $this->setTechAndGroupFromHardware($input, $item);
break;
}
}

if (!isset($input['_skip_sla_assign']) || $input['_skip_sla_assign'] === false) {
// Manage SLA / OLA asignment
// Manual SLA / OLA defined : reset due date
Expand Down
Loading