Auto reload user permissions (#7694)

Reload the current loaded permissions for the logged in user when using the Upgrade web interface
This commit is contained in:
frytimo
2026-01-13 00:33:36 -04:00
committed by GitHub
parent 6f37951e02
commit b33c450862

View File

@@ -43,6 +43,37 @@
$permission = new permission;
$permission->restore();
//reload the permissions for current user
if (!empty($_SESSION["groups"]) && is_array($_SESSION["groups"])) {
//clear current permissions
unset($_SESSION['permissions'], $_SESSION['user']['permissions']);
//get the permissions assigned to the groups that the current user is a member of, set the permissions in session variables
$x = 0;
$sql = "select distinct(permission_name) from v_group_permissions ";
$sql .= "where (domain_uuid = :domain_uuid or domain_uuid is null) ";
$sql .= "and permission_assigned = 'true' ";
foreach ($_SESSION["groups"] as $field) {
if (!empty($field['group_name'])) {
$sql_where_or[] = "group_name = :group_name_".$x;
$parameters['group_name_'.$x] = $field['group_name'];
$x++;
}
}
if (is_array($sql_where_or) && @sizeof($sql_where_or) != 0) {
$sql .= "and (".implode(' or ', $sql_where_or).") ";
}
$parameters['domain_uuid'] = $_SESSION["domain_uuid"];
$result = $database->select($sql, $parameters, 'all');
if (is_array($result) && @sizeof($result) != 0) {
foreach ($result as $row) {
$_SESSION['permissions'][$row["permission_name"]] = true;
$_SESSION["user"]["permissions"][$row["permission_name"]] = true;
}
}
unset($sql, $parameters, $result, $row);
}
//redirect the users
if (empty($included) || !$included) {
//show a message to the user