public function deleteAction() { $this->setNoRender(); $this->disableLayout(); $request = $this->getRequest(); if (!$request->isPost()) { return; } $moduleId = $request->getPost('module_id'); $controlerId = $request->getPost('controller_id'); $actionId = $request->getPost('action_id'); /** * Delete all action by module_id and controller_id */ Modules_Core_Services_Action::delete($moduleId, $controlerId, $actionId); $this->getResponse()->setBody('RESULT_OK'); }
public function isAllowed($actionId, $controllerId = null, $moduleId = null) { if (null == $this->_user) { return null; } $request = Gio_Core_Request::getInstance(); $moduleId = null == $moduleId ? $request->getParam('module') : $moduleId; $controllerId = null == $controllerId ? $request->getParam('controller') : $controllerId; $action = Modules_Core_Services_Action::getByMCA($moduleId, $controllerId, $actionId); if (null == $action) { return true; } if ($this->_rules) { $roleId = isset($this->_user->role_id) ? $this->_user->role_id : null; $roleName = 'role_' . $roleId; $userId = isset($this->_user->user_id) ? $this->_user->user_id : null; $userRoleName = 'user_' . $userId; $moduleController = $moduleId . ':' . $controllerId; $pattern = array('role_name' => $roleName, 'allow' => 0, 'module_controller' => $moduleController, 'action_id' => $actionId); $userPattern = array('role_name' => $userRoleName, 'allow' => 0, 'module_controller' => $moduleController, 'action_id' => $actionId); if (in_array($pattern, $this->_rules) || in_array($userPattern, $this->_rules)) { return false; } else { $pattern['allow'] = 1; $userPattern['allow'] = 1; if (in_array($pattern, $this->_rules) || in_array($userPattern, $this->_rules)) { return true; } else { $pattern['module_controller'] = null; $pattern['action_id'] = null; $userPattern['module_controller'] = null; $userPattern['action_id'] = null; if (in_array($pattern, $this->_rules) || in_array($userPattern, $this->_rules)) { return true; } } } } return false; }
/** * Perform install actions * * @param bool $importSampleData * @return bool */ public static function install($importSampleData = false, $adminInfo = array()) { try { $view = Gio_Core_View::getInstance(); $moduleDirs = Gio_Core_File::getSubDir(ROOT_DIR . DS . 'modules'); /** * Install modules */ $modules = array(); foreach ($moduleDirs as $module) { $modules[] = Modules_Core_Services_Module::install($module); } foreach ($modules as $module) { if ($module) { Modules_Core_Services_Module::add($module); } } /** * Install widgets */ foreach ($moduleDirs as $module) { /** * Load all widgets from module */ $widgetDirs = Gio_Core_File::getSubDir(ROOT_DIR . DS . 'modules' . DS . $module . DS . 'widgets'); foreach ($widgetDirs as $widgetName) { $widget = array('module_id' => $module, 'widget_id' => $widgetName, 'title' => $view->TRANSLATOR->widget('about_title', $module, $widgetName), 'description' => $view->TRANSLATOR->widget('about_description', $module, $widgetName), 'created_date' => date('Y-m-d H:i:s')); Modules_Core_Services_Widget::add($widget); } } /** * Create resources and previleges */ foreach ($moduleDirs as $module) { $file = ROOT_DIR . DS . 'modules' . DS . $module . DS . 'configs' . DS . 'permissions.xml'; if (!file_exists($file)) { continue; } $xml = simplexml_load_file($file); foreach ($xml->controller as $res) { $attr = $res->attributes(); $langKey = (string) $attr['langKey']; $description = $view->TRANSLATOR->translator($langKey, $module); $description = $description == $langKey ? (string) $attr['description'] : $description; $resource = array('controller_id' => $attr['name'], 'description' => $description, 'module_id' => $module, 'created_date' => date('Y-m-d H:i:s')); /** * Add resource */ Modules_Core_Services_Controller::add($resource); if ($res->action) { foreach ($res->action as $pri) { $attr2 = $pri->attributes(); $langKey = (string) $attr2['langKey']; $description = $view->TRANSLATOR->translator($langKey, $module); $description = $description == $langKey ? (string) $attr2['description'] : $description; $privilege = array('controller_id' => $attr['name'], 'description' => $description, 'module_id' => $module, 'action_id' => $attr2['name'], 'created_date' => date('Y-m-d H:i:s')); Modules_Core_Services_Action::add($privilege); } } } } /** * Finally, init data */ $dbFile = ROOT_DIR . DS . 'install' . DS . 'db.xml'; if (file_exists($dbFile)) { $xml = simplexml_load_file($dbFile); $xpath = $xml->xpath('module/query'); if (is_array($xpath) && count($xpath) > 0) { $conn = Gio_Db_Connection::getConnection(); foreach ($xpath as $query) { $q = str_replace('###table_prefix###', $conn->_tablePrefix, (string) $query); $conn->query($q); } } } /** * Allows user to import sample data */ if ($importSampleData) { $file = ROOT_DIR . DS . 'install' . DS . 'giocms_sample_db.sql'; $importer = Gio_Core_Import_Importer::getInstance(); if ($importer != null && $file != null) { $importer->import($file); } } /** * Create admin user */ $salt = md5(time()); $user = array('username' => $adminInfo['username'], 'password' => md5(md5($adminInfo['password']) . $salt), 'email' => $adminInfo['email'], 'fullname' => $adminInfo['fullname'], 'salt' => $salt, 'status' => 'active', 'created_date' => date('Y-m-d H:i:s'), 'role_id' => 1); Modules_Core_Services_User::add($user); } catch (Exception $ex) { return false; } return true; }
public function roleAction() { $request = $this->getRequest(); $roleId = $request->getParam('role_id'); $role = Modules_Core_Services_Role::getById($roleId); if (null == $role) { return; } $this->view->role = $role; $act = $request->getParam('act'); if ($request->isPost()) { $this->setNoRender(); $this->disableLayout(); $mod = $request->getPost('mod'); $this->view->mod = $mod; $controllers = Modules_Core_Services_Action::getDbActionsByModule($mod); switch ($act) { case 'save': /** * Reset rule for user */ Modules_Core_Services_Rule::reset('role', $role['role_id'], $mod); $actions = $request->getPost('actions'); if ($controllers) { foreach ($controllers as $index => $controller) { if ($controller['actions']) { foreach ($controller['actions'] as $indexAction => $controllerAction) { $allow = 0; if ($actions) { foreach ($actions as $action) { if ($mod . '_' . $controller['controller_id'] . '_' . $controllerAction['action_id'] == $action) { $allow = 1; } } } $rule = array('module_id' => $mod, 'controller_id' => $controller['controller_id'], 'action_id' => $controllerAction['action_id'], 'object_type' => 'role', 'object_id' => $role['role_id'], 'allow' => $allow); $ruleId = Modules_Core_Services_Rule::add($rule); } } } } $this->getResponse()->setBody('RESULT_OK'); return; break; default: $dbRoleRules = Modules_Core_Services_Rule::getRules('role', $role['role_id']); $dbRules = $dbRoleRules; $this->view->dbRules = $dbRules; $this->view->controllers = $controllers; $viewFile = ROOT_DIR . DS . 'templates' . DS . $this->view->APP_TEMPLATE . DS . 'modules' . DS . 'core' . DS . 'permission' . DS . 'role.ajax.phtml'; $response = $this->view->render($viewFile); $this->getResponse()->setBody($response); return; break; } } $modules = Modules_Core_Services_Module::getModulesInstalled(); /** * Add module core to the top array */ $modules = array_pad($modules, -count($modules) - 1, array('module_id' => 'core')); $this->view->modules = $modules; }