/** @test */ public function it_deletes_an_role() { $this->prepare(); $response = $this->actingAs($this->superAdminUser)->visit('genealabs/laravel-governor/roles/create')->type('TestRole', 'name')->type('This is a description for test users role.', 'description')->press('Add Role')->see('TestRole'); $response = $this->actingAs($this->superAdminUser)->delete('genealabs/laravel-governor/roles/TestRole', ['_token' => csrf_token()]); $this->assertCount(0, Role::where('name', 'TestRole')->get()); }
/** * @return mixed */ public function index() { $assignment = new Assignment(); $this->authorize('view', $assignment); $displayNameField = $this->displayNameField; $users = $this->user->all(); $roles = Role::with('users')->get(); return view('genealabs-laravel-governor::assignments.index', compact('users', 'roles', 'displayNameField', 'userList', 'assignment')); }
public function run() { $user = App::make(Config::get('auth.model')); $superuser = $user->find($user->min($user['primaryKey'])); $role = new Role(); $role->name = 'SuperAdmin'; $role->description = 'This role is for the main administrator of your site. They will be able to do absolutely everything. (This role cannot be edited.)'; $role->save(); $role = Role::find('SuperAdmin'); $role->users()->attach($superuser); Role::create(['name' => 'Member', 'description' => 'Represents the baseline registered user. Customize permissions as best suits your site.']); }
public function run() { $superadmin = Role::whereName('SuperAdmin')->get()->first(); $actions = Action::all(); $ownership = Ownership::whereName('any')->get()->first(); $entities = Entity::all(); foreach ($entities as $entity) { foreach ($actions as $action) { $permission = new Permission(); $permission->role()->associate($superadmin); $permission->action()->associate($action); $permission->ownership()->associate($ownership); $permission->entity()->associate($entity); $permission->save(); } } }
public function prepare() { Session::start(); $this->artisan('migrate', ['--path' => 'packages/genealabs/laravel-governor/database/migrations']); $this->artisan('migrate', ['--path' => 'database/secondaryMigrations']); $this->superAdminUser = factory(LaravelGovernorTests\User::class)->create(); $this->artisan('db:seed', ['--class' => 'LaravelGovernorDatabaseSeeder']); $this->unauthorizedUser = factory(LaravelGovernorTests\User::class)->create(); $this->superAdminUser->fill(['name' => 'Test User', 'first_name' => 'Test', 'last_name' => 'User', 'email' => '*****@*****.**', 'password' => 'test123$']); $this->superAdminUser->save(); $this->rolePolicy = new RolePolicy(); $this->entityPolicy = new EntityPolicy(); $this->assignmentPolicy = new AssignmentPolicy(); $this->superAdminRole = Role::find('SuperAdmin'); $this->memberRole = Role::find('Member'); $this->role = new Role(); $this->entity = new Entity(); $this->assignment = new Assignment(); $this->memberUser = User::limit(2)->get()->last(); }
/** * @return bool */ public function getIsSuperAdminAttribute() { $superAdminRole = Role::where('name', 'SuperAdmin')->first(); $this->load('roles'); return $this->roles->contains($superAdminRole->name); }
/** * @param $name * @return mixed */ public function destroy($name) { $role = Role::find($name); $this->authorize('remove', $role); $role->delete(); return redirect()->route('genealabs.laravel-governor.roles.index'); }
public function getAllUsersOfRole($role) { $role = Role::with('users')->find($role); return $role->users; }