From 17aa9430922361421f8abe65aa84a0846310fbaf Mon Sep 17 00:00:00 2001 From: Thierry Bugier Date: Fri, 18 Nov 2022 17:31:42 +0100 Subject: [PATCH] fix(form): prevent SQL error when current user is not member of any group, MySQL may warn about truncated decimal (nonsens, but happens) because groups are tested against IN('') statement --- inc/form.class.php | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/inc/form.class.php b/inc/form.class.php index d1de6252f..f50538609 100644 --- a/inc/form.class.php +++ b/inc/form.class.php @@ -967,12 +967,6 @@ protected function showMyLastForms() : void { 'searchtype' => 'equals', 'value' => 'myself', ], - 1 => [ - 'link' => 'OR', - 'field' => 7, - 'searchtype' => 'equals', - 'value' => 'mygroups', - ], ], 'sort' => [ 0 => 6 @@ -981,6 +975,15 @@ protected function showMyLastForms() : void { 0 => 'DESC' ], ]; + if (count($_SESSION['glpigroups'] ?? []) > 0) { + // The user is member of some groups, then add criteria for those groups + $criteria['criteria'][] = [ + 'link' => 'OR', + 'field' => 7, + 'searchtype' => 'equals', + 'value' => 'mygroups', + ]; + } $backupListLimit = $_SESSION['glpilist_limit']; $_SESSION['glpilist_limit'] = 5; $search = Search::getDatas(PluginFormcreatorFormAnswer::class, $criteria, $showColumns);