From 4a5edad2f6416f8d5ac8564aa5eb17ae267b10ed Mon Sep 17 00:00:00 2001 From: Jash Ambaliya <87864439+AJ0070@users.noreply.github.com> Date: Mon, 23 Nov 2026 19:19:10 +0530 Subject: [PATCH] fix: filter view lists only the filters the user can view refs #7562 (#7563) --- tests/php/test_filter_view_lists_viewable.php | 91 +++++++++++++++++++ web/skins/classic/views/filter.php | 2 + 2 files changed, 93 insertions(+) create mode 100644 tests/php/test_filter_view_lists_viewable.php diff --git a/tests/php/test_filter_view_lists_viewable.php b/tests/php/test_filter_view_lists_viewable.php new file mode 100644 index 0000000000..394dec2bed --- /dev/null +++ b/tests/php/test_filter_view_lists_viewable.php @@ -0,0 +1,91 @@ +id = $id; + $this->name = $name; + $this->viewable = $viewable; + $this->bg = $bg; + $this->conc = $conc; + } + + public function Id() { return $this->id; } + public function Name() { return $this->name; } + public function Background() { return $this->bg; } + public function Concurrent() { return $this->conc; } + public function canView() { return $this->viewable; } + } + + $root = isset($argv[1]) ? rtrim($argv[1], '/') : __DIR__.'/../..'; + $path = $root.'/web/skins/classic/views/filter.php'; + $src = file_get_contents($path); + if ($src === false) { + fwrite(STDERR, "FAIL - could not read $path\n"); + exit(1); + } + + if (!preg_match('/^# Build filter names list.*?\n\}\n/ms', $src, $m)) { + fwrite(STDERR, "FAIL - could not find the filter names list loop in $path\n"); + exit(1); + } + + $GLOBALS['filters'] = array( + new FakeFilter(1, 'mine', true), + new FakeFilter(2, 'theirs', false), + new FakeFilter(3, 'shared', true, true), + ); + + function runFilterNamesLoop($code) { + $filterNames = array(); + eval($code); + return $filterNames; + } + + $filterNames = runFilterNamesLoop($m[0]); + + $failed = false; + + $keys = array_keys($filterNames); + if ($keys === array(1, 3)) { + echo "ok - only viewable filters are listed\n"; + } else { + echo "FAIL - only viewable filters are listed (got " . var_export($keys, true) . ")\n"; + $failed = true; + } + + if (!isset($filterNames[2])) { + echo "ok - another user's filter is not listed\n"; + } else { + echo "FAIL - another user's filter is not listed (got " . var_export($filterNames[2], true) . ")\n"; + $failed = true; + } + + if (isset($filterNames[3]) && $filterNames[3] === 'shared*') { + echo "ok - background filter name gets '*'\n"; + } else { + echo "FAIL - background filter name gets '*' (got " . var_export(isset($filterNames[3]) ? $filterNames[3] : null, true) . ")\n"; + $failed = true; + } + + exit($failed ? 1 : 0); +} diff --git a/web/skins/classic/views/filter.php b/web/skins/classic/views/filter.php index 0ee9e7047c..c86c158ad8 100644 --- a/web/skins/classic/views/filter.php +++ b/web/skins/classic/views/filter.php @@ -48,6 +48,8 @@ if (isset($_REQUEST['Id']) and $_REQUEST['Id']) { # Build filter names list for dropdown foreach (ZM\Filter::find(null, array('order'=>'lower(Name)')) as $Filter) { + # Another user's filter, with its command and email address, is not for this user to see. + if (!$Filter->canView()) continue; $filterNames[$Filter->Id()] = (defined('ZM_WEB_ID_ON_FILTER') and ZM_WEB_ID_ON_FILTER) ? $Filter->Id() . ' ' . $Filter->Name() : $Filter->Name(); if ($Filter->Background()) $filterNames[$Filter->Id()] .= '*'; if ($Filter->Concurrent()) $filterNames[$Filter->Id()] .= '&';