lib: Add View::hasPermission()

This commit is contained in:
Eric Lippmann 2015-01-23 09:36:45 +01:00
parent 6da3cb8403
commit cd8822ceff

View File

@ -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.