Skip to content

Commit 74108d0

Browse files
Coussecousseerika
andauthored
Admin: #add health check box on admin page - refs #6738
Co-authored-by: erika <eandre-do-brito@linagora.com>
1 parent f1a9ce2 commit 74108d0

File tree

5 files changed

+104
-6
lines changed

5 files changed

+104
-6
lines changed

assets/vue/composables/admin/indexBlocks.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ export function useIndexBlocks() {
8080
const blockChamilo = ref(null)
8181
const blockSecurity = ref(null)
8282
const blockPlugins = ref(null)
83+
const blockHealthCheck = ref(null)
8384

8485
async function loadBlocks() {
8586
const blocks = await adminService.findBlocks()
@@ -95,6 +96,7 @@ export function useIndexBlocks() {
9596
blockChamilo.value = blocks.chamilo || null
9697
blockSecurity.value = blocks.security || null
9798
blockPlugins.value = blocks.plugins || null
99+
blockHealthCheck.value = blocks.health_check || null
98100
}
99101

100102
return {
@@ -116,5 +118,6 @@ export function useIndexBlocks() {
116118
blockSupportStatusEl,
117119
loadSupport,
118120
blockPlugins,
121+
blockHealthCheck,
119122
}
120123
}

assets/vue/views/admin/AdminIndex.vue

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,14 @@
100100
icon="settings"
101101
/>
102102

103+
<AdminBlock
104+
v-if="blockHealthCheck && blockHealthCheck.items.length > 0"
105+
:id="blockHealthCheck.id"
106+
:items="blockHealthCheck.items"
107+
:title="t('Health check')"
108+
icon="multiple-marked"
109+
/>
110+
103111
<div
104112
v-if="securityStore.isAdmin"
105113
class="admin-index__block-container block-admin-version"
@@ -281,6 +289,7 @@ const {
281289
blockNewsStatusEl,
282290
blockSupportStatusEl,
283291
blockPlugins,
292+
blockHealthCheck,
284293
} = useIndexBlocks()
285294
286295
function checkVersionOnSubmit() {

public/main/admin/access_urls.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,14 @@
7979
$parameters['sec_token'] = Security::get_token();
8080

8181
// Checking if the admin is registered in all sites
82-
$url_string = '';
83-
foreach ($url_list as $u) {
84-
if (!in_array($u->getId(), $my_user_url_list)) {
85-
$url_string .= $u->getUrl() . '<br />';
82+
if (!api_is_admin_in_all_active_urls()) {
83+
// Get the list of unregistered urls
84+
$url_string = '';
85+
foreach ($url_list as $u) {
86+
if (!in_array($u->getId(), $my_user_url_list)) {
87+
$url_string .= $u->getUrl() . '<br />';
88+
}
8689
}
87-
}
88-
if (!empty($url_string)) {
8990
echo Display::return_message(
9091
get_lang('Admin user should be registered here') . '<br />' . $url_string,
9192
'warning',

public/main/inc/lib/api.lib.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5259,6 +5259,43 @@ function api_get_access_url_from_user($user_id)
52595259
return $list;
52605260
}
52615261

5262+
/**
5263+
* Checks whether the current admin user in in all access urls.
5264+
*
5265+
* @return bool
5266+
*/
5267+
function api_is_admin_in_all_active_urls()
5268+
{
5269+
if (api_is_platform_admin()) {
5270+
$urls = api_get_active_urls();
5271+
$user_url_list = api_get_access_url_from_user(api_get_user_id());
5272+
foreach ($urls as $url) {
5273+
if (!in_array($url['id'], $user_url_list)) {
5274+
return false;
5275+
}
5276+
}
5277+
return true;
5278+
}
5279+
}
5280+
5281+
/**
5282+
* Gets all the access urls in the database.
5283+
*
5284+
* @return array
5285+
*/
5286+
function api_get_active_urls()
5287+
{
5288+
$table = Database::get_main_table(TABLE_MAIN_ACCESS_URL);
5289+
$sql = "SELECT * FROM $table WHERE active = 1";
5290+
$result = Database::query($sql);
5291+
// Fetch all rows as associative arrays
5292+
$urls = [];
5293+
while ($row = Database::fetch_assoc($result)) {
5294+
$urls[] = $row;
5295+
}
5296+
return $urls;
5297+
}
5298+
52625299
/**
52635300
* Checks whether the curent user is in a group or not.
52645301
*

src/CoreBundle/Controller/Admin/IndexBlocksController.php

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Chamilo\CoreBundle\Event\Events;
1717
use Chamilo\CoreBundle\Helpers\AccessUrlHelper;
1818
use Chamilo\CoreBundle\Helpers\AuthenticationConfigHelper;
19+
use Chamilo\CoreBundle\Repository\Node\AccessUrlRepository;
1920
use Chamilo\CoreBundle\Repository\PageCategoryRepository;
2021
use Chamilo\CoreBundle\Repository\PageRepository;
2122
use Chamilo\CoreBundle\Repository\PluginRepository;
@@ -45,6 +46,7 @@ public function __construct(
4546
private readonly EventDispatcherInterface $eventDispatcher,
4647
private readonly PluginRepository $pluginRepository,
4748
private readonly AccessUrlHelper $accessUrlHelper,
49+
private readonly AccessUrlRepository $accessUrlRepository,
4850
AuthenticationConfigHelper $authConfigHelper,
4951
) {
5052
$this->isLdapActive = $authConfigHelper->getLdapConfig()['enabled'];
@@ -145,6 +147,13 @@ public function __invoke(): JsonResponse
145147
'editable' => false,
146148
'items' => $this->getItemsPlugins(),
147149
];
150+
151+
/* Health check */
152+
$json['health_check'] = [
153+
'id' => 'block-admin-health-check',
154+
'editable' => false,
155+
'items' => $this->getItemsHealthCheck(),
156+
];
148157
}
149158

150159
/* Sessions */
@@ -908,4 +917,43 @@ private function getItemsPlugins(): array
908917

909918
return $items;
910919
}
920+
921+
private function getItemsHealthCheck(): array
922+
{
923+
$items = [];
924+
925+
// Check if dsn or email is defined :
926+
$mailDsn = $this->settingsManager->getSetting('mail.mailer_dsn', true);
927+
$mailSender = $this->settingsManager->getSetting('mail.mailer_from_email', true);
928+
if ((empty($mailDsn) || 'null://null' == $mailDsn) && empty($mailSender)) {
929+
$items[] = [
930+
'className' => 'item-health-check-mail-settings text-error',
931+
'url' => '/admin/settings/mail',
932+
'label' => $this->translator->trans('E-mail settings need to be configured'),
933+
];
934+
} else {
935+
$items[] = [
936+
'className' => 'item-health-check-mail-settings text-success',
937+
'url' => '/admin/settings/mail',
938+
'label' => $this->translator->trans('E-mail settings are OK'),
939+
];
940+
}
941+
942+
// Check if the admin user has access to all URLs
943+
if (api_is_admin_in_all_active_urls()) {
944+
$items[] = [
945+
'className' => 'item-health-check-admin-urls text-success',
946+
'url' => '/main/admin/access_urls.php',
947+
'label' => $this->translator->trans('Admin has access to all active URLs'),
948+
];
949+
} else {
950+
$items[] = [
951+
'className' => 'item-health-check-admin-urls text-error',
952+
'url' => '/main/admin/access_url_edit_users_to_url.php',
953+
'label' => $this->translator->trans('Admin does not have access to all active URLs'),
954+
];
955+
}
956+
957+
return $items;
958+
}
911959
}

0 commit comments

Comments
 (0)