Skip to content

Commit 79af87d

Browse files
committed
fix(glpiselectfield): entity restriction not applied on users
1 parent 81afb9e commit 79af87d

File tree

2 files changed

+34
-3
lines changed

2 files changed

+34
-3
lines changed

inc/field/dropdownfield.class.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
use CommonTreeDropdown;
4545
use ITILCategory;
4646
use Entity;
47+
use Profile_User;
4748
use User;
4849
use Group;
4950
use Group_Ticket;
@@ -251,6 +252,38 @@ public function buildParams($rand = null) {
251252

252253
case User::class:
253254
$dparams['right'] = 'all';
255+
$currentEntity = Session::getActiveEntity();
256+
$ancestorEntities = getAncestorsOf(Entity::getTable(), $currentEntity);
257+
switch ($decodedValues['entity_restrict']) {
258+
case self::ENTITY_RESTRICT_FORM:
259+
$form = new PluginFormcreatorForm();
260+
$form->getFromDBByQuestion($this->getQuestion());
261+
$currentEntity = $form->fields['entities_id'];
262+
$ancestorEntities = getAncestorsOf(Entity::getTable(), $currentEntity);
263+
break;
264+
265+
case self::ENTITY_RESTRICT_BOTH:
266+
$form = new PluginFormcreatorForm();
267+
$form->getFromDBByQuestion($this->getQuestion());
268+
$currentEntity = [$currentEntity, $form->fields['entities_id']];
269+
$ancestorEntities = array_merge($ancestorEntities, getAncestorsOf(Entity::getTable(), $currentEntity));
270+
break;
271+
}
272+
$where = ['OR' => []];
273+
$where['OR'][] = ['entities_id' => $currentEntity];
274+
if (count($ancestorEntities) > 0) {
275+
$where['OR'][] = [
276+
'entities_id' => $ancestorEntities,
277+
'is_recursive' => '1',
278+
];
279+
}
280+
$dparams_cond_crit = [
281+
'id' => new QuerySubQuery([
282+
'SELECT' => 'users_id',
283+
'FROM' => Profile_User::getTable(),
284+
'WHERE' => $where,
285+
])
286+
];
254287
break;
255288

256289
case ITILCategory::class:

inc/field/glpiselectfield.class.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,9 +182,7 @@ public function prepareQuestionInputForSave($input) {
182182
'itemtype' => $itemtype
183183
];
184184
// Params for entity restrictables itemtypes
185-
if ((new $itemtype)->isEntityAssign()) {
186-
$input['values']['entity_restrict'] = $input['entity_restrict'] ?? self::ENTITY_RESTRICT_FORM;
187-
}
185+
$input['values']['entity_restrict'] = $input['entity_restrict'] ?? self::ENTITY_RESTRICT_FORM;
188186
unset($input['entity_restrict']);
189187

190188
$input['default_values'] = isset($input['dropdown_default_value']) ? $input['dropdown_default_value'] : '';

0 commit comments

Comments
 (0)