/** * @param $id */ public function postGroup($id, Request $request) { AdminAccess::where('cp_group_id', '=', $id)->delete(); if ($request->has('access_allow')) { foreach ($request->input('access_allow') as $access) { $adminAccess = new AdminAccess(); $adminAccess->cp_group_id = $id; $adminAccess->access = $access; $adminAccess->save(); } } return redirect($this->redirectPath('/perm/group/' . $id))->with($this->statusVar, Lang::get('access.updateGroupPermSuccess')); }
/** * 检查访问权限 * * @return boolean */ public function allow() { // 检查是否是系统管理员 if (AdminAccess::checkIsSystemAdmin($this->_user)) { return true; } //检测所在的管理组 if (!$this->_user->cp_group_id) { return false; } $this->_user->custom_access = !empty($this->_user->custom_access) ? unserialize($this->_user->custom_access) : array(); if (intval($this->_user->cp_group_id) > 0) { //获取组权限列表 $accessList = $this->getAdminAccessesToArray(); //权限菜单 $menuList = $this->_menus; //管理框架无需权限 $this->_allowAccess['App\\Http\\Controllers\\AdminController@getIndex'] = true; foreach ($menuList as $topMenu) { foreach ($topMenu['treeViewMenu'] as $menu) { $adminAccess = AdminAccess::where('cp_group_id', '=', $this->_user->cp_group_id)->where('access', '=', $menu['actionName'])->first(); if ($adminAccess && !in_array($adminAccess->access, $this->_user->custom_access) && $menu['auth']) { $menu['auth'] = is_array($menu['auth']) ? $menu['auth'] : (array) $menu['auth']; foreach ($menu['auth'] as $auth) { $accessList[] = array('cp_group_id' => $adminAccess->cp_group_id, 'access' => $auth); } } } } //保存访问权限 foreach ($accessList as $access) { if (empty($this->_user->custom_access)) { $this->_allowAccess[$access['access']] = true; } elseif (!in_array($access['access'], $this->_user->custom_access)) { $this->_allowAccess[$access['access']] = true; } } //是否允许POST if (!empty($_POST) && !array_key_exists('_allowpost', $this->_allowAccess)) { return false; } $actionName = $this->getRouter()->currentRouteAction(); if (isset($this->_allowAccess[$actionName])) { return $this->_allowAccess[$actionName]; } return false; } return true; }