Skip to content

Commit 2c3cfa9

Browse files
committed
Add option to restrict users by role that are available in the User Swicther panel.
1 parent 1007ccf commit 2c3cfa9

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

TracyDebugger.module

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class TracyDebugger extends WireData implements Module, ConfigurableModule {
3232
'summary' => __('Tracy debugger from Nette with several PW specific custom tools.', __FILE__),
3333
'author' => 'Adrian Jones',
3434
'href' => 'https://processwire.com/talk/topic/12208-tracy-debugger/',
35-
'version' => '4.9.27',
35+
'version' => '4.9.28',
3636
'autoload' => true,
3737
'singular' => true,
3838
'requires' => 'ProcessWire>=2.7.2, PHP>=5.4.4',
@@ -211,6 +211,7 @@ class TracyDebugger extends WireData implements Module, ConfigurableModule {
211211
"debugModePanelSections" => array('pagesLoaded', 'modulesLoaded', 'hooks', 'databaseQueries', 'selectorQueries', 'timers', 'user', 'cache', 'autoload'),
212212
"diagnosticsPanelSections" => array('filesystemFolders'),
213213
"snippetsPath" => 'templates',
214+
"userSwitcherRestricted" => null,
214215
"todoIgnoreDirs" => 'git, svn, images, img, errors, sass-cache, node_modules',
215216
"todoScanModules" => null,
216217
"todoAllowedExtensions" => 'php, module, inc, txt, latte, html, htm, md, css, scss, less, js',
@@ -2712,6 +2713,23 @@ class TracyDebugger extends WireData implements Module, ConfigurableModule {
27122713
if($data['customPhpCode']) $f->attr('value', $data['customPhpCode']);
27132714
$fieldset->add($f);
27142715

2716+
// User Switcher Panel
2717+
$fieldset = $this->wire('modules')->get("InputfieldFieldset");
2718+
$fieldset->label = __('User Switcher panel', __FILE__);
2719+
$wrapper->add($fieldset);
2720+
2721+
$f = $this->wire('modules')->get("InputfieldAsmSelect");
2722+
$f->attr('name', 'userSwitcherRestricted');
2723+
$f->label = __('Restricted Roles', __FILE__);
2724+
$f->description = __('Users with selected roles will not be available from the list of users to switch to.', __FILE__);
2725+
$f->notes = __('This can be useful if you use the User system to store frontend "members" and the system has a lot of users.', __FILE__);
2726+
$f->setAsmSelectOption('sortable', false);
2727+
foreach($this->wire('roles') as $role) {
2728+
$f->addOption($role->id, $role->name);
2729+
}
2730+
if($data['userSwitcherRestricted']) $f->attr('value', $data['userSwitcherRestricted']);
2731+
$fieldset->add($f);
2732+
27152733
// Server Type Indicator
27162734
$fieldset = $this->wire('modules')->get("InputfieldFieldset");
27172735
$fieldset->label = __('Server type indicator', __FILE__);

panels/UserSwitcherPanel.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public function getPanel() {
8686
<select name="userSwitcher" size="5" style="width:100% !important; height:90px !important">';
8787
if(!$this->wire('user')->isLoggedin()) $out .= '<option value="guest" selected="selected">guest</option>';
8888

89-
foreach($this->wire('users') as $u) {
89+
foreach($this->wire('users')->find('roles!='.implode(', roles!=', \TracyDebugger::getDataValue('userSwitcherRestricted'))) as $u) {
9090
if(count($u->roles)>1) $out .= '<option value="'.$u->name.'"' . ($this->wire('user')->name === $u->name ? 'selected="selected"' : '') . '>'.$u->name.'</option>';
9191
}
9292
$out .= '

0 commit comments

Comments
 (0)