/** * Queries the Flag and Flipper and redirects the user to a different * page if he/her doesn't have the required permissions for * accessing the current page * * @access protected * @return void */ protected function _checkFlagFlippers() { $controllerName = Zend_Registry::get('controllerName'); $actionName = Zend_Registry::get('actionName'); $user = BaseUser::getSession(); if (Zend_Registry::get('IS_DEVELOPMENT') && $controllerName != 'error') { $flagModel = new Flag(); $flag = strtolower(CURRENT_MODULE) . '-' . $controllerName; if (!$flagModel->checkRegistered($flag, App_Inflector::camelCaseToDash($actionName))) { $params = array('originalController' => $controllerName, 'originalAction' => $actionName); $this->_forward('flagflippers', 'error', NULL, $params); return; } } //Check the flag and flippers for ZFDebug if (!App_FlagFlippers_Manager::isAllowed($user->group->name, 'testing', 'zfdebug')) { Zend_Controller_Front::getInstance()->unregisterPlugin('ZFDebug_Controller_Plugin_Debug'); } if (!App_FlagFlippers_Manager::isAllowed($user->group->name, $controllerName, $actionName)) { if (empty($user->id)) { // the user is a guest, save the request and redirect him to // the login page $session = new Zend_Session_Namespace('FrontendRequest'); $session->request = serialize($this->getRequest()); if (Zend_Controller_Front::getInstance()->getRequest()->getModuleName() == "frontend") { $this->_redirect($this->view->url(array('module' => 'frontend', 'controller' => 'user', 'action' => 'login'), 'default', true)); } else { $this->_redirect('/profile/login/'); } } else { $this->_redirect('/error/forbidden/'); } } }
/** * Check if a role is allowed for a certain resource * * @param string $role * @param string $resource * @return boolean */ public static function isAllowed($role = NULL, $resource = NULL, $action = NULL) { if (empty($role)) { $user = BaseUser::getSession(); $role = $user->group->name; } if (!empty($resource)) { $resource = strtolower(CURRENT_MODULE) . '-' . $resource; } if (!empty($action)) { $action = App_Inflector::camelCaseToDash($action); } return App_FlagFlippers_Manager::_getFromRegistry()->isAllowed($role, $resource, $action); }
/** * Load the js files related with the current controller and action * * @return void */ public function AutoloadResources() { $controllerName = Zend_Registry::get('controllerName'); $actionName = Zend_Registry::get('actionName'); if (CURRENT_MODULE == 'backoffice') { $file = ROOT_PATH . '/public/' . CURRENT_MODULE . '/js/autoload/' . $controllerName . '/' . strtolower(App_Inflector::camelCaseToDash($actionName)) . '.js'; } else { $file = ROOT_PATH . '/public/' . CURRENT_MODULE . '/js/autoload/' . strtolower(App_Inflector::camelCaseToDash($controllerName)) . '.js'; } if (file_exists($file)) { if (CURRENT_MODULE == 'backoffice') { $file = $this->view->baseUrl() . '/js/autoload/' . $controllerName . '/' . strtolower(App_Inflector::camelCaseToDash($actionName)) . '.js'; $this->view->headScript()->offsetSetFile(2, $file); } else { $file = $this->view->baseUrl() . '/js/autoload/' . strtolower(App_Inflector::camelCaseToDash($controllerName)) . '.js'; $this->view->headScript()->appendFile($file); } } }
$files[] = $file; } } closedir($dir); } } $resources = array(); foreach ($files as $file) { $filepath = $path . DIRECTORY_SEPARATOR . $file; require_once $filepath; $reflectionFile = new Zend_Reflection_File($filepath); foreach ($reflectionFile->getClasses() as $class) { $classInfo = array('description' => $class->getDocblock()->getShortDescription(), 'name' => strtolower($module) . '-' . App_Inflector::convertControllerName($class->getName()), 'methods' => array()); foreach ($class->getMethods() as $method) { if (substr($method->getName(), -6) == 'Action') { $classInfo['methods'][] = array('description' => $method->getDocblock()->getShortDescription(), 'name' => App_Inflector::convertActionName($method->getName())); } } $resources[] = $classInfo; } } $flagFlippers = App_Cli_FlagFlippers::getInstance(); $inserts = $flagFlippers->generateInserts($resources); if (empty($inserts)) { echo 'No new flags / privileges found.'; exit; } $date = new Zend_Date(); echo '-- Flag And Flipper data' . PHP_EOL; echo '-- Report generated at ' . $date . PHP_EOL; foreach ($inserts as $insert) {