/** * Test al-lowed action for public role and no debug. * * @return void */ public function testAllowedActionNoPrefixAndNoDebug() { Configure::write('debug', 0); $this->userData['role_id'] = Role::PUBLIC_ID; $this->request->params['controller'] = 'Pages'; $this->request->params['prefix'] = ''; $this->request->params['plugin'] = false; $Permissions = new Permissions($this->userData, $this->request); $this->assertSame(['display'], $Permissions->getAllowed()); Configure::write('debug', 1); }
/** * Initialize hook method. * * @param array $config * @return void */ public function initialize(array $config) { $this->config('loginRedirect', $this->_loginRedirect()); $controller = $this->_registry->getController(); $this->_controller = $controller; $permissions = new Permissions($this->user(), $this->request); $allowedActions = $permissions->getAllowed(); $isAllowed = Arr::in($this->request->param('action'), $allowedActions); $this->request->offsetSet('isAllowed', $isAllowed); if ($this->user('role_id') == Role::ADMIN_ID) { $this->allow(); } else { $this->allow($allowedActions); } $controller->set('loggedUser', $this->_getLoggedUserForView()); parent::initialize($config); }