diff --git a/core/groups/permissions_default.php b/core/groups/permissions_default.php index d2c7aa4a54..a58ed0f913 100644 --- a/core/groups/permissions_default.php +++ b/core/groups/permissions_default.php @@ -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