Skip to content

Commit 2539e36

Browse files
committed
fix(dropdownfield): SQL error for GLPI objects / tickets and some specific rights
1 parent 7841cd7 commit 2539e36

File tree

1 file changed

+13
-21
lines changed

1 file changed

+13
-21
lines changed

inc/field/dropdownfield.class.php

+13-21
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
use SLA;
5858
use SLM;
5959
use OLA;
60+
use QueryExpression;
6061
use QuerySubQuery;
6162
use QueryUnion;
6263
use GlpiPlugin\Formcreator\Exception\ComparisonException;
@@ -227,9 +228,11 @@ public function buildParams($rand = null) {
227228
$currentUser = Session::getLoginUserID();
228229
if (!Session::haveRight(Ticket::$rightname, Ticket::READMY) && !Session::haveRight(Ticket::$rightname, Ticket::READGROUP)) {
229230
// No right to view any ticket, then force the dropdown to be empty
230-
$dparams_cond_crit['OR'] = new \QueryExpression('0=1');
231+
$dparams_cond_crit['OR'] = new QueryExpression('0=1');
231232
break;
232233
}
234+
$tickets_filter = ['users_id_recipient' => $currentUser];
235+
233236
if (Session::haveRight(Ticket::$rightname, Ticket::READMY)) {
234237
$requestersObserversQuery = new QuerySubQuery([
235238
'SELECT' => 'tickets_id',
@@ -239,34 +242,23 @@ public function buildParams($rand = null) {
239242
'type' => [CommonITILActor::REQUESTER, CommonITILActor::OBSERVER]
240243
],
241244
]);
242-
$dparams_cond_crit['OR'] = [
245+
$tickets_filter[] = [
243246
'id' => $requestersObserversQuery,
244-
'users_id_recipient' => $currentUser,
245247
];
246248
}
247-
if (Session::haveRight(Ticket::$rightname, Ticket::READGROUP)) {
248-
$sub_query = [
249+
250+
if (Session::haveRight(Ticket::$rightname, Ticket::READGROUP) && count($_SESSION['glpigroups']) > '0') {
251+
$requestersObserversGroupsQuery = new QuerySubQuery([
249252
'SELECT' => 'tickets_id',
250253
'FROM' => Group_Ticket::getTable(),
251254
'WHERE' => [
252-
'type' => [CommonITILActor::REQUESTER, CommonITILActor::OBSERVER]
255+
'type' => [CommonITILActor::REQUESTER, CommonITILActor::OBSERVER],
256+
'groups_id' => $_SESSION['glpigroups'],
253257
],
254-
];
255-
if (count($_SESSION['glpigroups']) > '0') {
256-
$sub_query['WHERE']['groups_id'] = $_SESSION['glpigroups'];
257-
}
258-
$requestersObserversGroupsQuery = new QuerySubQuery($sub_query);
259-
if (!isset($dparams_cond_crit['OR']['id'])) {
260-
$dparams_cond_crit['OR'] = [
261-
'id' => $requestersObserversGroupsQuery,
262-
];
263-
} else {
264-
$dparams_cond_crit['OR']['id'] = new QueryUnion([
265-
$dparams_cond_crit['OR']['id'],
266-
$requestersObserversGroupsQuery,
267-
]);
268-
}
258+
]);
259+
$tickets_filter[] = ['id' => $requestersObserversGroupsQuery];
269260
}
261+
$dparams_cond_crit['OR'] = $tickets_filter;
270262
break;
271263

272264
default:

0 commit comments

Comments
 (0)