Example #1
0
 /**
  * @param int $id
  * @return ResourceInterface
  * @throws Illuminate\Database\Eloquent\ModelNotFoundException
  */
 public function getResource()
 {
     $resource = null;
     try {
         $id_or_name = $this->argument('resource');
         if (is_numeric($id_or_name)) {
             $resource = $this->repository->findOrFail($id_or_name);
             $this->info("Resource {$id_or_name} -> {$resource->getName()} found.");
         } else {
             $resource = $this->repository->byName($id_or_name);
             $this->info("Resource {$resource->getId()} -> {$id_or_name} found.");
         }
     } catch (\Illuminate\Database\Eloquent\ModelNotFoundException $e) {
         $this->info("Failed to find resource with id {$id_or_name}");
         throw $e;
     }
     return $resource;
 }
Example #2
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy(ResourceInterface $resource)
 {
     $response = null;
     if (Auth::user()->can('delete', $resource)) {
         if ($this->repository->delete($resource)) {
             $response = Redirect::route('roles.resource.index')->with('message', trans('roles::privileg.delete success', ['name' => $resource->getName()]));
         } else {
             $errors = new MessageBag();
             $errors->add('error', trans('roles::resource.delete failed'));
             $response = Redirect::back()->withErrors($errors);
         }
     } else {
         $errors = new MessageBag();
         $errors->add('error', trans('roles::resource.delete permission denied'));
         $response = Redirect::back()->withErrors($errors);
     }
     return $response;
 }
Example #3
0
 /**
  * Show the form for editing the specified role.
  *
  * @param  int  $id
  * @return Response
  */
 public function edit(RoleInterface $role)
 {
     $user = $this->getUser();
     if ($user->can('edit', $role)) {
         $variables = [];
         $variables['extends'] = Config::get('roles::extends');
         $variables['role'] = $role;
         $variables['privileges'] = $this->privilege_repository->all();
         $variables['users'] = $this->user_repository->all();
         /*
          * categorize permissions by their container name to fold them up into an accordion
          */
         $variables['permission_categories'] = [];
         foreach ($role->getPermissions() as $permission) {
             // Set up info for the view if this accordion is open upon loading or not
             if (Session::get('permission_container_open') == $permission->getContainer()) {
                 $variables['permission_container'][$permission->getContainer()] = 'in';
             } else {
                 $variables['permission_container'][$permission->getContainer()] = '';
             }
             if (!isset($variables['permission_categories'][$permission->getContainer()])) {
                 $variables['permission_categories'][$permission->getContainer()] = [];
             }
             $variables['permission_categories'][$permission->getContainer()][] = $permission;
         }
         /**
          * Set up which privilege accordions are open and which are closed upon loading
          */
         foreach ($variables['privileges'] as $privilege) {
             if (Session::get('permission_add_container_open') == $privilege->getName()) {
                 $variables['permission_add_container'][$privilege->getName()] = 'in';
             } else {
                 $variables['permission_add_container'][$privilege->getName()] = '';
             }
         }
         $variables['privilege_open'] = Session::has('privilege_open') ? 'in' : '';
         $variables['users_open'] = Session::has('users_open') ? 'in' : '';
         $variables['edit_open'] = !$variables['users_open'] && !$variables['privilege_open'] ? 'in' : '';
         $response = View::make('roles::role/edit', $variables);
     } else {
         $response = Redirect::home();
     }
     return $response;
 }