Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat(user): add default entity value = Full structure #17923

Open
wants to merge 4 commits into
base: 10.0/bugfixes
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions src/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -392,8 +392,21 @@ public static function shouldReloadActiveEntities(): bool
if (count($glpiactiveentities)) {
$glpiactive_entity = $_SESSION['glpiactive_entity'];
$glpiactive_entity_recursive = $_SESSION['glpiactive_entity_recursive'] ?? false;
$entities = [$glpiactive_entity];
if ($glpiactive_entity_recursive) {
$entities = [$glpiactive_entity => $glpiactive_entity];
if (
($_SESSION["glpientity_fullstructure"] ?? false)
&& isset($_SESSION['glpiactiveprofile']['entities'])
) {
foreach ($_SESSION['glpiactiveprofile']['entities'] as $val) {
$entities[$val['id']] = $val['id'];
if ($val['is_recursive']) {
$sons = getSonsOf("glpi_entities", $val['id']);
foreach ($sons as $key2 => $val2) {
$entities[$key2] = $key2;
}
}
}
} elseif ($glpiactive_entity_recursive) {
$entities = getSonsOf("glpi_entities", $glpiactive_entity);
}

Expand Down Expand Up @@ -421,6 +434,8 @@ public static function changeActiveEntities($ID = "all", $is_recursive = false)
$newentities = [];
$ancestors = [];

$_SESSION["glpientity_fullstructure"] = ($ID === 'all');

if (isset($_SESSION['glpiactiveprofile'])) {
if ($ID === "all") {
foreach ($_SESSION['glpiactiveprofile']['entities'] as $val) {
Expand Down
10 changes: 8 additions & 2 deletions src/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -2923,7 +2923,10 @@ public function showForm($ID, array $options = [])
$entities = $this->getEntities();
Entity::dropdown(['value' => $this->fields["entities_id"],
'rand' => $entrand,
'entity' => $entities
'entity' => $entities,
'toadd' => [
0 => __('Full structure'),
]
]);
echo "</td></tr>";

Expand Down Expand Up @@ -3311,7 +3314,10 @@ public function showMyForm($target, $ID)
echo "<td><label for='dropdown_entities_id$entrand'>" . __('Default entity') . "</td><td>";
Entity::dropdown(['value' => $this->fields['entities_id'],
'rand' => $entrand,
'entity' => $entities
'entity' => $entities,
'toadd' => [
0 => __('Full structure'),
]
]);
} else {
echo "<td colspan='2'>&nbsp;";
Expand Down