Skip to content

Fix Fields search options leaking across entity scopes - #1282

Open
brunoCarraroGridtech wants to merge 1 commit into
pluginsGLPI:mainfrom
brunoCarraroGridtech:main
Open

brunoCarraroGridtech wants to merge 1 commit into
pluginsGLPI:mainfrom
brunoCarraroGridtech:main

Conversation

@brunoCarraroGridtech

@brunoCarraroGridtech brunoCarraroGridtech commented Oct 2, 2026 •

Copy link
Copy Markdown

Checklist before requesting a review

Please delete options that are not relevant.

  • [X ] I have performed a self-review of my code.
  • I have added tests (when available) that prove my fix is effective or that my feature works.
  • I have updated the CHANGELOG with a short functional description of the fix or new feature.
  • [X ] This change requires a documentation update.

Description

  • It fixes # (issue number, if applicable)
  • Adds Entity and Child entities settings to Fields containers, allowing each additional-fields block to be scoped to a specific GLPI entity. It also makes Fields search and filter options respect that same entity scope, preventing client-specific fields from appearing in unrelated entities.

Screenshots (if appropriate):

@Rom1-B Rom1-B left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This branch is based on GLPI 11 code (1.24.5) while main now targets GLPI 12. Could you change the base to 11.0/bugfixes and rebase onto it? It will be forward-ported to main afterwards.

Can you add a test checking that a block in a non-recursive child entity is absent from getAddSearchOptions() in a sibling entity, present in its own, and still present in cron?

CI fails on the missing CHANGELOG entry, e.g. under [Unreleased] > Fixed: "Fix search options of blocks from other entities being available in the search engine".

Comment thread inc/container.class.php
Comment on lines +1094 to +1108
echo '<td>' . __('Entity') . ' : </td>';
echo '<td>';
Entity::dropdown(
[
'name' => 'entities_id',
'value' => $this->fields['entities_id'],
],
);
echo '</td>';
echo '</tr>';

echo '<tr>';
echo '<td>' . __('Child entities') . ' : </td>';
echo '<td>';
Dropdown::showYesNo('is_recursive', $this->fields['is_recursive']);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The form header already renders the entity and a "Child entities" toggle; this duplicate overrides the header toggle on submit. Could you drop it?

Suggested change
echo '<td>' . __('Entity') . ' : </td>';
echo '<td>';
Entity::dropdown(
[
'name' => 'entities_id',
'value' => $this->fields['entities_id'],
],
);
echo '</td>';
echo '</tr>';
echo '<tr>';
echo '<td>' . __('Child entities') . ' : </td>';
echo '<td>';
Dropdown::showYesNo('is_recursive', $this->fields['is_recursive']);

Comment thread inc/container.class.php
Comment on lines 2514 to +2521
}
$request['WHERE'][] = getEntitiesRestrictCriteria(
'glpi_plugin_fields_containers',
'',
$_SESSION['glpiactiveentities'] ?? 0,
true,
true,
);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cron has no active entities, so this drops sub-entity blocks there (field history included); scope it like the profile filter.

Suggested change
}
$request['WHERE'][] = getEntitiesRestrictCriteria(
'glpi_plugin_fields_containers',
'',
$_SESSION['glpiactiveentities'] ?? 0,
true,
true,
);
$request['WHERE'][] = getEntitiesRestrictCriteria('glpi_plugin_fields_containers', '', '', true);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants