Repository navigation
refactor: share the device scope and filter across the remaining panels - #435
Open
somethingwithproof wants to merge 1 commit into
Open
somethingwithproof wants to merge 1 commit into
somethingwithproof wants to merge 1 commit into
Conversation
somethingwithproof
force-pushed
the
refactor/device-scope-remaining
branch
3 times, most recently
from
October 24, 2026 14:00
e873c2a to
cce5955
Compare
Refs Cacti#384 Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
somethingwithproof
force-pushed
the
refactor/device-scope-remaining
branch
from
October 24, 2026 14:04
cce5955 to
5b0c826
Compare
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Description
Moves the repeated permission preamble (
get_simple_device_perms(),intropage_get_allowed_devices(), then building theIN (...)text) intop5.php,graphs.php,analyze.phpandsystem.phponto the helpers from #379. Behavior is unchanged.intropage_device_filter($user_id, $column)inincludes/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 intop5.php, 6 ingraphs.php, 1 insystem.php.intropage_device_scope()only:graph_host()(it never builds a condition) and the twoanalyse_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, andmisc.phpmaint(), whose two permission calls take different user arguments ($user_idand$_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_hostis checked by outcome. 41 of the 44 cases are panel behavior and pass unchanged ondevelop; 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 warningsdevelopalready has.tests/bootstrap-unit.phpgains a seedabledb_fetch_cell_prepared(), a recordeddb_fetch_cell()(separate array, so existing call counts are unchanged) and adb_table_exists()stub.Merge order: this branch edits the same
tests/bootstrap-unit.phpstubs as #432, which adds a__test_queryhook 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
Checklist: