Skip to content

Commit

Permalink
Add option to restrict users by role that are available in the User S…
Browse files Browse the repository at this point in the history
…wicther panel.
  • Loading branch information
adrianbj committed Mar 14, 2018
1 parent 1007ccf commit 2c3cfa9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
20 changes: 19 additions & 1 deletion TracyDebugger.module
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class TracyDebugger extends WireData implements Module, ConfigurableModule {
'summary' => __('Tracy debugger from Nette with several PW specific custom tools.', __FILE__),
'author' => 'Adrian Jones',
'href' => 'https://processwire.com/talk/topic/12208-tracy-debugger/',
'version' => '4.9.27',
'version' => '4.9.28',
'autoload' => true,
'singular' => true,
'requires' => 'ProcessWire>=2.7.2, PHP>=5.4.4',
Expand Down Expand Up @@ -211,6 +211,7 @@ class TracyDebugger extends WireData implements Module, ConfigurableModule {
"debugModePanelSections" => array('pagesLoaded', 'modulesLoaded', 'hooks', 'databaseQueries', 'selectorQueries', 'timers', 'user', 'cache', 'autoload'),
"diagnosticsPanelSections" => array('filesystemFolders'),
"snippetsPath" => 'templates',
"userSwitcherRestricted" => null,
"todoIgnoreDirs" => 'git, svn, images, img, errors, sass-cache, node_modules',
"todoScanModules" => null,
"todoAllowedExtensions" => 'php, module, inc, txt, latte, html, htm, md, css, scss, less, js',
Expand Down Expand Up @@ -2712,6 +2713,23 @@ class TracyDebugger extends WireData implements Module, ConfigurableModule {
if($data['customPhpCode']) $f->attr('value', $data['customPhpCode']);
$fieldset->add($f);

// User Switcher Panel
$fieldset = $this->wire('modules')->get("InputfieldFieldset");
$fieldset->label = __('User Switcher panel', __FILE__);
$wrapper->add($fieldset);

$f = $this->wire('modules')->get("InputfieldAsmSelect");
$f->attr('name', 'userSwitcherRestricted');
$f->label = __('Restricted Roles', __FILE__);
$f->description = __('Users with selected roles will not be available from the list of users to switch to.', __FILE__);
$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__);
$f->setAsmSelectOption('sortable', false);
foreach($this->wire('roles') as $role) {
$f->addOption($role->id, $role->name);
}
if($data['userSwitcherRestricted']) $f->attr('value', $data['userSwitcherRestricted']);
$fieldset->add($f);

// Server Type Indicator
$fieldset = $this->wire('modules')->get("InputfieldFieldset");
$fieldset->label = __('Server type indicator', __FILE__);
Expand Down
2 changes: 1 addition & 1 deletion panels/UserSwitcherPanel.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public function getPanel() {
<select name="userSwitcher" size="5" style="width:100% !important; height:90px !important">';
if(!$this->wire('user')->isLoggedin()) $out .= '<option value="guest" selected="selected">guest</option>';

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

0 comments on commit 2c3cfa9

Please sign in to comment.