/** * 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()); $this->_redirect('/profile/login/'); } else { $this->_redirect('/error/forbidden/'); } } }
/** * Check the permissions of a role through flag and flippers * * @param string $role * @param string $resource * @param string $privilege * @return boolean */ public function flagFlippers($role, $resource, $privilege) { return App_FlagFlippers_Manager::isAllowed($role, $resource, $privilege); }
/** * This method is called automatically when using the name of the helper directly * * @param string $role * @param string $resource * @return boolean */ public function direct($role, $resource) { return App_FlagFlippers_Manager::isAllowed($role, $resource); }
/** * Returns an array with all the pages that will be available for * the current user * * @param array $data * @access protected * @return array */ protected function _filter($data) { $filtered = array(); foreach ($data as $tab) { $filteredPages = array(); if (isset($tab['pages'])) { foreach ($tab['pages'] as $page) { if (App_FlagFlippers_Manager::isAllowed(NULL, $page['controller'], $page['action'])) { $filteredPages[] = $page; } } } if (!empty($filteredPages)) { $filteredTab = array('main' => $tab['main'], 'pages' => $filteredPages); $filtered[] = $filteredTab; } } return $filtered; }
/** * Queries the Flag and Flippers and returns true if the current * user is allowed to access the requested page. * * @param string $action * @param string $controller * @access public * @return string */ public function can($action, $controller = NULL) { $user = Zend_Auth::getInstance()->getIdentity(); if (NULL === $controller) { $controller = $this->_controllerName; } return App_FlagFlippers_Manager::isAllowed($user->username, $controller, $action); }