/**
  * Display a listing of the resource.
  *
  * @return Response
  */
 public function index()
 {
     if (Auth::user() && Auth::user()->id == Config::get('laracancan.super_admin')) {
         if (Input::get('ajax') == null) {
             $resources = Resource::all();
             return view('laracancan::permission.list')->with('resources', $resources);
         }
     }
     return response(view('laracancan::master.401'), 401);
 }
Esempio n. 2
0
 public function manageRolePermissionsAction($id)
 {
     if (Auth::user() && Auth::user()->id == Config::get('laracancan.super_admin')) {
         $role = Role::find($id);
         $role->resourcePermissions()->detach();
         foreach (Resource::all() as $resource) {
             $permissions = Input::get($resource->id . "_resourcepermissions");
             if ($permissions != null) {
                 foreach ($permissions as $permission) {
                     $resourcePermission = Resourcepermission::where('permission_id', $permission)->where('resource_id', $resource->id)->first();
                     $role->resourcePermissions()->detach([$resourcePermission->id]);
                     $role->resourcePermissions()->attach([$resourcePermission->id]);
                     foreach ($resourcePermission->childResourcePermissions as $child) {
                         $role->resourcePermissions()->attach([$child->id => ['parent_id' => $resourcePermission->id]]);
                     }
                 }
             }
         }
         return redirect()->back()->with('flash_success', 'Permissions saved successfully!');
     }
     return response(view('laracancan::master.401'), 401);
 }
 public function postManageChildren($id)
 {
     if (Auth::user() && Auth::user()->id == Config::get('laracancan.super_admin')) {
         $children = Input::get('children', array());
         $resource = Resource::find($id);
         $resource->childResources()->detach();
         foreach ($resource->parentResources as $parent) {
             $parent->pivot->pivot = NULL;
             $parent->pivot->save();
         }
         foreach ($children as $child) {
             $pivot = Input::get($child . '_pivot');
             $resource->childResources()->attach([$child => ['pivot' => $pivot]]);
             $potentialMutualResource = Resource::find($child);
             if ($potentialMutualResource->isParentOf($id)) {
                 $potentialMutualResource->childResources()->detach($id);
                 $potentialMutualResource->childResources()->attach([$id => ['pivot' => $pivot]]);
             }
         }
         return redirect()->back()->with('flash_success', 'Records Updated Successfully');
     }
     return response(view('laracancan::master.401'), 401);
 }
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy($id)
 {
     if (Auth::user() && Auth::user()->id == Config::get('laracancan.super_admin')) {
         $resource = Resource::find(Input::get('resource_id'));
         $resource->resourcePermissions()->detach([$id]);
         return redirect()->back()->with('flash_success', 'Permission successfully removed from this resource.');
     }
     return response(view('laracancan::master.401'), 401);
 }
 /**
  * Function for resources of user based on a specific permission
  * @param $permission
  * @return array
  */
 function resourcesByPermission($permission)
 {
     if ($this->id == Config::get('laracancan.super_admin', 0)) {
         return Resource::all();
     }
     $roles = $this->roles;
     $resourses = array();
     foreach ($roles as $role) {
         $roleResources = $role->resourcesByPermission($permission);
         $resourses = array_merge($resourses, $roleResources ? $roleResources : array());
     }
     $resourses = array_unique($resourses);
     return $resourses;
 }