Example #1
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function fire()
 {
     $id = $this->argument('user id');
     $resource = $this->getResourceByParameter();
     $action = $this->getAction($resource);
     $role = $this->getRole($action);
     $user = $this->userRepository->byId($id);
     $user->assignRole($role);
 }
Example #2
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;
 }