Skip to content

Commit

Permalink
Update GateCollector (barryvdh#735)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
devinfd authored and barryvdh committed Dec 24, 2017
1 parent 43ba768 commit ab1ef1c
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/DataCollector/GateCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use DebugBar\DataCollector\MessagesCollector;
use Illuminate\Contracts\Auth\Access\Gate;
use Illuminate\Contracts\Auth\Authenticatable;
use Illuminate\Contracts\Auth\Access\Authorizable;
use Symfony\Component\HttpKernel\DataCollector\Util\ValueExporter;

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

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

$this->addMessage([
'ability' => $ability,
'result' => $result,
'user' => $user->getAuthIdentifier(),
snake_case(class_basename($user)) => $user->id,
'arguments' => $this->exporter->exportValue($arguments),
], $label, false);
}
Expand Down

0 comments on commit ab1ef1c

Please sign in to comment.