Beispiel #1
0
 private function getMenus($user)
 {
     $menus = Permission::with('menus')->where('parent_id', 0)->orderBy('sort')->get();
     if (isset($user)) {
         $business_id = 0;
         if (config('quickcms.business_user_model_class')) {
             $reflectionClass = new \ReflectionClass(config('quickcms.business_user_model_class'));
             $business_user = $reflectionClass->newInstance();
             $business_user = $business_user::where('admin_id', Auth::admin()->get()->id)->first();
             $business_id = count($business_user) ? $business_user->business_id : 0;
         }
         Session::put('business_id', $business_id);
         foreach ($menus as $key => $menu) {
             $items = Permission::where('parent_id', $menu->id)->orderBy('sort')->where('type', 0)->get();
             if (!is_null($items) && count($items) > 0) {
                 foreach ($items as $item_key => $item) {
                     if (!$user->can($item->name)) {
                         unset($menus[$key]['menus'][$item_key]);
                     }
                 }
             }
             if (!$user->can($menu->name)) {
                 unset($menus[$key]);
             }
         }
     }
     Session::put('menu', json_decode($menus, true));
 }
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     $parent_permissions = Permission::where('type', 0)->where('route', '!=', '#')->where('route', '!=', '/admin/index')->get();
     $operation = array('create' => '新增', 'edit' => '编辑', 'delete' => '删除', 'detail' => '详情');
     $permission = [];
     foreach ($parent_permissions as $parent_key => $parent_value) {
         foreach ($operation as $operate_key => $operate_value) {
             $permission[] = array('name' => str_replace('.index', '', $parent_value->name) . '.' . $operate_key, 'display_name' => $operate_value, 'route' => $parent_value->route . '/' . $operate_key, 'type' => 1, 'parent_id' => $parent_value->id);
         }
     }
     DB::table('permissions')->insert($permission);
 }
Beispiel #3
0
 public function getIndex()
 {
     $user = Auth::admin()->get();
     $permissions = Permission::whereNotNull('route')->where('route', '!=', '')->orderBy('level')->where('route', '!=', '#')->orderBy('sort');
     $permission_routes = $permissions->lists('route', 'name');
     if (count($permission_routes) > 0) {
         foreach ($permission_routes as $name => $route) {
             if ($user->can($name)) {
                 return redirect($route);
             }
         }
     }
     return redirect('/admin/index');
 }
Beispiel #4
0
 public function __construct()
 {
     //$route_url = '/' . Route::getCurrentRoute()->getPath();
     /*if(!Session::has($route_url)){
           $permission = Permission::with('parent')->select('id','route', 'name','display_name','parent_id')
               ->where('route', $route_url)
               ->first();
           Session::push($route_url, $permission);
       }*/
     if (!Session::has('permissions')) {
         $roles = Auth::admin()->get()->roles()->first();
         $permission_ids = PermissionRole::where('role_id', $roles->pivot->role_id)->lists('permission_id');
         $permissions = Permission::where('type', 1)->whereIn('id', $permission_ids)->get();
         Session::put('permissions', $permissions);
     }
     $this->systemConfig = Cache::rememberForever('system_config', function () {
         return System::get();
     });
 }
Beispiel #5
0
 public static function filterOperationPermission($request, $permission, $route_name)
 {
     $method = $request->method();
     $path = Route::getCurrentRoute()->getPath();
     $path = str_replace("/", ".", $path);
     $route = Route::currentRouteName();
     $user = Auth::admin()->get();
     if (config('quickcms.permission_switch')) {
         if ($route != 'admin.' . $route_name . '.search' && $route != 'admin.' . $route_name . '.store' && !$user->can($route)) {
             App::abort('403');
         }
     } else {
         $permissions = Permission::where('name', $route)->first();
         if (isset($permissions) && $permissions->type == 0) {
             if (!$user->can($route)) {
                 App::abort('403');
             }
         }
     }
 }
 public function destroy($id)
 {
     $permission = Permission::find($id);
     $menu = Permission::where('parent_id', $id)->first();
     if (is_null($menu)) {
         $result = true;
         $content = '删除权限成功';
         $permission->delete();
     } else {
         $result = false;
         $content = '删除权限失败,不能删除已经被关联的一级权限';
     }
     $res = array('result' => $result, 'content' => $content);
     return $res;
 }
 public function destroy($id, $permission_id)
 {
     $permission = Permission::find($permission_id);
     $result = true;
     $content = '删除权限成功';
     $permission->delete();
     $res = array('result' => $result, 'content' => $content);
     return $res;
 }
Beispiel #8
0
 public function permissions($id)
 {
     $role = Role::find($id);
     $perents = Permission::with('menus')->where('parent_id', 0)->get();
     $permission_ids = PermissionRole::where('role_id', $role->id)->lists('permission_id')->all();
     return view('backend::roles.permission', compact('perents', 'role', 'permission_ids'));
 }