From a0b5647043640efcc4980f1f4aeed7b71baf9323 Mon Sep 17 00:00:00 2001 From: erika Date: Tue, 7 Oct 2025 17:16:37 +0200 Subject: [PATCH 1/4] Feature: Add health check block to admin index for email --- assets/vue/composables/admin/indexBlocks.js | 3 ++ assets/vue/views/admin/AdminIndex.vue | 9 ++++++ .../Admin/IndexBlocksController.php | 31 +++++++++++++++++++ 3 files changed, 43 insertions(+) diff --git a/assets/vue/composables/admin/indexBlocks.js b/assets/vue/composables/admin/indexBlocks.js index 9b1ac9a3b0a..eeafc458cca 100644 --- a/assets/vue/composables/admin/indexBlocks.js +++ b/assets/vue/composables/admin/indexBlocks.js @@ -80,6 +80,7 @@ export function useIndexBlocks() { const blockChamilo = ref(null) const blockSecurity = ref(null) const blockPlugins = ref(null) + const blockHealthCheck = ref(null) async function loadBlocks() { const blocks = await adminService.findBlocks() @@ -95,6 +96,7 @@ export function useIndexBlocks() { blockChamilo.value = blocks.chamilo || null blockSecurity.value = blocks.security || null blockPlugins.value = blocks.plugins || null + blockHealthCheck.value = blocks.health_check || null } return { @@ -116,5 +118,6 @@ export function useIndexBlocks() { blockSupportStatusEl, loadSupport, blockPlugins, + blockHealthCheck, } } diff --git a/assets/vue/views/admin/AdminIndex.vue b/assets/vue/views/admin/AdminIndex.vue index fff7a6692ee..0c3d280158a 100644 --- a/assets/vue/views/admin/AdminIndex.vue +++ b/assets/vue/views/admin/AdminIndex.vue @@ -89,6 +89,14 @@ icon="plugin" /> + + false, 'items' => $this->getItemsPlugins(), ]; + + /* Health check */ + $json['health_check'] = [ + 'id' => 'block-admin-health-check', + 'editable' => false, + 'items' => $this->getItemsHealthCheck(), + ]; } /* Sessions */ @@ -907,4 +914,28 @@ private function getItemsPlugins(): array return $items; } + + private function getItemsHealthCheck(): array + { + $items = []; + + /* Check if dsn or email is defined : */ + $mailDsn = $this->settingsManager->getSetting('mail.mailer_dsn'); + $mailSender = $this->settingsManager->getSetting('mail.mailer_from_email'); + if (empty($mailDsn) || empty($mailSender)) { + $items[] = [ + 'className' => 'item-health-check-mail-settings text-error', + 'url' => '/admin/settings/mail', + 'label' => $this->translator->trans('E-mail settings need to be configured'), + ]; + } else { + $items[] = [ + 'className' => 'item-health-check-mail-settings text-success', + 'url' => '/admin/settings/mail', + 'label' => $this->translator->trans('E-mail settings are OK'), + ]; + } + + return $items; + } } From 55c9ebf11f3980c27ee70288dd4ca5a62a151795 Mon Sep 17 00:00:00 2001 From: erika Date: Wed, 8 Oct 2025 11:43:43 +0200 Subject: [PATCH 2/4] Feat: Add health check for admin URL access Fix: Get active urls instead of all urls and get them from db If we don't get them from db, changes aren't apply Fix: Update mail settings check to handle 'null://null' as a valid empty value --- public/main/admin/access_urls.php | 11 ++++-- public/main/inc/lib/api.lib.php | 37 +++++++++++++++++++ .../Admin/IndexBlocksController.php | 25 +++++++++++-- 3 files changed, 65 insertions(+), 8 deletions(-) diff --git a/public/main/admin/access_urls.php b/public/main/admin/access_urls.php index 78fe84d9689..0205085721a 100644 --- a/public/main/admin/access_urls.php +++ b/public/main/admin/access_urls.php @@ -79,10 +79,13 @@ $parameters['sec_token'] = Security::get_token(); // Checking if the admin is registered in all sites -$url_string = ''; -foreach ($url_list as $u) { - if (!in_array($u->getId(), $my_user_url_list)) { - $url_string .= $u->getUrl() . '
'; +if (!api_is_admin_in_all_active_urls()) { + // Get the list of unregistered urls + $url_string = ''; + foreach ($url_list as $u) { + if (!in_array($u->getId(), $my_user_url_list)) { + $url_string .= $u->getUrl() . '
'; + } } } if (!empty($url_string)) { diff --git a/public/main/inc/lib/api.lib.php b/public/main/inc/lib/api.lib.php index 8e06d13d7be..13b0cdce8db 100644 --- a/public/main/inc/lib/api.lib.php +++ b/public/main/inc/lib/api.lib.php @@ -5259,6 +5259,43 @@ function api_get_access_url_from_user($user_id) return $list; } +/** + * Checks whether the current admin user in in all access urls. + * + * @return bool + */ +function api_is_admin_in_all_active_urls() +{ + if (api_is_platform_admin()) { + $urls = api_get_active_urls(); + $user_url_list = api_get_access_url_from_user(api_get_user_id()); + foreach ($urls as $url) { + if (!in_array($url['id'], $user_url_list)) { + return false; + } + } + return true; + } +} + +/** + * Gets all the access urls in the database. + * + * @return array + */ +function api_get_active_urls() +{ + $table = Database::get_main_table(TABLE_MAIN_ACCESS_URL); + $sql = "SELECT * FROM $table WHERE active = 1"; + $result = Database::query($sql); + // Fetch all rows as associative arrays + $urls = []; + while ($row = Database::fetch_assoc($result)) { + $urls[] = $row; + } + return $urls; +} + /** * Checks whether the curent user is in a group or not. * diff --git a/src/CoreBundle/Controller/Admin/IndexBlocksController.php b/src/CoreBundle/Controller/Admin/IndexBlocksController.php index 7805dc10803..be41be4ad72 100644 --- a/src/CoreBundle/Controller/Admin/IndexBlocksController.php +++ b/src/CoreBundle/Controller/Admin/IndexBlocksController.php @@ -15,6 +15,7 @@ use Chamilo\CoreBundle\Event\AdminBlockDisplayedEvent; use Chamilo\CoreBundle\Event\Events; use Chamilo\CoreBundle\Helpers\AccessUrlHelper; +use Chamilo\CoreBundle\Repository\Node\AccessUrlRepository; use Chamilo\CoreBundle\Repository\PageCategoryRepository; use Chamilo\CoreBundle\Repository\PageRepository; use Chamilo\CoreBundle\Repository\PluginRepository; @@ -44,6 +45,7 @@ public function __construct( private readonly EventDispatcherInterface $eventDispatcher, private readonly PluginRepository $pluginRepository, private readonly AccessUrlHelper $accessUrlHelper, + private readonly AccessUrlRepository $accessUrlRepository, ) { $this->extAuthSource = [ 'extldap' => [], @@ -919,10 +921,10 @@ private function getItemsHealthCheck(): array { $items = []; - /* Check if dsn or email is defined : */ - $mailDsn = $this->settingsManager->getSetting('mail.mailer_dsn'); - $mailSender = $this->settingsManager->getSetting('mail.mailer_from_email'); - if (empty($mailDsn) || empty($mailSender)) { + // Check if dsn or email is defined : + $mailDsn = $this->settingsManager->getSetting('mail.mailer_dsn', true); + $mailSender = $this->settingsManager->getSetting('mail.mailer_from_email', true); + if ((empty($mailDsn) || $mailDsn == 'null://null') && empty($mailSender)) { $items[] = [ 'className' => 'item-health-check-mail-settings text-error', 'url' => '/admin/settings/mail', @@ -936,6 +938,21 @@ private function getItemsHealthCheck(): array ]; } + // Check if the admin user has access to all URLs + if (api_is_admin_in_all_active_urls()) { + $items[] = [ + 'className' => 'item-health-check-admin-urls text-success', + 'url' => '/main/admin/access_urls.php', + 'label' => $this->translator->trans('Admin has access to all active URLs'), + ]; + } else { + $items[] = [ + 'className' => 'item-health-check-admin-urls text-error', + 'url' => '/main/admin/access_url_edit_users_to_url.php', + 'label' => $this->translator->trans('Admin does not have access to all active URLs'), + ]; + } + return $items; } } From 32b5ff9f0c63545a9773e3cd17bf426354355dec Mon Sep 17 00:00:00 2001 From: erika Date: Wed, 8 Oct 2025 11:45:54 +0200 Subject: [PATCH 3/4] Minor: Move health check block after the system block --- assets/vue/views/admin/AdminIndex.vue | 16 ++++++++-------- public/main/admin/access_urls.php | 2 -- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/assets/vue/views/admin/AdminIndex.vue b/assets/vue/views/admin/AdminIndex.vue index 0c3d280158a..76322653e50 100644 --- a/assets/vue/views/admin/AdminIndex.vue +++ b/assets/vue/views/admin/AdminIndex.vue @@ -89,14 +89,6 @@ icon="plugin" /> - - + +
getUrl() . '
'; } } -} -if (!empty($url_string)) { echo Display::return_message( get_lang('Admin user should be registered here') . '
' . $url_string, 'warning', From 53a902a87df8f92bd5af97b03d859d40d6c51ab4 Mon Sep 17 00:00:00 2001 From: erika Date: Wed, 8 Oct 2025 15:12:17 +0200 Subject: [PATCH 4/4] Minor: ECS --- src/CoreBundle/Controller/Admin/IndexBlocksController.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/CoreBundle/Controller/Admin/IndexBlocksController.php b/src/CoreBundle/Controller/Admin/IndexBlocksController.php index be41be4ad72..a5603a9c62d 100644 --- a/src/CoreBundle/Controller/Admin/IndexBlocksController.php +++ b/src/CoreBundle/Controller/Admin/IndexBlocksController.php @@ -919,12 +919,12 @@ private function getItemsPlugins(): array private function getItemsHealthCheck(): array { - $items = []; + $items = []; // Check if dsn or email is defined : $mailDsn = $this->settingsManager->getSetting('mail.mailer_dsn', true); $mailSender = $this->settingsManager->getSetting('mail.mailer_from_email', true); - if ((empty($mailDsn) || $mailDsn == 'null://null') && empty($mailSender)) { + if ((empty($mailDsn) || 'null://null' == $mailDsn) && empty($mailSender)) { $items[] = [ 'className' => 'item-health-check-mail-settings text-error', 'url' => '/admin/settings/mail',