diff --git a/src/Core/Users/User.php b/src/Core/Users/User.php index a92e28ad5..29541f0b7 100755 --- a/src/Core/Users/User.php +++ b/src/Core/Users/User.php @@ -77,7 +77,7 @@ class User extends Model /** * An array of permissions that this user has. * - * @var array|null + * @var string[]|null */ protected $permissions = null; @@ -378,12 +378,38 @@ class User extends Model } if (is_null($this->permissions)) { - $this->permissions = $this->permissions()->lists('permission')->all(); + $this->permissions = $this->getPermissions(); } return in_array($permission, $this->permissions); } + /** + * Check whether the user has a permission that is like the given string, + * based on their groups. + * + * @param string $match + * @return boolean + */ + public function hasPermissionLike($match) + { + if ($this->isAdmin()) { + return true; + } + + if (is_null($this->permissions)) { + $this->permissions = $this->getPermissions(); + } + + foreach ($this->permissions as $permission) { + if (substr($permission, -strlen($match)) === $match) { + return true; + } + } + + return false; + } + /** * Get the notification types that should be alerted to this user, according * to their preferences. @@ -595,6 +621,16 @@ class User extends Model return Permission::whereIn('group_id', $groupIds); } + /** + * Get a list of permissions that the user has. + * + * @return string[] + */ + public function getPermissions() + { + return $this->permissions()->lists('permission')->all(); + } + /** * Define the relationship with the user's access tokens. *