diff --git a/cake4/rd_cake/src/Controller/Component/CountsComponent.php b/cake4/rd_cake/src/Controller/Component/CountsComponent.php index a42d5d5b0..660ad17ea 100644 --- a/cake4/rd_cake/src/Controller/Component/CountsComponent.php +++ b/cake4/rd_cake/src/Controller/Component/CountsComponent.php @@ -117,15 +117,26 @@ public function countPermanentUsers(int $cloudId): array { ) ->count(); - // Suspended users - $suspended = (clone $base) - ->where(['PermanentUsers.admin_state' => 'suspended']) - ->count(); + // Check if admin_state column exists + $PermanentUsers = TableRegistry::getTableLocator()->get('PermanentUsers'); + $schema = $PermanentUsers->getSchema(); + $hasAdminState = $schema->hasColumn('admin_state'); + + // Suspended users (only if column exists) + $suspended = 0; + if ($hasAdminState) { + $suspended = (clone $base) + ->where(['PermanentUsers.admin_state' => 'suspended']) + ->count(); + } - // Terminated users - $terminated = (clone $base) - ->where(['PermanentUsers.admin_state' => 'terminated']) - ->count(); + // Terminated users (only if column exists) + $terminated = 0; + if ($hasAdminState) { + $terminated = (clone $base) + ->where(['PermanentUsers.admin_state' => 'terminated']) + ->count(); + } return [ 'total' => (int)$total, diff --git a/cake4/rd_cake/src/Controller/DashboardController.php b/cake4/rd_cake/src/Controller/DashboardController.php index 9cf01d752..5df10b056 100644 --- a/cake4/rd_cake/src/Controller/DashboardController.php +++ b/cake4/rd_cake/src/Controller/DashboardController.php @@ -578,11 +578,15 @@ public function itemsFor(){ $tabItem = $this->request->getQuery('item_id'); $cloudId = $this->request->getQuery('cloud_id'); $req_q = $this->request->getQuery(); - + $comps = []; + $right = false; + if($cloudId){ $r_and_c = $this->Aa->rights_and_components_on_cloud(); - $right = $r_and_c['rights']; - $comps = $r_and_c['components']; + if($r_and_c && isset($r_and_c['rights'])){ + $right = $r_and_c['rights']; + $comps = $r_and_c['components'] ?? []; + } } //$right = $this->Aa->rights_on_cloud(); @@ -629,7 +633,7 @@ public function itemsFor(){ } if($tabItem == 'tabMainUsers'){ - if($comps['cmp_permanent_users']){ + if(isset($comps['cmp_permanent_users']) && $comps['cmp_permanent_users']){ $items[] = [ "title" => "Permanent Users", "glyph" => "xf2c0@FontAwesome", @@ -640,7 +644,7 @@ public function itemsFor(){ ] ]; } - if($comps['cmp_vouchers']){ + if(isset($comps['cmp_vouchers']) && $comps['cmp_vouchers']){ $items[] = [ "title" => "Vouchers", "glyph" => "xf145@FontAwesome", @@ -663,7 +667,7 @@ public function itemsFor(){ } if($tabItem == 'tabMainRadius'){ - if($comps['cmp_dynamic_clients']){ + if(isset($comps['cmp_dynamic_clients']) && $comps['cmp_dynamic_clients']){ $items[] = [ "title" => "RADIUS Clients", "glyph" => "xf1ce@FontAwesome", @@ -674,7 +678,7 @@ public function itemsFor(){ ] ]; } - if($comps['cmp_nas']){ + if(isset($comps['cmp_nas']) && $comps['cmp_nas']){ $items[] = [ "title" => "NAS", "glyph" => "xf1cb@FontAwesome", @@ -685,7 +689,7 @@ public function itemsFor(){ ] ]; } - if($comps['cmp_profiles']){ + if(isset($comps['cmp_profiles']) && $comps['cmp_profiles']){ $items[] = [ "title" => "Profiles", "glyph" => "xf1b3@FontAwesome", @@ -697,7 +701,7 @@ public function itemsFor(){ ]; } - if($comps['cmp_realms']){ + if(isset($comps['cmp_realms']) && $comps['cmp_realms']){ $items[] = [ "title" => "Realms (Groups)", "glyph" => "xf06c@FontAwesome", @@ -725,10 +729,10 @@ public function itemsFor(){ } if($tabItem == 'tabMainNetworks'){ - if($comps['cmp_meshes']){ + if(isset($comps['cmp_meshes']) && $comps['cmp_meshes']){ $items['meshes'] = true; } - if($comps['cmp_ap_profiles']){ + if(isset($comps['cmp_ap_profiles']) && $comps['cmp_ap_profiles']){ $items['ap_profiles'] = true; } $items['unknown_nodes'] = true; @@ -824,15 +828,20 @@ public function usersItems(){ //FIXME This needs some more work in terms of components which should be listed per Access Provider $cloudId = (int)$this->request->getQuery('cloud_id'); + $comps = []; + $right = false; + if($cloudId){ $r_and_c = $this->Aa->rights_and_components_on_cloud(); - $right = $r_and_c['rights']; - $comps = $r_and_c['components']; + if($r_and_c && isset($r_and_c['rights'])){ + $right = $r_and_c['rights']; + $comps = isset($r_and_c['components']) ? $r_and_c['components'] : []; + } } $firstRow = []; - if($comps['cmp_permanent_users']){ + if(isset($comps['cmp_permanent_users']) && $comps['cmp_permanent_users']){ $tUsers = $this->Counts->countPermanentUsers($cloudId); $firstRow['column1'] = [ @@ -848,7 +857,7 @@ public function usersItems(){ 'accent' => 'blue' ]; } - if($comps['cmp_vouchers']){ + if(isset($comps['cmp_vouchers']) && $comps['cmp_vouchers']){ $tVouchers = $this->Counts->countVouchers($cloudId); $firstRow['column2'] = [ @@ -1438,8 +1447,8 @@ private function _get_user_detail($user,$auto_compact=false){ private function _nav_tree($rc){ - $rights = $rc['rights']; - $components = $rc['components']; + $rights = isset($rc['rights']) ? $rc['rights'] : false; + $components = isset($rc['components']) ? $rc['components'] : []; $items = [ [ 'text' => 'OVERVIEW', @@ -1451,7 +1460,7 @@ private function _nav_tree($rc){ ] ]; - if($components['cmp_permanent_users'] || $components['cmp_vouchers']){ + if(isset($components['cmp_permanent_users']) && isset($components['cmp_vouchers']) && ($components['cmp_permanent_users'] || $components['cmp_vouchers'])){ $items[] = [ 'text' => 'USERS', 'leaf' => true, @@ -1462,7 +1471,10 @@ private function _nav_tree($rc){ ]; } - if($components['cmp_dynamic_clients'] || $components['cmp_nas'] || $components['cmp_profiles'] || $components['cmp_realms'] ){ + if((isset($components['cmp_dynamic_clients']) && $components['cmp_dynamic_clients']) || + (isset($components['cmp_nas']) && $components['cmp_nas']) || + (isset($components['cmp_profiles']) && $components['cmp_profiles']) || + (isset($components['cmp_realms']) && $components['cmp_realms'])){ $items[] = [ 'text' => 'RADIUS', 'leaf' => true, @@ -1473,7 +1485,8 @@ private function _nav_tree($rc){ ]; } - if($components['cmp_meshes'] || $components['cmp_ap_profiles']){ + if((isset($components['cmp_meshes']) && $components['cmp_meshes']) || + (isset($components['cmp_ap_profiles']) && $components['cmp_ap_profiles'])){ $items[] = [ 'text' => 'NETWORK', 'leaf' => true, @@ -1484,7 +1497,7 @@ private function _nav_tree($rc){ ]; } - if($components['cmp_other']){ + if(isset($components['cmp_other']) && $components['cmp_other']){ $items[] = [ 'text' => 'OTHER', 'leaf' => true, @@ -1521,5 +1534,4 @@ private function _nav_tree_blank(){ return $items; } -} - +} \ No newline at end of file