Skip to content

Commit 5f513a5

Browse files
committed
add admin permission config flag
1 parent 16209af commit 5f513a5

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

_config/debugbar.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ LeKoala\DebugBar\DebugBar:
4747
# set 0 to disable
4848
template_rendering_warning_level: 2.0
4949
show_db_warning: true
50+
user_admin_only: false
5051
SilverStripe\Control\Director:
5152
rules:
5253
'__debugbar': 'LeKoala\DebugBar\DebugBarController'

code/DebugBar.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
use SilverStripe\Config\Collections\DeltaConfigCollection;
4444
use SilverStripe\Config\Collections\CachedConfigCollection;
4545
use LeKoala\DebugBar\Bridge\SymfonyMailer\SymfonyMailerCollector;
46+
use SilverStripe\Security\Permission;
4647

4748
/**
4849
* A simple helper
@@ -472,6 +473,9 @@ public static function disabledCriteria()
472473
if (self::isExcludedRoute()) {
473474
$reasons[] = 'Route excluded';
474475
}
476+
if (self::hasRequiredPermissions()) {
477+
$reasons[] = 'Not allowed';
478+
}
475479
return $reasons;
476480
}
477481

@@ -536,6 +540,17 @@ public static function isDisabled()
536540
return false;
537541
}
538542

543+
/**
544+
* @return bool
545+
*/
546+
public static function hasRequiredPermissions()
547+
{
548+
if (static::config()->get('user_admin_only')) {
549+
return Permission::check('ADMIN');
550+
}
551+
return true;
552+
}
553+
539554
/**
540555
* @return bool
541556
*/

0 commit comments

Comments
 (0)