Skip to content

Commit ab1ef1c

Browse files
devinfdbarryvdh
authored andcommitted
Update GateCollector (barryvdh#735)
addCheck assumed that the authorized model was the authenticated App\User. In my case I have a App\User, App\Account and an App\AccountUser. The App\User is authenticated but authorizations are on the App\AccountUser which does not implement Authenticatable. This change type hints $user to Authorizable because thats what is really important in this collector. It also uses the Authorizable's base class name in the message instead of assuming user.
1 parent 43ba768 commit ab1ef1c

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/DataCollector/GateCollector.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
use DebugBar\DataCollector\MessagesCollector;
66
use Illuminate\Contracts\Auth\Access\Gate;
7-
use Illuminate\Contracts\Auth\Authenticatable;
7+
use Illuminate\Contracts\Auth\Access\Authorizable;
88
use Symfony\Component\HttpKernel\DataCollector\Util\ValueExporter;
99

1010
/**
@@ -25,14 +25,14 @@ public function __construct(Gate $gate)
2525
$gate->after([$this, 'addCheck']);
2626
}
2727

28-
public function addCheck(Authenticatable $user, $ability, $result, $arguments = [])
28+
public function addCheck(Authorizable $user, $ability, $result, $arguments = [])
2929
{
3030
$label = $result ? 'success' : 'error';
3131

3232
$this->addMessage([
3333
'ability' => $ability,
3434
'result' => $result,
35-
'user' => $user->getAuthIdentifier(),
35+
snake_case(class_basename($user)) => $user->id,
3636
'arguments' => $this->exporter->exportValue($arguments),
3737
], $label, false);
3838
}

0 commit comments

Comments
 (0)