Skip to content

refactor: add intropage_device_scope() and adopt it across the busiest panels - #379

Merged
TheWitness merged 3 commits into
Cacti:developfrom
somethingwithproof:refactor/busiest-family
Sep 10, 2026
Merged

refactor: add intropage_device_scope() and adopt it across the busiest panels#379
TheWitness merged 3 commits into
Cacti:developfrom
somethingwithproof:refactor/busiest-family

Conversation

@somethingwithproof

@somethingwithproof somethingwithproof commented Aug 30, 2026

Copy link
Copy Markdown
Member

Two commits: the helper plus a coverage harness, then adopting it across the panels that repeat the same device-scope query construction.

Kept together because #378 was fully contained in this branch — reviewing them separately meant reviewing the helper twice.

Supersedes #378.

Extract the repeated get_simple_device_perms + intropage_get_allowed_devices
preamble into one documented helper returning the user's device scope, and adopt
it in alert.php's two panels. Add a phpunit.xml coverage source config and a
behavioural Pest test (with permission-chain stubs) that exercises every branch
of the helper, since the plugin previously had only source-scan tests and no
coverage config.

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
Replace the copied permission preamble in all 14 busiest update/detail functions
with the device_scope helper, and add a behavioural test that drives busiest_cpu
and asserts the host filter (IN clause for a restricted user, none for a simple
user). Extend the test bootstrap so fetch results and config options are
controllable and SELECT SQL is captured.

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
@somethingwithproof somethingwithproof changed the title refactor: adopt device_scope across the busiest panels, with a behavioral test refactor: add intropage_device_scope() and adopt it across the busiest panels Aug 31, 2026
Cacti core now requires PHP >= 8.2, so the 8.1 integration job fails the
composer platform check; Ubuntu Noble also lacks libapache2-mod-php for
non-native versions without the ondrej PPA.

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The new test configuration and CI workflow changes introduce likely breakage/incompatibilities (PHPUnit config vs Pest/PHPUnit versions, CI matrix/runtime setup changes) that should be corrected before approval.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

This PR refactors repeated device-permission scoping logic into a new intropage_device_scope($user_id) helper and adopts it across the busiest/alert panels, while adding a Pest-based coverage/test harness to exercise the helper and verify the busiest panels’ host filtering behavior.

Changes:

  • Add intropage_device_scope() to centralize the “simple perms vs allowed host IDs” resolution used by panels.
  • Update panellib/busiest.php and panellib/alert.php to use the helper instead of duplicating the permission preamble.
  • Introduce a test/coverage harness (Pest + phpunit.xml + bootstrap stubs) and add unit tests for the helper and busiest scope SQL.
File summaries
File Description
include/functions.php Adds intropage_device_scope() helper wrapping the device-permission chain.
panellib/busiest.php Adopts the helper across busiest panels/detail views to de-duplicate scope construction.
panellib/alert.php Adopts the helper for host-alert panels to reduce repeated permission logic.
tests/bootstrap.php Expands test stubs to support scope resolution and capture SQL for assertions.
tests/Unit/DeviceScopeTest.php Adds unit coverage for all branches of intropage_device_scope().
tests/Unit/BusiestScopeTest.php Adds a SQL-capture test ensuring busiest CPU queries apply host scoping correctly.
phpunit.xml Adds test suite + coverage source configuration for the plugin.
.gitignore Ignores PHPUnit/PHP-CS-Fixer caches.
.github/workflows/plugin-ci-workflow.yml Adjusts CI PHP matrix and changes apt update behavior.
Review details
  • Files reviewed: 8/9 changed files
  • Comments generated: 4
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread phpunit.xml
Comment thread .github/workflows/plugin-ci-workflow.yml
Comment thread .github/workflows/plugin-ci-workflow.yml
Comment thread phpunit.xml
@TheWitness
TheWitness merged commit cf8fab7 into Cacti:develop Sep 10, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants