Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions assets/vue/composables/admin/indexBlocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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 {
Expand All @@ -116,5 +118,6 @@ export function useIndexBlocks() {
blockSupportStatusEl,
loadSupport,
blockPlugins,
blockHealthCheck,
}
}
9 changes: 9 additions & 0 deletions assets/vue/views/admin/AdminIndex.vue
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,14 @@
icon="settings"
/>

<AdminBlock
v-if="blockHealthCheck && blockHealthCheck.items.length > 0"
:id="blockHealthCheck.id"
:items="blockHealthCheck.items"
:title="t('Health check')"
icon="multiple-marked"
/>

<div
v-if="securityStore.isAdmin"
class="admin-index__block-container block-admin-version"
Expand Down Expand Up @@ -281,6 +289,7 @@ const {
blockNewsStatusEl,
blockSupportStatusEl,
blockPlugins,
blockHealthCheck,
} = useIndexBlocks()

function checkVersionOnSubmit() {
Expand Down
13 changes: 7 additions & 6 deletions public/main/admin/access_urls.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,14 @@
$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() . '<br />';
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() . '<br />';
}
}
}
if (!empty($url_string)) {
echo Display::return_message(
get_lang('Admin user should be registered here') . '<br />' . $url_string,
'warning',
Expand Down
37 changes: 37 additions & 0 deletions public/main/inc/lib/api.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
48 changes: 48 additions & 0 deletions src/CoreBundle/Controller/Admin/IndexBlocksController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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' => [],
Expand Down Expand Up @@ -146,6 +148,13 @@ public function __invoke(): JsonResponse
'editable' => false,
'items' => $this->getItemsPlugins(),
];

/* Health check */
$json['health_check'] = [
'id' => 'block-admin-health-check',
'editable' => false,
'items' => $this->getItemsHealthCheck(),
];
}

/* Sessions */
Expand Down Expand Up @@ -907,4 +916,43 @@ 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', true);
$mailSender = $this->settingsManager->getSetting('mail.mailer_from_email', true);
if ((empty($mailDsn) || 'null://null' == $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'),
];
}

// 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;
}
}
Loading