Skip to content

Commit

Permalink
Merge pull request #4815 from 3liz/backport-4804-to-release_3_8
Browse files Browse the repository at this point in the history
[Backport release_3_8] Show Lizmap modules infos
  • Loading branch information
Gustry authored Sep 30, 2024
2 parents f7e83dd + ab1b26e commit 4a62b30
Show file tree
Hide file tree
Showing 9 changed files with 146 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<?php

use LizmapAdmin\ModulesInfo\ModulesChecker;

/**
* Lizmap administration : Server information page.
*
Expand Down Expand Up @@ -69,11 +72,14 @@ public function index()
jLog::log($updateLizmapPlugin, 'lizmapadmin');
}

$modules = new ModulesChecker();

// Set the HTML content
$tpl = new jTpl();
$assign = array(
'data' => $data,
'baseUrlApplication' => \jServer::getServerURI().\jApp::urlBasePath(),
'modules' => $modules->getList(false),
'qgisServerNeedsUpdate' => $qgisServerNeedsUpdate,
'updateQgisServer' => $updateQgisServer,
'lizmapQgisServerNeedsUpdate' => $lizmapQgisServerNeedsUpdate,
Expand Down
31 changes: 31 additions & 0 deletions lizmap/modules/admin/lib/ModulesInfo/ModuleMetaData.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace LizmapAdmin\ModulesInfo;

class ModuleMetaData
{
private $slug;
private $version;
private $isCore;

public function __construct($slug, $version, $core)
{
$this->slug = $slug;
$this->version = $version;
$this->isCore = $core;
}

public function __get($name)
{
if (in_array($name, array('slug', 'version', 'isCore'))) {
return $this->{$name};
}

throw new \DomainException();
}

public function __toString()
{
return $this->slug;
}
}
48 changes: 48 additions & 0 deletions lizmap/modules/admin/lib/ModulesInfo/ModulesChecker.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

namespace LizmapAdmin\ModulesInfo;

use Jelix\IniFile\IniReader;

class ModulesChecker
{
private const coreModules = array('jelix',
'jacl2',
'jacl2db',
'jcommunity',
'admin',
'dataviz',
'filter',
'action',
'dynamicLayers',
'lizmap',
'proj4php',
'view',
'jacl2db_admin',
'jauthdb_admin',
'master_admin',
);

public function getList($withCore = false)
{
$moduleConfig = \jApp::config()->modules;

// file_get_contents(\jApp::varConfigPath('installer.ini.php'));
$installreRadr = new IniReader(\jApp::varConfigPath('installer.ini.php'));

$enabledModuleName = array();
foreach ($moduleConfig as $paramName => $value) {
if (preg_match('/(\w*)\.enabled/', $paramName, $matches) && $value == '1') {
$moduleSlug = $matches[1];
$coreModule = in_array($moduleSlug, self::coreModules);
if ($coreModule && !$withCore) {
continue;
}
$version = $installreRadr->getValue($moduleSlug.'.version', 'modules');
$enabledModuleName[] = new ModuleMetaData($moduleSlug, $version, $coreModule);
}
}

return $enabledModuleName;
}
}
Empty file.
5 changes: 4 additions & 1 deletion lizmap/modules/admin/locales/en_US/admin.UTF-8.properties
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,10 @@ server.information.lizmap.info=Information
server.information.lizmap.info.version=Version
server.information.lizmap.info.date=Date of release
server.information.lizmap.url=URL in the QGIS desktop plugin
server.information.webdav.url=URL of the WebDAV server
server.information.modules=Modules
server.information.no.module=No module installed
server.information.module=Module
server.information.module.version=Version
server.information.qgis.label=QGIS Server
server.information.qgis.metadata=Version
Expand Down
19 changes: 19 additions & 0 deletions lizmap/modules/admin/templates/server_information.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,25 @@
</td>
</tr>
</table>

<h4>{@admin.server.information.modules@}</h4>
{if empty($modules)}
<p>{@admin.server.information.no.module@}</p>
{else}
<table class="table table-condensed table-striped table-bordered table-lizmap-modules">
<tr>
<th>{@admin.server.information.module@}</th>
<th>{@admin.server.information.module.version@}</th>
</tr>
{foreach $modules as $module}
<tr>
<th style='width:20%;'> {$module->slug}</th>
<td style='width:20%;'>{$module->version}</td>
</tr>
{/foreach}
{/if}
</table>

{hook 'LizmapServerVersion', $data['info']}

<h3>{@admin.server.information.qgis.label@}</h3>
Expand Down
25 changes: 25 additions & 0 deletions lizmap/modules/lizmap/lib/Server/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

namespace Lizmap\Server;

use LizmapAdmin\ModulesInfo\ModulesChecker;

class Server
{
/**
Expand Down Expand Up @@ -211,6 +213,26 @@ private function getLizmapRepositories()
return $repositories;
}

/**
* Get the list of modules.
*
* @return array List of modules
*/
private function getModules()
{
$data = array();
$modules = new ModulesChecker();

foreach ($modules->getList(false) as $module => $info) {
$data[$info->slug] = array(
'version' => $info->version,
'core' => $info->isCore,
);
}

return $data;
}

/**
* Get the data on Lizmap groups of users.
*
Expand Down Expand Up @@ -280,6 +302,9 @@ private function getLizmapMetadata()
// Add the list of repositories
$data['repositories'] = $this->getLizmapRepositories();

// Add the list of modules
$data['modules'] = $this->getModules();

$data['lizmap_desktop_plugin_version'] = $this->getLizmapPluginDesktopVersion();

// Add the list of user groups
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ describe('Request JSON metadata', function () {
expect(response.body.qgis_server_info.metadata.version).to.contain('3.')
expect(response.body.qgis_server_info.plugins.lizmap_server.version).to.match(/(\d+\.\d+|master|dev)/i)

// Modules
expect(response.body.modules.lizmapdemo.version).to.match(/\d+\.\d+/i)

// Desktop plugin
expect(response.body.lizmap_desktop_plugin_version).to.match(/(\d{5,6})/i)

Expand Down
10 changes: 10 additions & 0 deletions tests/end2end/playwright/server-information.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@ test.describe('Server information', () => {
await expect(lwcRow.locator('td')).toHaveCount(1);
await expect(await lwcRow.locator('td').innerText()).not.toEqual('');
}
// Check that Lizmap modules contains 2 lines (header and 1 module lizmapdemo)
const modulesRows = page.locator('#lizmap_server_information table.table-lizmap-modules tr:nth-child(1n+2)')
await expect(modulesRows).toHaveCount(1);
for (const row of await modulesRows.all()) {
await modulesRows.scrollIntoViewIfNeeded();
await expect(modulesRows.locator('th')).toHaveCount(1);
await expect(await modulesRows.locator('th').innerText()).not.toEqual('');
await expect(modulesRows.locator('td')).toHaveCount(1);
await expect(await modulesRows.locator('td').innerText()).not.toEqual('');
}
// Check that QGIS Server table contains 4 lines
const qgisServerRows = page.locator('#lizmap_server_information table.table-qgis-server tr')
await expect(qgisServerRows).toHaveCount(4);
Expand Down

0 comments on commit 4a62b30

Please sign in to comment.