Skip to content

Commit a5c8840

Browse files
authored
Update AssignableItem.php
Thanks to Phind AI :) Since my migration to GLPI11, I have random error in APPLIANCE view when a computer was associated *** Uncaught PHP Exception TypeError: "array_intersect(): Argument #1 ($array) must be of type array, int given" at AssignableItem.php line 63 Backtrace : ./src/Glpi/Features/AssignableItem.php:63 ./src/Glpi/Features/AssignableItem.php:63 array_intersect() ./src/CommonDBTM.php:2986 Appliance->canViewItem() ./src/CommonDBTM.php:1486 CommonDBTM->can() ./src/Appliance_Item.php:285 CommonDBTM->getLink() ./src/Appliance_Item.php:100 Appliance_Item::showForItem() ./src/CommonGLPI.php:694 Appliance_Item::displayTabContentForItem() ./ajax/common.tabs.php:108 CommonGLPI::displayStandardTab() ...Glpi/Controller/LegacyFileLoadController.php:64 require() ./vendor/symfony/http-kernel/HttpKernel.php:181 Glpi\Controller\LegacyFileLoadController->__invoke() ./vendor/symfony/http-kernel/HttpKernel.php:76 Symfony\Component\HttpKernel\HttpKernel->handleRaw() ./vendor/symfony/http-kernel/Kernel.php:197 Symfony\Component\HttpKernel\HttpKernel->handle() ./public/index.php:70 Symfony\Component\HttpKernel\Kernel->handle() message was clear as an array was expected, but an INT was provided. This fix the vew issue
1 parent 44e068c commit a5c8840

File tree

1 file changed

+19
-15
lines changed

1 file changed

+19
-15
lines changed

src/Glpi/Features/AssignableItem.php

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -53,26 +53,30 @@ public static function canView(): bool
5353
}
5454

5555
/** @see AssignableItemInterface::canViewItem() */
56-
public function canViewItem(): bool
57-
{
58-
if (!parent::canViewItem()) {
59-
return false;
60-
}
56+
public function canViewItem(): bool
57+
{
58+
if (!parent::canViewItem()) {
59+
return false;
60+
}
6161

62-
$is_assigned = $this->fields['users_id_tech'] === $_SESSION['glpiID']
63-
|| count(array_intersect($this->fields['groups_id_tech'] ?? [], $_SESSION['glpigroups'] ?? [])) > 0;
64-
$is_owned = $this->fields['users_id'] === $_SESSION['glpiID']
65-
|| count(array_intersect($this->fields['groups_id'] ?? [], $_SESSION['glpigroups'] ?? [])) > 0;
62+
// Ensure we have arrays for comparison
63+
$tech_groups = (array)($this->fields['groups_id_tech'] ?? []);
64+
$own_groups = (array)($this->fields['groups_id'] ?? []);
65+
$session_groups = (array)($_SESSION['glpigroups'] ?? []);
6666

67-
if (!Session::haveRight(static::$rightname, READ)) {
68-
return ($is_assigned && Session::haveRight(static::$rightname, READ_ASSIGNED))
69-
|| ($is_owned && Session::haveRight(static::$rightname, READ_OWNED));
70-
}
67+
$is_assigned = $this->fields['users_id_tech'] === $_SESSION['glpiID']
68+
|| count(array_intersect($tech_groups, $session_groups)) > 0;
69+
$is_owned = $this->fields['users_id'] === $_SESSION['glpiID']
70+
|| count(array_intersect($own_groups, $session_groups)) > 0;
7171

72-
// Has global READ right
73-
return true;
72+
if (!Session::haveRight(static::$rightname, READ)) {
73+
return ($is_assigned && Session::haveRight(static::$rightname, READ_ASSIGNED))
74+
|| ($is_owned && Session::haveRight(static::$rightname, READ_OWNED));
7475
}
7576

77+
return true;
78+
}
79+
7680
/** @see AssignableItemInterface::canUpdate() */
7781
public static function canUpdate(): bool
7882
{

0 commit comments

Comments
 (0)