diff --git a/Helper/Config.php b/Helper/Config.php index f25cb31..cab8ea4 100644 --- a/Helper/Config.php +++ b/Helper/Config.php @@ -25,21 +25,35 @@ public function __construct(Context $context, protected DeploymentConfig $deploy /** * Check whether the module is enabled. */ - public function isEnabled(): bool + public function isEnabledInCurrentArea(): bool { - $enabled = $this->scopeConfig->isSetFlag('smile_debugtoolbar/configuration/enabled'); - if (!$enabled) { + if (!$this->isEnabled()) { return false; } - $enabledAdmin = $this->scopeConfig->isSetFlag('smile_debugtoolbar/configuration/enabled_admin'); - if (!$enabledAdmin && $this->isAdminArea()) { + if (!$this->isEnabledAdmin() && $this->isAdminArea()) { return false; } return true; } + /** + * Check whether the module is enabled globally. + */ + public function isEnabled(): bool + { + return $this->scopeConfig->isSetFlag('smile_debugtoolbar/configuration/enabled'); + } + + /** + * Check whether the module is enabled for the admin area. + */ + public function isEnabledAdmin(): bool + { + return $this->scopeConfig->isSetFlag('smile_debugtoolbar/configuration/enabled_admin'); + } + /** * Get the config value for keep_last_execution. */ diff --git a/Model/Message/ProductionMode.php b/Model/Message/ProductionMode.php new file mode 100644 index 0000000..a951df5 --- /dev/null +++ b/Model/Message/ProductionMode.php @@ -0,0 +1,61 @@ +deploymentConfig->get(State::PARAM_MODE) !== State::MODE_PRODUCTION; + } + + /** + * @inheritdoc + */ + public function getText() + { + return __( + <<<'EOT' + The DebugToolbar module is not supposed to be installed on production environments. + It may expose sensitive information if it is enabled. + EOT + ); + } + + /** + * @inheritdoc + */ + public function getSeverity() + { + return $this->configHelper->isEnabled() + ? MessageInterface::SEVERITY_CRITICAL + : MessageInterface::SEVERITY_MAJOR; + } +} diff --git a/Observer/AddToolbar.php b/Observer/AddToolbar.php index e006958..85868df 100644 --- a/Observer/AddToolbar.php +++ b/Observer/AddToolbar.php @@ -42,7 +42,7 @@ public function __construct( */ public function execute(Observer $observer) { - if (!$this->configHelper->isEnabled()) { + if (!$this->configHelper->isEnabledInCurrentArea()) { return; } diff --git a/Plugin/App/Action/AbstractActionPlugin.php b/Plugin/App/Action/AbstractActionPlugin.php index a3029c5..e57060f 100644 --- a/Plugin/App/Action/AbstractActionPlugin.php +++ b/Plugin/App/Action/AbstractActionPlugin.php @@ -25,7 +25,7 @@ public function __construct(protected DataHelper $dataHelper, protected ConfigHe */ public function beforeDispatch(MagentoAction $subject, RequestInterface $request): array { - if ($this->configHelper->isEnabled()) { + if ($this->configHelper->isEnabledInCurrentArea()) { $className = get_class($subject); $className = preg_replace('!\\\\Interceptor$!', '', $className); $this->dataHelper->setValue('controller_classname', $className); diff --git a/Plugin/App/CachePlugin.php b/Plugin/App/CachePlugin.php index f8c909d..b944452 100644 --- a/Plugin/App/CachePlugin.php +++ b/Plugin/App/CachePlugin.php @@ -25,7 +25,7 @@ public function __construct(protected ConfigHelper $configHelper, protected Cach */ public function aroundLoad(CacheInterface $subject, Closure $closure, string $identifier): mixed { - if (!$this->configHelper->isEnabled()) { + if (!$this->configHelper->isEnabledInCurrentArea()) { return $closure($identifier); } @@ -54,7 +54,7 @@ public function aroundSave( array $tags = [], ?int $lifeTime = null ): bool { - if (!$this->configHelper->isEnabled()) { + if (!$this->configHelper->isEnabledInCurrentArea()) { return $closure($data, $identifier, $tags, $lifeTime); } @@ -77,7 +77,7 @@ public function aroundSave( */ public function aroundRemove(CacheInterface $subject, Closure $closure, string $identifier): bool { - if (!$this->configHelper->isEnabled()) { + if (!$this->configHelper->isEnabledInCurrentArea()) { return $closure($identifier); } diff --git a/Plugin/App/HttpPlugin.php b/Plugin/App/HttpPlugin.php index fdcd556..b5878d2 100644 --- a/Plugin/App/HttpPlugin.php +++ b/Plugin/App/HttpPlugin.php @@ -24,7 +24,7 @@ public function __construct(protected DataHelper $dataHelper, protected ConfigHe */ public function beforeLaunch(MagentoHttp $subject): array { - if ($this->configHelper->isEnabled()) { + if ($this->configHelper->isEnabledInCurrentArea()) { $this->dataHelper->startTimer('app_http'); } diff --git a/ViewModel/Loader.php b/ViewModel/Loader.php index 0a55b10..0ce3de9 100644 --- a/ViewModel/Loader.php +++ b/ViewModel/Loader.php @@ -18,6 +18,6 @@ public function __construct(protected ConfigHelper $configHelper) */ public function isToolbarEnabled(): bool { - return $this->configHelper->isEnabled(); + return $this->configHelper->isEnabledInCurrentArea(); } } diff --git a/ViewModel/Toolbar.php b/ViewModel/Toolbar.php index 01bb3ba..b1c5cd2 100644 --- a/ViewModel/Toolbar.php +++ b/ViewModel/Toolbar.php @@ -19,7 +19,7 @@ public function __construct(protected DataHelper $dataHelper, protected ConfigHe */ public function isToolbarEnabled(): bool { - return $this->configHelper->isEnabled(); + return $this->configHelper->isEnabledInCurrentArea(); } /** diff --git a/etc/adminhtml/di.xml b/etc/adminhtml/di.xml new file mode 100644 index 0000000..0745a58 --- /dev/null +++ b/etc/adminhtml/di.xml @@ -0,0 +1,9 @@ + + + + + Smile\DebugToolbar\Model\Message\ProductionMode + + + +