From cd8822ceff7be9acc8ba7b93137d8231ce491f37 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Fri, 23 Jan 2015 09:36:45 +0100 Subject: [PATCH] lib: Add View::hasPermission() --- library/Icinga/Web/View.php | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/library/Icinga/Web/View.php b/library/Icinga/Web/View.php index 7a954934a..2122662ac 100644 --- a/library/Icinga/Web/View.php +++ b/library/Icinga/Web/View.php @@ -4,10 +4,11 @@ namespace Icinga\Web; +use Closure; +use Zend_View_Abstract; +use Icinga\Authentication\Manager; use Icinga\Exception\ProgrammingError; use Icinga\Util\Translator; -use Zend_View_Abstract; -use Closure; /** * Icinga view @@ -36,6 +37,13 @@ class View extends Zend_View_Abstract */ private $helperFunctions = array(); + /** + * Authentication manager + * + * @type \Icinga\Authentication\Manager|null + */ + private $auth; + /** * Create a new view object * @@ -154,6 +162,31 @@ class View extends Zend_View_Abstract } } + /** + * Get the authentication manager + * + * @return Manager + */ + public function Auth() + { + if ($this->auth === null) { + $this->auth = Manager::getInstance(); + } + return $this->auth; + } + + /** + * Whether the current user has the given permission + * + * @param string $permission Name of the permission + * + * @return bool + */ + public function hasPermission($permission) + { + return $this->Auth()->hasPermission($permission); + } + /** * Use to include the view script in a scope that only allows public * members.