Skip to content

Commit

Permalink
Dont reload component.
Browse files Browse the repository at this point in the history
  • Loading branch information
dereuromark committed Sep 10, 2024
1 parent e18abeb commit 68a568e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/Panel/AuthPanel.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Cake\Core\InstanceConfigTrait;
use Cake\Event\EventInterface;
use DebugKit\DebugPanel;
use RuntimeException;
use TinyAuth\Auth\AclTrait;
use TinyAuth\Auth\AllowTrait;
use TinyAuth\Utility\Config;
Expand Down Expand Up @@ -74,7 +75,10 @@ public function shutdown(EventInterface $event): void {
$rule = $this->_getAllowRule($params);
$this->isPublic = $this->_isActionAllowed($rule, $params['action']);

$controller->loadComponent('TinyAuth.AuthUser');
if (!$controller->components()->has('AuthUser')) {
throw new RuntimeException('You must have TinyAuth.AuthUser component installed');
}

/** @var \TinyAuth\Controller\Component\AuthUserComponent $authUserComponent */
$authUserComponent = $controller->components()->get('AuthUser');
$user = $authUserComponent->user();
Expand Down
4 changes: 4 additions & 0 deletions tests/TestCase/Panel/AuthPanelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public function tearDown(): void {
*/
public function testPanelRestrictedAction() {
$controller = new Controller(new ServerRequest());
$controller->loadComponent('TinyAuth.AuthUser');
$event = new Event('event', $controller);

$this->panel->shutdown($event);
Expand All @@ -86,6 +87,7 @@ public function testPanelPublicAction() {
$request = new ServerRequest(['url' => '/users']);
$request = $request->withAttribute('params', $url);
$controller = new Controller($request);
$controller->loadComponent('TinyAuth.AuthUser');
$event = new Event('event', $controller);

$this->panel->shutdown($event);
Expand Down Expand Up @@ -115,6 +117,7 @@ public function testPanelAclRestricted() {
$request = new ServerRequest(['url' => '/tags']);
$request = $request->withAttribute('params', $url);
$controller = new Controller($request);
$controller->loadComponent('TinyAuth.AuthUser');
$event = new Event('event', $controller);

$this->panel->shutdown($event);
Expand Down Expand Up @@ -147,6 +150,7 @@ public function testPanelAclAllowed() {
'role_id' => 1,
]);
$controller = new Controller($request);
$controller->loadComponent('TinyAuth.AuthUser');
$event = new Event('event', $controller);

$this->panel->shutdown($event);
Expand Down

0 comments on commit 68a568e

Please sign in to comment.