Use `User::can()' in `hasPermission()' of the authentication manager

This commit is contained in:
Eric Lippmann 2014-09-18 14:57:24 +02:00
parent af58732545
commit 794910256a
1 changed files with 3 additions and 12 deletions

View File

@ -145,25 +145,16 @@ class Manager
/** /**
* Whether an authenticated user has a given permission * Whether an authenticated user has a given permission
* *
* This is true if the user owns this permission, false if not.
* Also false if there is no authenticated user
*
* TODO: I'd like to see wildcard support, e.g. module/*
*
* @param string $permission Permission name * @param string $permission Permission name
* @return bool *
* @return bool True if the user owns the given permission, false if not or if not authenticated
*/ */
public function hasPermission($permission) public function hasPermission($permission)
{ {
if (! $this->isAuthenticated()) { if (! $this->isAuthenticated()) {
return false; return false;
} }
foreach ($this->user->getPermissions() as $p) { return $this->user->can($permission);
if ($p === $permission) {
return true;
}
}
return false;
} }
/** /**