I have been thinking a lot recently that I like to have the debug bar on even in production, however, I want it to only work and show up for me, a.k.a role admin user.
Having the debug bar in production has allowed me to do solve problems 100x faster at times. No having to replicate the envo, which may not even work, etc etc. Just view the page right there on the live data and workings.
I cannot use the IP restriction like I can on some projects of mine since I will not be connecting to this site through static IPs.
So what do you think about adding the ability to RBAC the showing of the debug module?
Now you can override checkAccess(). But it's also possible to add an ability to specify access callback. Not sure it's a good idea though.
Ah yeah good point actually, maybe that is the better way of doing it
Though will checkaccess run when the user is available?
Availability of user won't affect checkAccess(). Another possibility is to attach custom handler to EVENT_BEFORE_ACTION of the module. If this handler will return false then action won't be executed.
I think there's no need to actually add any additional extension points.
Ok Kool, I will try this out, thanks
On 22 November 2014 at 23:05, Alexander Makarov [email protected]
wrote:
Availability of user won't affect checkAccess(). Another possibility is
to attach custom handler to EVENT_BEFORE_ACTION of the module. If this
handler will return false then action won't be executed.I think there's no need to actually add any additional extension points.
—
Reply to this email directly or view it on GitHub
https://github.com/yiisoft/yii2/issues/6177#issuecomment-64098993.
I have tried this however, I believe I have hit into a problem.
When I extend the debug Module into my config:
'bootstrap' => ['debug'],
'modules' => [
'debug' => [
'class' => 'common\components\Module',
]
],
It causes the debug controller to seek MY applications directory for the panels and debug toolbar:
Exception 'yii\base\InvalidParamException' with message 'The view file does not exist: /srv/server_ws/xxx/common/components/views/default/toolbar.php'
in /srv/server_ws/xxx/vendor/yiisoft/yii2/base/View.php:226
Stack trace:
#0 /srv/server_ws/xxx/vendor/yiisoft/yii2/base/View.php(149): yii\base\View->renderFile('/srv/server_ws/...', Array, Object(yii\debug\controllers\DefaultController))
#1 /srv/server_ws/xxx/vendor/yiisoft/yii2/base/Controller.php(398): yii\base\View->render('toolbar', Array, Object(yii\debug\controllers\DefaultController))
#2 /srv/server_ws/xxx/vendor/yiisoft/yii2-debug/controllers/DefaultController.php(98): yii\base\Controller->renderPartial('toolbar', Array)
#3 [internal function]: yii\debug\controllers\DefaultController->actionToolbar('5471cdf75d403')
#4 /srv/server_ws/xxx/vendor/yiisoft/yii2/base/InlineAction.php(55): call_user_func_array(Array, Array)
#5 /srv/server_ws/xxx/vendor/yiisoft/yii2/base/Controller.php(151): yii\base\InlineAction->runWithParams(Array)
#6 /srv/server_ws/xxx/vendor/yiisoft/yii2/base/Module.php(455): yii\base\Controller->runAction('toolbar', Array)
#7 /srv/server_ws/xxx/vendor/yiisoft/yii2/web/Application.php(83): yii\base\Module->runAction('debug/default/t...', Array)
#8 /srv/server_ws/xxx/vendor/yiisoft/yii2/base/Application.php(375): yii\web\Application->handleRequest(Object(common\components\Request))
#9 /srv/server_ws/xxx/frontend/web/index.php(17): yii\base\Application->run()
#10 {main}
Ok I eventually got this working by overriding the base path function:
/**
* Returns the root directory of the module.
* It defaults to the directory containing the module class file.
* @return string the root directory of the module.
*/
public function getBasePath()
{
if ($this->_basePath === null) {
$class = new \ReflectionClass(new yii\debug\Module('debug'));
$this->_basePath = dirname($class->getFileName());
}
return $this->_basePath;
}
Maybe there is a better way for this to be done?
For anyone else who comes here asking, I have written it up here: http://sammaye.wordpress.com/2014/11/23/getting-yii2-debug-to-show-on-user-role-instead-of-ip/ with a full example class.
Most helpful comment
For anyone else who comes here asking, I have written it up here: http://sammaye.wordpress.com/2014/11/23/getting-yii2-debug-to-show-on-user-role-instead-of-ip/ with a full example class.