public function testEnabled() { $this->initDB(); $exitCode = Artisan::call('role:edit', ['id' => $this->role->id, '--name' => 'some bogus value']); $this->assertEquals($exitCode, 0); $this->assertContains('The role has been updated', Artisan::output()); $this->assertEquals(Role::find($this->role->id)->name, 'some bogus value'); }
public function testCreate() { /** @var Role $dummy */ $dummy = factory(Role::class)->make(); $exitCode = Artisan::call('role:create', ['name' => $dummy->name, 'description' => $dummy->description]); $this->assertEquals(0, $exitCode); $this->assertContains('created', Artisan::output()); Role::where(['name' => $dummy->name, 'description' => $dummy->description])->forceDelete(); }
/** * {@inheritdoc}. */ protected function getObjectByArguments() { $role = false; if (!is_object($role)) { $role = Role::where('name', $this->argument('role'))->first(); } if (!is_object($role)) { $role = Role::find($this->argument('role')); } return $role; }
/** * Execute the console command. * * @return bool */ public function handle() { if (empty($this->option('role')) || empty($this->option('permission'))) { $this->error('Missing options for role and/or permission to select, try --help'); return false; } /* * Detect the role->id and lookup the user if its thru a user assignment. */ $role = false; if (!is_object($role)) { $role = Role::where('name', $this->option('role'))->first(); } if (!is_object($role)) { $role = Role::find($this->option('role')); } if (!is_object($role)) { $this->error('Unable to find role with this criteria'); return false; } /* * Detect the permission->id and lookup the name if needed */ $permission = false; if (!is_object($permission)) { $permission = Permission::where('name', $this->option('permission'))->first(); } if (!is_object($permission)) { $permission = Permission::find($this->option('permission')); } if (!is_object($permission)) { $this->error('Unable to find permission with this criteria'); return false; } $permissionRole = new PermissionRole(); $permissionRole->permission_id = $permission->id; $permissionRole->role_id = $role->id; $validation = Validator::make($permissionRole->toArray(), PermissionRole::createRules($permissionRole)); if ($validation->fails()) { $this->warn('The role has already been granted this permission'); $this->error('Failed to create the permission due to validation warnings'); return false; } if (!$permissionRole->save()) { $this->error('Failed to save the permission into the database'); return false; } $this->info("The permission {$permission->name} has been granted to role {$role->name}"); return true; }
/** * Execute the console command. * * @return boolean */ public function handle() { if (empty($this->option('name')) || empty($this->option('description'))) { $this->error('Missing options for name and/or descrption'); return false; } $role = new Role(); $role->name = empty($this->option('name')) ? false : $this->option('name'); $role->description = empty($this->option('description')) ? false : $this->option('description'); $validation = Validator::make($role->toArray(), Role::createRules($role)); if ($validation->fails()) { foreach ($validation->messages()->all() as $message) { $this->warn($message); } $this->error('Failed to create the role due to validation warnings'); return false; } if (!$role->save()) { $this->error('Failed to save the role into the database'); return false; } $this->info("The role {$this->option('name')} has been created"); return true; }
/** * Execute the console command. * * @return boolean */ public function handle() { if (empty($this->option('role')) && empty($this->option('user'))) { $this->error('Missing options for role and/or user(e-mail) to select'); return false; } /* * Detect the role->id and lookup the user if its thru a user assignment. */ $role = false; $user = false; if (!empty($this->option('role'))) { if (!is_object($role)) { $role = Role::where('name', $this->option('role'))->first(); } if (!is_object($role)) { $role = Role::find($this->option('role')); } } if (!empty($this->option('user'))) { if (!is_object($user)) { $user = User::where('email', $this->option('user'))->first(); } if (!is_object($user)) { $user = Role::find($this->option('user')); } } if (!is_object($role) || !is_object($user)) { $this->error('Unable to find role with this criteria'); return false; } $RoleUser = new RoleUser(); $RoleUser->user_id = $user->id; $RoleUser->role_id = $role->id; $validation = Validator::make($RoleUser->toArray(), RoleUser::createRules($RoleUser)); if ($validation->fails()) { $this->warn('The role has already been granted this permission'); $this->error('Failed to create the permission due to validation warnings'); return false; } if (!$RoleUser->save()) { $this->error('Failed to save the permission into the database'); return false; } $this->info("The role {$role->name} has been granted to user {$user->email}"); return true; }
/** * Execute the console command. * * @return boolean */ public function handle() { if (empty($this->option('role')) && empty($this->option('user'))) { $this->error('Missing options for role and/or user(e-mail) to select'); return false; } /* * Detect the role->id and lookup the user if its thru a user assignment. */ $role = false; $user = false; if (!empty($this->option('role'))) { if (!is_object($role)) { $role = Role::where('name', $this->option('role'))->first(); } if (!is_object($role)) { $role = Role::find($this->option('role')); } } if (!empty($this->option('user'))) { if (!is_object($user)) { $user = User::where('email', $this->option('user'))->first(); } if (!is_object($user)) { $user = Role::find($this->option('user')); } } if (!is_object($role) || !is_object($user)) { $this->error('Unable to find role with this criteria'); return false; } $roleUser = RoleUser::all()->where('role_id', $role->id)->where('user_id', $user->id)->first(); if (!is_object($roleUser)) { $this->error('Nothing to delete, this {$permission->name} permission is not linked to the role {$role->name}'); return false; } if (!$roleUser->delete()) { $this->error('Failed to remove the permission into the database'); return false; } $this->info("The role {$role->name} has been revoked from role {$user->email}"); return true; }
/** * Execute the console command. * * @return boolean */ public function handle() { if (empty($this->option('role'))) { $this->warn('the required role argument was not passed, try --help'); return false; } $role = false; if (!is_object($role)) { $role = Role::where('name', $this->option('role'))->first(); } if (!is_object($role)) { $role = Role::find($this->option('role')); } if (!is_object($role)) { $this->error('Unable to find role with this criteria'); return false; } // Apply changes to the role object if (!empty($this->option('name'))) { $role->name = $this->option('name'); } if (!empty($this->option('description'))) { $role->description = $this->option('description'); } $validation = Validator::make($role->toArray(), Role::updateRules($role)); if ($validation->fails()) { foreach ($validation->messages()->all() as $message) { $this->warn($message); } $this->error('Failed to create the role due to validation warnings'); return false; } // Save the object $role->save(); $this->info("Role has been successfully updated"); return true; }
/** * Execute the console command. * * @return boolean */ public function handle() { if (empty($this->option('role'))) { $this->warn('no email or id argument was passed, try --help'); return false; } $role = false; if (!is_object($role)) { $role = Role::where('name', $this->option('role'))->first(); } if (!is_object($role)) { $role = Role::find($this->option('role')); } if (!is_object($role)) { $this->error('Unable to find role with this criteria'); return false; } $permissions = ''; foreach ($role->permissions as $permission) { $permissions .= $permission->name . PHP_EOL; } $table = []; $counter = 0; foreach (array_combine($this->headers, $this->fields) as $header => $field) { $counter++; if ($header == 'Permissions') { $table[$counter][] = $header; $table[$counter][] = chop($permissions); } else { $table[$counter][] = $header; $table[$counter][] = (string) $role->{$field}; } } $this->table(['Role Setting', 'Role Value'], $table); return true; }
/** * {@inheritdoc}. */ protected function findAll() { $roles = Role::all($this->fields); return $this->hydrateRolesWithPermissionCount($roles); }
/** * {@inherit docs}. */ protected function getCollectionWithArguments() { return Role::where('id', $this->argument('role'))->orWhere('name', $this->argument('role')); }
/** * {@inheritdoc}. */ protected function getValidator($model) { return Validator::make($model->toArray(), Role::createRules()); }
/** * {@inheritdoc}. */ protected function getValidator($model) { $data = $this->getModelAsArrayForDirtyAttributes($model); $updateRules = $this->getUpdateRulesForDirtyAttributes(Role::updateRules($model)); return Validator::make($data, $updateRules); }
/** * Show the form for editing the specified resource. * * @param User $user * * @return \Illuminate\Http\Response */ public function edit(User $user) { $accounts = Account::lists('name', 'id'); $roles = Role::lists('name', 'id'); $locales = []; foreach (Config::get('app.locales') as $locale => $locale_data) { $locales[$locale] = $locale_data[0]; } return view('users.edit')->with('user', $user)->with('account_selection', $accounts)->with('selected', $user->account_id)->with('locale_selection', $locales)->with('locale_selected', null)->with('disabled_checked', $user->disabled)->with('roles', $roles)->with('selected_roles', $user->roles->lists('id')->toArray())->with('auth_user', $this->auth_user); }