Пример #1
1
 /**
  * Change the active status of a flag on development
  *
  * @access public
  * @return void
  */
 public function toggledevAction()
 {
     $id = $this->getRequest()->getParam('id');
     $flagModel = new Flag();
     $flagModel->toggleFlag($id, APP_STATE_DEVELOPMENT);
     App_FlagFlippers_Manager::save();
     $this->_redirect('/flags/');
 }
Пример #2
0
 /**
  * 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/');
         }
     }
 }
Пример #3
0
 /**
  * delete url rewriting 
  * @author EL GUENNUNI Sohaib s.elguennuni@gmail.com
  * @param 
  * @return 
  */
 public function deleteAction()
 {
     $this->title = 'Delete url';
     $form = new DeleteForm();
     $urlModel = new UrlAlias();
     if ($this->getRequest()->isPost()) {
         $urlModel->deleteById($this->_getParam('id'));
         $this->_helper->FlashMessenger(array('msg-success' => 'The url was successfully deleted.'));
         //Regenerate Flag and Flippers
         App_FlagFlippers_Manager::save();
         $this->_redirect('/url/');
     } else {
         $id = $this->_getParam('id');
         $row = $urlModel->findById($id);
         if (empty($row)) {
             $this->_helper->FlashMessenger(array('msg-warning' => sprintf('We cannot find url with id %s', $id)));
             $this->_redirect('/url/');
         }
         $form->populate($row->toArray());
         $this->view->item = $row;
     }
     $this->view->form = $form;
 }
Пример #4
0
 /**
  * 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);
 }
Пример #5
0
 /**
  * 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);
 }
Пример #6
0
 /**
  * Initialize the Flag and Flipper System
  *
  * @return void
  */
 protected function _initFlagFlippers()
 {
     $this->bootstrap('ModulePaths');
     $path = realpath(APPLICATION_PATH . '/../logs/' . CURRENT_MODULE . '/flagflippers.log');
     $logger = new Zend_Log(new Zend_Log_Writer_Stream($path));
     if (!Zend_Registry::get('IS_PRODUCTION')) {
         $logger->addWriter(new Zend_Log_Writer_Firebug());
     }
     Zend_Registry::set('Zend_Log_FlagFlippers', $logger);
     App_FlagFlippers_Manager::load();
 }
 /**
  * Allows users to logically delete other users
  * (should be reserved for administrators)
  *
  * @access public
  * @return void
  */
 public function deleteAction()
 {
     $this->title = 'Delete this user';
     $form = new DeleteForm();
     $userModel = new BackofficeUser();
     if ($this->getRequest()->isPost()) {
         if ($form->isValid($this->getRequest()->getPost())) {
             $userModel->deleteById($form->getValue('id'));
             $this->_helper->FlashMessenger(array('msg-success' => 'The item was successfully deleted.'));
             App_FlagFlippers_Manager::save();
             $this->_redirect('/users/');
         }
     } else {
         $id = $this->_getParam('id');
         if (!is_numeric($id)) {
             $this->_helper->FlashMessenger(array('msg-error' => 'The id you provided is invalid.'));
             $this->_redirect('/users/');
         }
         if ($id == 1) {
             $this->_helper->FlashMessenger(array('msg-error' => 'It is forbidden to mess with the admin account in this release.'));
             $this->_redirect('/users/');
         }
         $row = $userModel->findById($id);
         if (empty($row)) {
             $this->_helper->FlashMessenger(array('msg-error' => 'The requested item cannot be found.'));
             $this->_redirect('/users/');
         }
         $this->view->item = $row;
         $form->populate($row->toArray());
     }
     $this->view->form = $form;
 }
Пример #8
0
 /**
  * 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;
 }
Пример #9
0
 /**
  * Store the Acl in the cache
  *
  * @return void
  */
 private static function _storeInCache($acl = NULL)
 {
     if (is_null($acl) && App_FlagFlippers_Manager::_checkIfExist()) {
         $acl = App_FlagFlippers_Manager::_getFromRegistry();
     }
     if (empty($acl)) {
         throw new Exception('You must provide a valid Acl in order to store it');
     }
     $cacheHandler = App_DI_Container::get('CacheManager')->getCache('default');
     $cacheHandler->save($acl, App_FlagFlippers_Manager::$indexKey);
 }
Пример #10
0
 /**
  * Allows the user to manage individual permissions for each
  * user group
  *
  * @access public
  * @return void
  */
 public function flippersAction()
 {
     $this->title = 'Manage permissions for this group.';
     $form = new GroupPermissionsForm();
     $fliperModel = new Flipper();
     $groupModel = new Group();
     if ($this->getRequest()->isPost()) {
         if ($form->isValid($this->getRequest()->getPost())) {
             $fliperModel->savePermissions($form->getValues());
             $this->_helper->FlashMessenger(array('msg-success' => sprintf('Permissions for group %s were successfully updated.', $group['name'])));
             App_FlagFlippers_Manager::save();
             $this->_redirect('/groups/');
         }
     } else {
         $id = $this->_getParam('id');
         if (!is_numeric($id)) {
             $this->_helper->FlashMessenger(array('msg-success' => sprintf('We cannot find group with id %s', $id)));
             $this->_redirect('/groups/');
         }
         $group = $groupModel->findById($id);
         $flipper = $fliperModel->findByGroupId($id);
         if (empty($group)) {
             $this->_helper->FlashMessenger(array('msg-success' => sprintf('The permissions for the group %s were updated.', $form->getValue('name'))));
             $this->_redirect('/groups/');
         }
         $form->populate($flipper->toArray(), $id);
         $this->view->item = $group;
     }
     $this->view->form = $form;
 }
Пример #11
0
 /**
  * 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);
 }