Skip to content

Commit 42338da

Browse files
committed
fix: prevent 500 errors in dashboard endpoints due to missing validation
1 parent 52b9cf9 commit 42338da

File tree

2 files changed

+36
-20
lines changed

2 files changed

+36
-20
lines changed

cake4/rd_cake/src/Controller/Component/CountsComponent.php

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -117,15 +117,26 @@ public function countPermanentUsers(int $cloudId): array {
117117
)
118118
->count();
119119

120-
// Suspended users
121-
$suspended = (clone $base)
122-
->where(['PermanentUsers.admin_state' => 'suspended'])
123-
->count();
120+
// Check if admin_state column exists
121+
$PermanentUsers = TableRegistry::getTableLocator()->get('PermanentUsers');
122+
$schema = $PermanentUsers->getSchema();
123+
$hasAdminState = $schema->hasColumn('admin_state');
124+
125+
// Suspended users (only if column exists)
126+
$suspended = 0;
127+
if ($hasAdminState) {
128+
$suspended = (clone $base)
129+
->where(['PermanentUsers.admin_state' => 'suspended'])
130+
->count();
131+
}
124132

125-
// Terminated users
126-
$terminated = (clone $base)
127-
->where(['PermanentUsers.admin_state' => 'terminated'])
128-
->count();
133+
// Terminated users (only if column exists)
134+
$terminated = 0;
135+
if ($hasAdminState) {
136+
$terminated = (clone $base)
137+
->where(['PermanentUsers.admin_state' => 'terminated'])
138+
->count();
139+
}
129140

130141
return [
131142
'total' => (int)$total,

cake4/rd_cake/src/Controller/DashboardController.php

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -828,14 +828,15 @@ public function usersItems(){
828828
//FIXME This needs some more work in terms of components which should be listed per Access Provider
829829

830830
$cloudId = (int)$this->request->getQuery('cloud_id');
831-
$comps = [];
832-
$right = false;
831+
$comps = [];
832+
$right = false;
833+
833834
if($cloudId){
834835
$r_and_c = $this->Aa->rights_and_components_on_cloud();
835-
if($r_and_c && isset($r_and_c['rights'])){
836-
$right = $r_and_c['rights'];
837-
$comps = $r_and_c['components'];
838-
}
836+
if($r_and_c && isset($r_and_c['rights'])){
837+
$right = $r_and_c['rights'];
838+
$comps = isset($r_and_c['components']) ? $r_and_c['components'] : [];
839+
}
839840
}
840841

841842
$firstRow = [];
@@ -1446,8 +1447,8 @@ private function _get_user_detail($user,$auto_compact=false){
14461447

14471448
private function _nav_tree($rc){
14481449

1449-
$rights = $rc['rights'];
1450-
$components = $rc['components'];
1450+
$rights = isset($rc['rights']) ? $rc['rights'] : false;
1451+
$components = isset($rc['components']) ? $rc['components'] : [];
14511452
$items = [
14521453
[
14531454
'text' => 'OVERVIEW',
@@ -1459,7 +1460,7 @@ private function _nav_tree($rc){
14591460
]
14601461
];
14611462

1462-
if($components['cmp_permanent_users'] || $components['cmp_vouchers']){
1463+
if(isset($components['cmp_permanent_users']) && isset($components['cmp_vouchers']) && ($components['cmp_permanent_users'] || $components['cmp_vouchers'])){
14631464
$items[] = [
14641465
'text' => 'USERS',
14651466
'leaf' => true,
@@ -1470,7 +1471,10 @@ private function _nav_tree($rc){
14701471
];
14711472
}
14721473

1473-
if($components['cmp_dynamic_clients'] || $components['cmp_nas'] || $components['cmp_profiles'] || $components['cmp_realms'] ){
1474+
if((isset($components['cmp_dynamic_clients']) && $components['cmp_dynamic_clients']) ||
1475+
(isset($components['cmp_nas']) && $components['cmp_nas']) ||
1476+
(isset($components['cmp_profiles']) && $components['cmp_profiles']) ||
1477+
(isset($components['cmp_realms']) && $components['cmp_realms'])){
14741478
$items[] = [
14751479
'text' => 'RADIUS',
14761480
'leaf' => true,
@@ -1481,7 +1485,8 @@ private function _nav_tree($rc){
14811485
];
14821486
}
14831487

1484-
if($components['cmp_meshes'] || $components['cmp_ap_profiles']){
1488+
if((isset($components['cmp_meshes']) && $components['cmp_meshes']) ||
1489+
(isset($components['cmp_ap_profiles']) && $components['cmp_ap_profiles'])){
14851490
$items[] = [
14861491
'text' => 'NETWORK',
14871492
'leaf' => true,
@@ -1492,7 +1497,7 @@ private function _nav_tree($rc){
14921497
];
14931498
}
14941499

1495-
if($components['cmp_other']){
1500+
if(isset($components['cmp_other']) && $components['cmp_other']){
14961501
$items[] = [
14971502
'text' => 'OTHER',
14981503
'leaf' => true,

0 commit comments

Comments
 (0)