function beforeRender(&$controller) { $Permit =& PermitComponent::getInstance(); if (empty($Permit->_user)) { $Permit->_user = $controller->Toolbar->Session->read("{$Permit->settings['path']}"); } return array('user' => $Permit->_user, 'routes' => $Permit->routes, 'executed' => $Permit->executed); }
/** * Creates an HTML link. * * If $url starts with "http://" this is treated as an external link. Else, * it is treated as a path to controller/action and parsed against the routes * included in app/config/permit.php. If there is a match and the User's session * clears with the rules, it is then sent off to the HtmlHelper::link() method * * If the $url is empty, $title is used instead. * * ### Options * * - `escape` Set to false to disable escaping of title and attributes. * * @param string $title The content to be wrapped by <a> tags. * @param mixed $url Cake-relative URL or array of URL parameters, or external URL (starts with http://) * @param array $options Array of HTML attributes. * @param string $confirmMessage JavaScript confirmation message. * @return string An `<a />` element. * @author Jose Diaz-Gonzalez */ public function link($title, $url = null, $options = array(), $confirmMessage = false) { if (!is_array($url)) { return $this->Html->link($title, $url, $options, $confirmMessage); } if (!isset($url['plugin']) && !empty($url['plugin'])) { $url['plugin'] = $this->params['plugin']; } if (!isset($url['controller']) && empty($url['controller'])) { $url['controller'] = $this->params['controller']; } if (!isset($url['action']) && empty($url['action'])) { $url['action'] = $this->params['action']; } if (empty($this->routes)) { $Permit =& PermitComponent::getInstance(); $this->routes = $Permit->routes; } if (empty($this->routes)) { return $this->Html->link($title, $url, $options, $confirmMessage); } foreach ($this->routes as $route) { if ($this->parse($url, $route)) { return $this->execute($route, $title, $url, $options, $confirmMessage); } } return $this->Html->link($title, $url, $options, $confirmMessage); }
function beforeRender(&$controller) { $permit_component =& PermitComponent::getInstance(); $permit =& Permit::getInstance(); return array('clearances' => $permit->clearances, 'executed' => $permit_component->executed); }
/** * Connects a route to a given ruleset * * @param array $route array describing a route * @param array $rules array of rules regarding the route * @param array $redirect Array containing the url to redirect to on route fail * @return array Array of connected routes */ function access($route, $rules = array(), $redirect = array()) { $Permit =& PermitComponent::getInstance(); $Permit->access($route, $rules, $redirect); }
function testPermitObject() { $permit = Permit::getInstance(); $Permit = PermitComponent::getInstance(); $this->assertEqual(count($Permit->routes), 0); Permit::access(array('controller' => 'posts', 'action' => array('add', 'edit', 'delete')), array('auth' => true), array('redirect' => array('controller' => 'users', 'action' => 'login'))); $this->assertEqual(count($Permit->routes), 1); Permit::access(array('controller' => 'users'), array('auth' => true), array('element' => 'auth_error', 'redirect' => array('controller' => 'users', 'action' => 'login'))); $this->assertEqual(count($Permit->routes), 2); $expected = array('route' => array('controller' => 'posts', 'action' => array('add', 'edit', 'delete')), 'rules' => array('auth' => array('group' => 'admin')), 'redirect' => array('controller' => 'users', 'action' => 'login'), 'message' => __('Access denied', true), 'element' => 'default', 'params' => array(), 'key' => 'flash'); $this->assertEqual(current($Permit->routes), $expected); reset($Permit->routes); $expected = array('route' => array('controller' => 'users'), 'rules' => array('auth' => true), 'redirect' => array('controller' => 'users', 'action' => 'login'), 'message' => __('Access denied', true), 'element' => 'auth_error', 'params' => array(), 'key' => 'flash'); $this->assertEqual(end($Permit->routes), $expected); reset($Permit->routes); }
function access($route, $rules = array(), $redirect = array()) { $permitComponent =& PermitComponent::getInstance(); $self =& Permit::getInstance(); if (empty($rules)) { return $permitComponent->routes; } $redirect = array_merge(array('redirect' => $self->redirect, 'message' => __('Access denied', true), 'trace' => false, 'element' => 'default', 'params' => array(), 'key' => 'flash'), $redirect); $newRoute = array('route' => $route, 'rules' => $rules, 'redirect' => $redirect['redirect'], 'message' => $redirect['message'], 'element' => $redirect['element'], 'params' => $redirect['params'], 'key' => $redirect['key'], 'trace' => $redirect['trace']); $permitComponent->routes[] = $newRoute; $self->clearances[] = $newRoute; return $permitComponent->routes; }