Ejemplo n.º 1
0
 public function ajaxSubmitAction()
 {
     $id = Request::getPOST('permission-id');
     $description = trim(Request::getPOST('description'));
     if (empty($id) || empty($description)) {
         $this->renderAjax(1, '参数不能为空!');
     }
     RootPermissionInterface::save(array('id' => $id, 'description' => $description));
     $this->setNotice(FrameworkVars::NOTICE_SUCCESS, '修改成功!');
     $this->renderAjax(0);
 }
Ejemplo n.º 2
0
 public function ajaxDeleteAction()
 {
     $ids = Request::getPOST('ids');
     // 过滤
     $ids = json_decode($ids, true);
     foreach ($ids as $i => $id) {
         if (!is_numeric($id) || $id <= 0) {
             unset($ids[$i]);
             continue;
         }
     }
     // 校验
     if (empty($ids)) {
         $this->renderAjax(1, '参数错误!');
     }
     RootPermissionInterface::deleteMultiByIds(array('ids' => $ids));
     $this->setNotice(FrameworkVars::NOTICE_SUCCESS, '删除成功!');
     $this->renderAjax(0);
 }
Ejemplo n.º 3
0
 public function defaultAction()
 {
     $pageSize = 20;
     // 获取参数
     $page = Pager::get();
     $keyword = Request::getGET('keyword');
     // 构建where
     $where = array();
     if (!empty($keyword)) {
         $where[] = array('OR' => array(array('code', 'LIKE', "%{$keyword}%"), array('description', 'LIKE', "%{$keyword}%")));
     }
     // 查询
     $offset = ($page - 1) * $pageSize;
     $permissionList = RootPermissionInterface::getList(array('where' => $where, 'limit' => $pageSize, 'offset' => $offset));
     $allCount = RootPermissionInterface::getCount($where);
     // 缓存部分的html
     $html = array();
     $html['pager'] = $this->view->fetch(array('renderAllCount' => $allCount, 'renderPageSize' => $pageSize, 'renderRadius' => 8), 'widget/pager.php');
     $this->renderFramework(array('html' => $html, 'permissionList' => $permissionList), 'permission/list.php');
 }
Ejemplo n.º 4
0
 public function ajaxSubmitAction()
 {
     $code = trim(Request::getPOST('code'));
     $description = trim(Request::getPOST('description'));
     // 校验
     if (empty($code) || empty($description)) {
         $this->renderAjax(1, '参数不能为空!');
     }
     $ret = RootPermissionInterface::isValidCode(array('code' => $code));
     if (false === $ret) {
         $this->renderAjax(1, '权限码不合法!');
     }
     $ret = RootPermissionInterface::testMakeCode(array('code' => $code));
     if (false === $ret) {
         $this->renderAjax(1, '权限已经存在,无法创建权限!');
     }
     // 保存
     RootPermissionInterface::save(array('description' => $description, 'code' => $code));
     $this->setNotice(FrameworkVars::NOTICE_SUCCESS, '添加成功!');
     $this->renderAjax(0);
 }
 /**
  * 权限控制
  *
  * @param   $params array(
  *              'user_id',  // 用户id
  *              'path',     // 权限路径
  *          )
  * @return  bool
  * @throws  LibraryException
  */
 public static function allowed($params)
 {
     $userId = self::get('user_id', $params, 0, TYPE_INT_GT0, true);
     $path = self::get('path', $params, '', TYPE_STR_Y, true);
     if (empty($path)) {
         Logger::warn('interface', '权限校验时,传入了空权限,系统默认返回true!');
         return true;
     }
     // 校验权限是否存在
     $existed = RootPermissionInterface::findPath(array('path' => $path, 'from_cache' => true));
     if (!$existed) {
         Logger::warn('interface', "权限{$path}不存在!");
         return false;
     }
     $managerId = RootManagerInterface::getEnabledId(array('user_id' => $userId, 'from_cache' => true));
     if (empty($managerId)) {
         return false;
     }
     $allowed = RootManagerInterface::checkPermission(array('id' => $managerId, 'path' => $path, 'from_cache' => true));
     return empty($allowed) ? false : true;
 }
Ejemplo n.º 6
0
 public function ajaxRemoveAction()
 {
     $managerId = Request::getPOST('manager-id', 0);
     $path = Request::getPOST('path', '');
     if (empty($managerId) || empty($path)) {
         $this->renderAjax(1, '参数错误!');
     }
     if (!RootPermissionInterface::isValidPath(array('path' => $path))) {
         $this->renderAjax(1, '路径不合法!');
     }
     // 路径不存在
     $where = array(array('manager_id', '=', $managerId), array('path', '=', $path));
     $rowInfo = RootRelationInterface::getRow(array('where' => $where));
     if (empty($rowInfo)) {
         $this->renderAjax(1, '管理员权限路径不存在!');
     }
     // 删除
     RootRelationInterface::deleteById(array('id' => $rowInfo['id']));
     $this->setNotice(FrameworkVars::NOTICE_SUCCESS, '移除权限成功!');
     $this->renderAjax(0);
 }
Ejemplo n.º 7
0
 public static function checkPermission($id, $path, $fromCache = false)
 {
     if (!RootPermissionInterface::isValidPath(array('path' => $path))) {
         throw new InterfaceException('路径格式不合法!');
     }
     // 对path处理
     $path = rtrim($path, '/') . '/';
     $pathList = self::getPaths($id, $fromCache);
     foreach ($pathList as $val) {
         // 对var处理
         $val = rtrim($val, '/') . '/';
         if (0 === strpos($path, $val)) {
             return true;
         }
     }
     return false;
 }
Ejemplo n.º 8
0
 public static function getInvalidPathList()
 {
     $where = array('group_by' => 'path');
     $order = array('path' => 'ASC');
     $relationList = self::getList('path AS name, count(1) AS count', $where, $order);
     foreach ($relationList as $i => $info) {
         if (RootPermissionInterface::findPath(array('path' => $info['name']))) {
             unset($relationList[$i]);
         }
     }
     return $relationList;
 }
Ejemplo n.º 9
0
 public function ajaxGetJstreeJsonAction()
 {
     echo RootPermissionInterface::getPermissionTreeJson(array('from_cache' => true));
 }
Ejemplo n.º 10
0
 public function defaultAction()
 {
     $pageSize = 20;
     $page = Pager::get();
     $loginName = Request::getGET('login-name', '');
     $path = Request::getGET('path', '');
     $includePath = Request::getGET('include-path', '');
     // 路径非法提示
     if (!empty($path)) {
         if (!RootPermissionInterface::isValidPath(array('path' => $path))) {
             $this->setNotice(FrameworkVars::NOTICE_ERROR, "路径{$path}格式不正确!");
             $url = Url::getCurrentUrl(array('path' => null));
             Url::redirect($url);
         }
     }
     // 路径非法提示
     if (!empty($includePath)) {
         if (!RootPermissionInterface::isValidPath(array('path' => $includePath))) {
             $this->setNotice(FrameworkVars::NOTICE_ERROR, "路径{$includePath}格式不正确!");
             $url = Url::getCurrentUrl(array('include-path' => null));
             Url::redirect($url);
         }
     }
     // 用户不存在提示
     if (!empty($loginName)) {
         $userInfo = UserCommonInterface::getByLoginName(array('login_name' => $loginName));
         if (empty($userInfo)) {
             $this->setNotice(FrameworkVars::NOTICE_ERROR, '用户不存在!');
             $url = Url::getCurrentUrl(array('login-name' => null));
             Url::redirect($url);
         }
     }
     // 构建where
     $where = array();
     if (!empty($userInfo)) {
         $where[] = array('user_id', '=', $userInfo['id']);
     }
     if (!empty($path)) {
         $managerIds = RootManagerInterface::getAllowedManagerIds(array('path' => $path));
         $where[] = array('id', 'IN', $managerIds);
     }
     if (!empty($includePath)) {
         $managerIds = RootManagerInterface::getIncludeManagerIds(array('path' => $includePath));
         $where[] = array('id', 'IN', $managerIds);
     }
     $offset = ($page - 1) * $pageSize;
     $managerList = RootManagerInterface::getList(array('where' => $where, 'limit' => $pageSize, 'offset' => $offset));
     $allCount = RootManagerInterface::getCount($where);
     $userList = array();
     $pathHash = array();
     if (!empty($managerList)) {
         $userIds = array_column($managerList, 'user_id');
         $userList = UserCommonInterface::getById(array('id' => $userIds));
         $userList = Arr::listToHash('id', $userList);
         // 获取权限列表
         $managerIds = array_column($managerList, 'id');
         $pathHash = RootManagerInterface::getPaths(array('id' => $managerIds));
     }
     // 找出invalid path
     $invalidHash = array();
     foreach ($pathHash as $id => $pathSet) {
         foreach ($pathSet as $tmpPath) {
             if (array_key_exists($tmpPath, $invalidHash)) {
                 continue;
             }
             $invalidHash[$tmpPath] = RootPermissionInterface::findPath(array('path' => $tmpPath)) ? 0 : 1;
         }
     }
     // 缓存部分的html
     $html = array();
     $html['pager'] = $this->view->fetch(array('renderAllCount' => $allCount, 'renderPageSize' => $pageSize, 'renderRadius' => 8), 'widget/pager.php');
     $this->renderFramework(array('html' => $html, 'managerList' => $managerList, 'userList' => $userList, 'pathHash' => $pathHash, 'invalidHash' => $invalidHash), 'manager/list.php');
 }