Skip to content

Commit

Permalink
3.1.1 styling improvements and security fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Luke Towers committed May 31, 2020
1 parent bd2493e commit 86dd29f
Show file tree
Hide file tree
Showing 11 changed files with 1,774 additions and 30 deletions.
63 changes: 53 additions & 10 deletions Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,17 @@
use App;
use Event;
use Config;
use Debugbar;
use BackendAuth;
use Backend\Models\UserRole;
use System\Classes\PluginBase;
use System\Classes\CombineAssets;
use Illuminate\Foundation\AliasLoader;

/**
* Debugbar Plugin Information File
*
* TODO:
* - Fix styling by scoping a html reset to phpdebugbar-openhandler and phpdebugbar
*/
class Plugin extends PluginBase
{
Expand All @@ -26,10 +30,10 @@ class Plugin extends PluginBase
public function pluginDetails()
{
return [
'name' => 'Debugbar',
'description' => 'Debugbar integration for OctoberCMS.',
'name' => 'rainlab.debugbar::lang.plugin.name',
'description' => 'rainlab.debugbar::lang.plugin.description',
'author' => 'RainLab',
'icon' => 'icon-cog',
'icon' => 'icon-bug',
'homepage' => 'https://github.com/rainlab/debugbar-plugin'
];
}
Expand All @@ -43,23 +47,28 @@ public function boot()
Config::set('debugbar', Config::get('rainlab.debugbar::config'));

// Service provider
App::register('\Barryvdh\Debugbar\ServiceProvider');
App::register(\RainLab\Debugbar\Classes\ServiceProvider::class);

// Register alias
$alias = AliasLoader::getInstance();
$alias->alias('Debugbar', '\Barryvdh\Debugbar\Facade');

// Register middleware
if (Config::get('app.debugAjax', false)) {
$this->app['Illuminate\Contracts\Http\Kernel']->pushMiddleware('\RainLab\Debugbar\Middleware\Debugbar');
$this->app['Illuminate\Contracts\Http\Kernel']->pushMiddleware('\RainLab\Debugbar\Middleware\InterpretsAjaxExceptions');
}

Event::listen('cms.page.beforeDisplay', function ($controller, $url, $page) {
// Only show for authenticated backend users
if (!BackendAuth::check()) {
Debugbar::disable();
// Add styling
$addResources = function ($controller) {
$debugBar = $this->app->make('Barryvdh\Debugbar\LaravelDebugbar');
if ($debugBar->isEnabled()) {
$controller->addCss(url(Config::get('cms.pluginsPath', '/plugins') . '/rainlab/debugbar/assets/css/debugbar.css'));
}
};
Event::listen('backend.page.beforeDisplay', $addResources, PHP_INT_MAX);
Event::listen('cms.page.beforeDisplay', $addResources, PHP_INT_MAX);

Event::listen('cms.page.beforeDisplay', function ($controller, $url, $page) {
// Twig extensions
$twig = $controller->getTwig();
if (!$twig->hasExtension(\Barryvdh\Debugbar\Twig\Extension\Debug::class)) {
Expand All @@ -68,4 +77,38 @@ public function boot()
}
});
}

/**
* Register the
*/
public function register()
{
/*
* Register asset bundles
*/
CombineAssets::registerCallback(function ($combiner) {
$combiner->registerBundle('$/rainlab/debugbar/assets/css/debugbar.less');
});
}

/**
* Register the permissions used by the plugin
*
* @return array
*/
public function registerPermissions()
{
return [
'rainlab.debugbar.access_debugbar' => [
'tab' => 'rainlab.debugbar::lang.plugin.name',
'label' => 'rainlab.debugbar::lang.plugin.access_debugbar',
'roles' => UserRole::CODE_DEVELOPER,
],
'rainlab.debugbar.access_stored_requests' => [
'tab' => 'rainlab.debugbar::lang.plugin.name',
'label' => 'rainlab.debugbar::lang.plugin.access_stored_requests',
'roles' => UserRole::CODE_DEVELOPER,
],
];
}
}
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ To install it with Composer, run `composer require rainlab/debugbar-plugin` from

### Usage

Set `debug` to `true` in `config/app.php`, and the debugbar should appear in your backend. See [barryvdh/laravel-debugbar](https://github.com/barryvdh/laravel-debugbar) for more usage instructions and documentation.
Set `debug` to `true` in `config/app.php`, and the debugbar should appear on your site to all authenticated backend users with the `rainlab.debugbar.access_debugbar` permission. If you would like to make the debugbar accessible to all users regardless of authentication & permissions, then set `allow_public_access` to `true` in `config/rainlab/debugbar/config.php`.

See [barryvdh/laravel-debugbar](https://github.com/barryvdh/laravel-debugbar) for more usage instructions and documentation.

To include exceptions in the response header of ajax calls set `debugAjax` to `true` in `config/app.php`.
Loading

0 comments on commit 86dd29f

Please sign in to comment.