Skip to content

Commit e8a3d1b

Browse files
committed
fix(glpiselectfield): entity restriction not applied on users
1 parent 0f707fa commit e8a3d1b

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;
@@ -250,6 +251,38 @@ public function buildParams($rand = null) {
250251

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

255288
case ITILCategory::class:

inc/field/glpiselectfield.class.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,9 +180,7 @@ public function prepareQuestionInputForSave($input) {
180180
$input['itemtype'] = $itemtype;
181181
$input['values'] = [];
182182
// Params for entity restrictables itemtypes
183-
if ((new $itemtype)->isEntityAssign()) {
184-
$input['values']['entity_restrict'] = $input['entity_restrict'] ?? self::ENTITY_RESTRICT_FORM;
185-
}
183+
$input['values']['entity_restrict'] = $input['entity_restrict'] ?? self::ENTITY_RESTRICT_FORM;
186184
unset($input['entity_restrict']);
187185

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

0 commit comments

Comments
 (0)