Skip to content

refactor: share the device scope and filter across the remaining panels - #435

Open
somethingwithproof wants to merge 1 commit into
Cacti:developfrom
somethingwithproof:refactor/device-scope-remaining
Open

somethingwithproof wants to merge 1 commit into
Cacti:developfrom
somethingwithproof:refactor/device-scope-remaining

Conversation

@somethingwithproof

@somethingwithproof somethingwithproof commented Oct 24, 2026 •

Copy link
Copy Markdown
Member

Description

Moves the repeated permission preamble (get_simple_device_perms(), intropage_get_allowed_devices(), then building the IN (...) text) in top5.php, graphs.php, analyze.php and system.php onto the helpers from #379. Behavior is unchanged.

  • New intropage_device_filter($user_id, $column) in includes/functions.php: intropage_device_scope() plus the ready condition (AND id IN (3,7,9), or an empty string for a user who sees every device). 15 sites use it, 8 in top5.php, 6 in graphs.php, 1 in system.php.
  • 4 sites use intropage_device_scope() only: graph_host() (it never builds a condition) and the two analyse_tree_host_graph* functions, which build several different column prefixes from one list.

Left alone on purpose: thold.php (3 sites), because #432 changes that file, and misc.php maint(), whose two permission calls take different user arguments ($user_id and $_SESSION['sess_user_id']), so it is not the same shape. The poller sets the session user to the panel's user before calling the panel, so the two currently agree.

Related Issue

Refs #384

Motivation and Context

#384 asks for the remaining sites to be converted family by family, with each IN() clause checked. The condition text is the part that varied, so the second helper takes the column and leaves the permission logic in one place. It also keeps the new code under SonarCloud's duplication limit, which a copy of the four-line scope block at every site did not.

How Has This Been Tested?

New tests/Unit/PanelDeviceScopeTest.php (44 cases) covers every converted function: a restricted user gets the allowed host ids in the query with the same column text as before, a simple-permission user gets no filter, and a restricted user with no devices gets no query or zero rows. graph_host is checked by outcome. 41 of the 44 cases are panel behavior and pass unchanged on develop; the other 3 test the new helper. Breaking either helper makes 14 or more cases fail. Full suite on PHP 8.4: 116 passed, plus the 2 warnings develop already has. tests/bootstrap-unit.php gains a seedable db_fetch_cell_prepared(), a recorded db_fetch_cell() (separate array, so existing call counts are unchanged) and a db_table_exists() stub.

Merge order: this branch edits the same tests/bootstrap-unit.php stubs as #432, which adds a __test_query hook that makes my two stub additions unnecessary. Please merge #432 first; I will rebase this onto it and drop those bootstrap changes.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation repository accordingly.

@somethingwithproof
somethingwithproof force-pushed the refactor/device-scope-remaining branch 3 times, most recently from e873c2a to cce5955 Compare October 24, 2026 14:00
@somethingwithproof somethingwithproof changed the title refactor: adopt intropage_device_scope() in the remaining panels refactor: share the device scope and filter across the remaining panels Oct 24, 2026
Refs Cacti#384

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
@somethingwithproof
somethingwithproof force-pushed the refactor/device-scope-remaining branch from cce5955 to 5b0c826 Compare October 24, 2026 14:04
@sonarqubecloud

Copy link
Copy Markdown

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.

1 participant