Skip to content

Commit 64f7c24

Browse files
committed
verifying that the item implements AssignableItem interface before unsetting the groups_id field
1 parent 416ae62 commit 64f7c24

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

inc/commoninjectionlib.class.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@
2828
* -------------------------------------------------------------------------
2929
*/
3030
use Glpi\Exception\Http\HttpException;
31+
use Glpi\Features\AssignableItemInterface;
3132

33+
use function Safe\class_implements;
3234
use function Safe\preg_match;
3335
use function Safe\preg_replace;
3436

@@ -965,7 +967,8 @@ private function setValueForItemtype($itemtype, $field, $value, $fromdb = false)
965967
if (isForeignKeyField($field) || (str_contains($field, 'is_')) || (method_exists($injectionClass, 'isNullable') && !$injectionClass->isNullable($field))) {
966968
//If the field concernes groupds, unseting it instead of setting it to 0 in order to avoid associating the item to a non existing group (id 0)
967969
$group_fields = ['groups_id_tech', 'groups_id', 'groups_id_normal'];
968-
if (in_array($field, $group_fields)) {
970+
$implemented_classes = class_implements($itemtype);
971+
if (in_array($field, $group_fields) && $implemented_classes && in_array(AssignableItemInterface::class, $implemented_classes)) {
969972
unset($this->values[$itemtype][$field]);
970973
} else {
971974
// If the field is an id, we set it to 0

0 commit comments

Comments
 (0)