function beforeRender(&$controller)
 {
     $permit_component =& PermitComponent::getInstance();
     $permit =& Permit::getInstance();
     return array('clearances' => $permit->clearances, 'executed' => $permit_component->executed);
 }
Exemple #2
0
 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);
 }
Exemple #3
0
 /**
  * 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.
  * @access public
  * @author Jose Diaz-Gonzalez
  */
 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 =& Permit::getInstance();
         // $permit->clearances should contain an array of all clearances now
         $this->routes = $permit->clearances;
     }
     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);
             break;
         }
     }
     return $this->Html->link($title, $url, $options, $confirmMessage);
 }
Exemple #4
0
 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;
 }