diff --git a/.github/copilot-instructions.md b/.github/copilot-instructions.md index 0e94f4d..df00725 100644 --- a/.github/copilot-instructions.md +++ b/.github/copilot-instructions.md @@ -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); ``` diff --git a/CHANGELOG.md b/CHANGELOG.md index 805f45f..2977cac 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/locales/po/cacti.pot b/locales/po/cacti.pot index 36bdc9a..fd9a1e9 100644 --- a/locales/po/cacti.pot +++ b/locales/po/cacti.pot @@ -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 "" diff --git a/phpunit.xml b/phpunit.xml index e9ef4a5..ccbfff2 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -28,6 +28,7 @@ setup.php + system/upgrade.php lib/funct_calculate.php lib/funct_export.php lib/funct_html.php diff --git a/setup.php b/setup.php index 69f5a23..51cac9c 100644 --- a/setup.php +++ b/setup.php @@ -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); @@ -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'), @@ -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'), @@ -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; } @@ -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']); } diff --git a/system/upgrade.php b/system/upgrade.php index 8f1662a..bfb48d8 100644 --- a/system/upgrade.php +++ b/system/upgrade.php @@ -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 diff --git a/tests/Unit/ReportitCheckUpgradeTest.php b/tests/Unit/ReportitCheckUpgradeTest.php index 10c67fc..1e44c84 100644 --- a/tests/Unit/ReportitCheckUpgradeTest.php +++ b/tests/Unit/ReportitCheckUpgradeTest.php @@ -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%"'); +}); diff --git a/tests/Unit/ReportitConfigArraysAndSettingsTest.php b/tests/Unit/ReportitConfigArraysAndSettingsTest.php index 27484c7..23e3c39 100644 --- a/tests/Unit/ReportitConfigArraysAndSettingsTest.php +++ b/tests/Unit/ReportitConfigArraysAndSettingsTest.php @@ -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:'); +}); diff --git a/tests/bootstrap-unit.php b/tests/bootstrap-unit.php index e87fd0b..58ee9a5 100644 --- a/tests/bootstrap-unit.php +++ b/tests/bootstrap-unit.php @@ -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;