Skip to content

Commit

Permalink
Fix(ticket): check category / entity validity
Browse files Browse the repository at this point in the history
  • Loading branch information
Rom1-B committed Sep 23, 2024
1 parent ea67d74 commit 44897be
Showing 1 changed file with 27 additions and 26 deletions.
53 changes: 27 additions & 26 deletions src/Ticket.php
Original file line number Diff line number Diff line change
Expand Up @@ -4319,14 +4319,39 @@ public function showForm($ID, array $options = [])
}
}

// Default check
if ($ID > 0) {
$this->check($ID, READ);
} else {
// Create item
$this->check(-1, CREATE, $options);
}

$userentities = [];
if (!$ID) {
$userentities = $this->getEntitiesForRequesters($options);

if (
count($userentities) > 0
&& !in_array($this->fields["entities_id"], $userentities)
) {
// If entity is not in the list of user's entities,
// then use as default value the first value of the user's entites list
$first_entity = current($userentities);
$this->fields["entities_id"] = $first_entity;
// Pass to values
$options['entities_id'] = $first_entity;
}
}

// Check category / type validity
if ($options['itilcategories_id']) {
$cat = new ITILCategory();
if ($cat->getFromDB($options['itilcategories_id'])) {
switch ($options['type']) {
case self::INCIDENT_TYPE:
if (!$cat->getField('is_incident')) {
$options['itilcategories_id'] = 0;
$options['itilcategories_id'] = 0;
}
break;

Expand All @@ -4342,35 +4367,11 @@ public function showForm($ID, array $options = [])
// Check category / entity validity
if (!in_array($cat->fields['entities_id'], getSonsOf('glpi_entities', $options['entities_id']))) {
$options['itilcategories_id'] = 0;
$this->fields['itilcategories_id'] = 0;
}
}
}

// Default check
if ($ID > 0) {
$this->check($ID, READ);
} else {
// Create item
$this->check(-1, CREATE, $options);
}

$userentities = [];
if (!$ID) {
$userentities = $this->getEntitiesForRequesters($options);

if (
count($userentities) > 0
&& !in_array($this->fields["entities_id"], $userentities)
) {
// If entity is not in the list of user's entities,
// then use as default value the first value of the user's entites list
$first_entity = current($userentities);
$this->fields["entities_id"] = $first_entity;
// Pass to values
$options['entities_id'] = $first_entity;
}
}

if ($options['type'] <= 0) {
$options['type'] = Entity::getUsedConfig(
'tickettype',
Expand Down

0 comments on commit 44897be

Please sign in to comment.