Example #1
0
File: Acl.php Project: aginev/acl
 /**
  * Handle an incoming request.
  *
  * @param  Request $request
  * @param  \Closure $next
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     $resource = $request->route()->getActionName();
     $permission = Permission::where('resource', '=', $resource)->first();
     // If the specific route requires permissions
     if ($permission) {
         // Get user permissions
         try {
             $user_permissions = Auth::user()->role->permissions->keyBy('resource');
         } catch (\Exception $e) {
             return abort(401, trans('acl::general.messages.user_permissions_not_found'));
         }
         // And the user has permissions
         if (!$user_permissions->has($resource)) {
             return abort(401, trans('acl::general.messages.no_permissions'));
         }
     }
     return $next($request);
 }
Example #2
0
 /**
  * Execute the command.
  *
  * @return void
  */
 public function handle()
 {
     // New permissions
     $permissions = new Collection();
     // Remove not existing permissions
     Permission::whereNotIn('resource', $this->routes->keys()->toArray())->delete();
     foreach ($this->routes as $route) {
         // Do we have the current permission in the database. If so skip it...
         $existing_permission = Permission::where('resource', '=', $route['resource'])->first();
         if ($existing_permission) {
             continue;
         }
         // Skip some methods
         $data = $this->getPermissionData($route);
         if ($data['method'] == 'missingMethod') {
             continue;
         }
         // Add new permission
         $permissions->push(Permission::create($data));
     }
     $this->assignPermissions($permissions);
 }
Example #3
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int $id
  *
  * @return Response
  */
 public function destroy($id)
 {
     $permission = Permission::findOrFail($id);
     $permission->delete();
     return redirect()->action('\\Aginev\\Acl\\Http\\Controllers\\PermissionController@index')->with('success', trans('acl::permission.destroy.deleted'));
 }
Example #4
0
 /**
  * Show the form for editing the specified resource.
  *
  * @param  int $id
  *
  * @return Response
  */
 public function edit($id)
 {
     $role = Role::findOrFail($id);
     return view('acl::role.edit', ['role' => $role, 'role_permissions' => $role->permissions->keyBy('id'), 'permissions' => Permission::all()->groupBy('controller')]);
 }