Skip to content
Merged
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
2 changes: 1 addition & 1 deletion .github/copilot-instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ api_plugin_register_hook('reportit', 'config_settings', 'reportit_config_s
api_plugin_register_hook('reportit', 'poller_bottom', 'reportit_poller_bottom', 'setup.php');
api_plugin_register_hook('reportit', 'clog_regex_array', 'reportit_clog_regex_array', 'setup.php');

api_plugin_register_realm('reportit', 'view.php,charts.php', 'ReportIt - Report Viewing', 1);
api_plugin_register_realm('reportit', 'view.php', 'ReportIt - Report Viewing', 1);
api_plugin_register_realm('reportit', 'reportit.php,view.php', 'ReportIt - Create Reports', 1);
api_plugin_register_realm('reportit', 'templates.php', 'ReportIt - Manage Reports', 1);
```
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ installation guidance and source-checked behavior.

--- develop ---

* bug: Fix the `reportsit.php` typo in the navigation entries and the General Administration role (so it now grants the Create Reports realm), and remove the realm and navigation entries for the nonexistent `charts.php`
* dev: Correct template-wizard switch-label spacing to pass the PHP formatting check
* dev: Run the CI poller with the shared runner group so RRD files and structured directories pass permission verification
* security: Move the plugin's remaining inline event handlers to CSP-safe bindings so the pages no longer trip Cacti's Content-Security-Policy script-src-attr directive: the confirmation-page Cancel buttons use the `cactiReturnTo` class, the filter rows selects are bound via change() in their ready blocks, and the template calc-syntax links use a delegated `reportitAddCalc` handler
Expand Down
12 changes: 0 additions & 12 deletions locales/po/cacti.pot
Original file line number Diff line number Diff line change
Expand Up @@ -1746,18 +1746,6 @@ msgstr ""
msgid "Export Report"
msgstr ""

#: setup.php
msgid "Public Report Charts"
msgstr ""

#: setup.php
msgid "Bar Chart"
msgstr ""

#: setup.php
msgid "Pie Chart"
msgstr ""

#: setup.php
msgid "Normal User"
msgstr ""
Expand Down
1 change: 1 addition & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
<source>
<include>
<file>setup.php</file>
<file>system/upgrade.php</file>
<file>lib/funct_calculate.php</file>
<file>lib/funct_export.php</file>
<file>lib/funct_html.php</file>
Expand Down
104 changes: 23 additions & 81 deletions setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ function plugin_reportit_install(): void {
api_plugin_register_hook('reportit', 'poller_bottom', 'reportit_poller_bottom', 'setup.php');
api_plugin_register_hook('reportit', 'clog_regex_array', 'reportit_clog_regex_array', 'setup.php');

api_plugin_register_realm('reportit', 'view.php,charts.php', 'ReportIt - Report Viewing', 1);
api_plugin_register_realm('reportit', 'view.php', 'ReportIt - Report Viewing', 1);
api_plugin_register_realm('reportit', 'reportit.php,view.php', 'ReportIt - Create Reports', 1);
api_plugin_register_realm('reportit', 'templates.php', 'ReportIt - Manage Reports', 1);

Expand Down Expand Up @@ -225,71 +225,35 @@ function reportit_upgrade_requirements(): bool {
* @return array The $nav array with this plugin's entries added.
*/
function reportit_draw_navigation_text($nav): array {
$nav['reportsit.php:'] = [
'title' => __('Reports', 'reportit'),
'mapping' => 'index.php:',
'url' => 'reportsit.php',
'level' => '1'];
$report_entry = static function (string $title, string $mapping, string $url, string $level): array {
return compact('title', 'mapping', 'url', 'level');
};

$nav['reportsit.php:save'] = [
'title' => __('(Edit)', 'reportit'),
'mapping' => 'index.php:',
'url' => 'templates.php',
'level' => '2'];
$edit_title = __('(Edit)', 'reportit');
$report_mapping = 'index.php:,reportit.php:';
$rrd_mapping = $report_mapping . ',rrdlist.php:';

$nav['reportsit.php:report_add'] = [
'title' => __('Add', 'reportit'),
'mapping' => 'index.php:',
'url' => 'templates.php',
'level' => '2'];
$nav['reportit.php:'] = $report_entry(__('Reports', 'reportit'), 'index.php:', 'reportit.php', '1');

$nav['reportsit.php:report_edit'] = [
'title' => __('(Edit)', 'reportit'),
'mapping' => 'index.php:',
'url' => 'templates.php',
'level' => '2'];
$nav['reportit.php:save'] = $report_entry($edit_title, 'index.php:', 'templates.php', '2');

$nav['reportsit.php:actions'] = [
'title' => __('Actions', 'reportit'),
'mapping' => 'index.php:',
'url' => 'templates.php',
'level' => '2'];
$nav['reportit.php:report_add'] = $report_entry(__('Add', 'reportit'), 'index.php:', 'templates.php', '2');

$nav['rrdlist.php:'] = [
'title' => __('Data Items', 'reportit'),
'mapping' => 'index.php:,reportsit.php:',
'url' => 'templates.php',
'level' => '2'];
$nav['reportit.php:report_edit'] = $report_entry($edit_title, 'index.php:', 'templates.php', '2');

$nav['rrdlist.php:save'] = [
'title' => __('(Edit)', 'reportit'),
'mapping' => 'index.php:,reportsit.php:,rrdlist.php:',
'url' => '',
'level' => '3'];
$nav['reportit.php:actions'] = $report_entry(__('Actions', 'reportit'), 'index.php:', 'templates.php', '2');

$nav['rrdlist.php:rrdlist_edit'] = [
'title' => __('(Edit)', 'reportit'),
'mapping' => 'index.php:,reportsit.php:,rrdlist.php:',
'url' => '',
'level' => '3'];
$nav['rrdlist.php:'] = $report_entry(__('Data Items', 'reportit'), $report_mapping, 'templates.php', '2');

$nav['rrdlist.php:actions'] = [
'title' => __('Actions', 'reportit'),
'mapping' => 'index.php:,reportsit.php:,rrdlist.php:',
'url' => '',
'level' => '3'];
$nav['rrdlist.php:save'] = $report_entry($edit_title, $rrd_mapping, '', '3');

$nav['items.php:'] = [
'title' => __('Add', 'reportit'),
'mapping' => 'index.php:,reportsit.php:,rrdlist.php:',
'url' => 'templates.php',
'level' => '3'];
$nav['rrdlist.php:rrdlist_edit'] = $report_entry($edit_title, $rrd_mapping, '', '3');

$nav['items.php:save'] = [
'title' => __('(Edit)', 'reportit'),
'mapping' => 'index.php:,reportsit.php:,rrdlist.php:',
'url' => '',
'level' => '4'];
$nav['rrdlist.php:actions'] = $report_entry(__('Actions', 'reportit'), $rrd_mapping, '', '3');

$nav['items.php:'] = $report_entry(__('Add', 'reportit'), $rrd_mapping, 'templates.php', '3');

$nav['items.php:save'] = $report_entry($edit_title, $rrd_mapping, '', '4');

$nav['templates.php:'] = [
'title' => __('Report Templates', 'reportit'),
Expand Down Expand Up @@ -399,11 +363,7 @@ function reportit_draw_navigation_text($nav): array {
'url' => '',
'level' => '3'];

$nav['run.php:calculation'] = [
'title' => __('Report Calculation', 'reportit'),
'mapping' => 'index.php:,reportsit.php:',
'url' => '',
'level' => '2'];
$nav['run.php:calculation'] = $report_entry(__('Report Calculation', 'reportit'), $report_mapping, '', '2');

$nav['view.php:'] = [
'title' => __('Public Reports', 'reportit'),
Expand All @@ -429,24 +389,6 @@ function reportit_draw_navigation_text($nav): array {
'url' => '',
'level' => '2'];

$nav['charts.php:'] = [
'title' => __('Public Report Charts', 'reportit'),
'mapping' => 'index.php:',
'url' => 'graph.php',
'level' => '1'];

$nav['charts.php:bar'] = [
'title' => __('Bar Chart', 'reportit'),
'mapping' => 'index.php:,graph.php:',
'url' => '',
'level' => '2'];

$nav['charts.php:pie'] = [
'title' => __('Pie Chart', 'reportit'),
'mapping' => 'index.php:,graph.php:',
'url' => '',
'level' => '2'];

return $nav;
}

Expand Down Expand Up @@ -479,8 +421,8 @@ function reportit_config_arrays(): void {
reportit_define_constants();

if (function_exists('auth_augment_roles')) {
auth_augment_roles(__('Normal User'), ['view.php,charts.php']);
auth_augment_roles(__('General Administration'), ['reportsit.php']);
auth_augment_roles(__('Normal User'), ['view.php']);
auth_augment_roles(__('General Administration'), ['reportit.php']);
auth_augment_roles(__('System Administration'), ['templates.php', 'measurands.php', 'variables.php']);
}

Expand Down
2 changes: 1 addition & 1 deletion system/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ function reportit_system_upgrade(string $old_version): void {

db_execute('UPDATE plugin_realms SET file="reports.php,view.php" WHERE plugin="reportit" AND file LIKE "%reports.php%"');
db_execute('UPDATE plugin_realms SET file="templates.php" WHERE plugin="reportit" AND file LIKE "%templates.php%"');
db_execute('UPDATE plugin_realms SET file="view.php,charts.php" WHERE plugin="reportit" AND file LIKE "view.php%"');
db_execute('UPDATE plugin_realms SET file="view.php" WHERE plugin="reportit" AND file LIKE "view.php%"');
}

// cacti 1.3.0 compatibility
Expand Down
10 changes: 10 additions & 0 deletions tests/Unit/ReportitCheckUpgradeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,13 @@
'0',
]);
});

it('migrates the legacy report viewer realm to the existing view page', function () {
require_once __DIR__ . '/../../system/install.php';
require_once __DIR__ . '/../../system/upgrade.php';

reportit_system_upgrade('1.1.1');

$queries = array_column($GLOBALS['__test_db_calls'], 'sql');
expect($queries)->toContain('UPDATE plugin_realms SET file="view.php" WHERE plugin="reportit" AND file LIKE "view.php%"');
});
8 changes: 8 additions & 0 deletions tests/Unit/ReportitConfigArraysAndSettingsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,11 @@
expect($settings_user['reportit'])->toHaveKey('other_user_setting');
expect($settings_user['reportit'])->toHaveKey('reportit_max_rows');
});

it('links report breadcrumbs to the report page and omits retired charts', function () {
$nav = reportit_draw_navigation_text([]);

expect($nav['reportit.php:']['url'])->toBe('reportit.php');
expect($nav['rrdlist.php:']['mapping'])->toBe('index.php:,reportit.php:');
expect($nav)->not->toHaveKey('charts.php:');
});
6 changes: 6 additions & 0 deletions tests/bootstrap-unit.php
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,12 @@ function cacti_log($message, $also_print = false, $log_type = '', $level = 0) {
}
}

if (!function_exists('cacti_version_compare')) {
function cacti_version_compare(string $version1, string $version2, string $operator = '>'): bool {
return version_compare($version1, $version2, $operator);
}
}

if (!function_exists('cacti_sizeof')) {
function cacti_sizeof($array) {
return is_array($array) ? count($array) : 0;
Expand Down
Loading