public function it_has_permission_in_db_after_registration(FunctionalTester $I)
 {
     $I->amOnRoute(RegisterPage::$ROUTE);
     $userData = $this->userActor->fillRegisterPageFields($I);
     $I->submitForm(RegisterPage::$formId, [], 'Register');
     $user = $I->grabRecord('users', ['username' => $userData['username']]);
     $permission = Permission::where('name', '=', array_shift(Permission::$defaultPermissions))->first();
     $I->seeRecord(UserPermission::$tableName, ['user_id' => $user->id, 'permission_id' => $permission->id]);
 }
 public function run()
 {
     \DB::table('permissions')->truncate();
     $generalPermissions = [['name' => 'editUserProfiles'], ['name' => 'browseWebsite']];
     $dashboardPermissions = [['name' => 'accessDashboard'], ['name' => 'viewUsers'], ['name' => 'updateUsersAccess'], ['name' => 'deleteUsers']];
     $permissions = array_merge($generalPermissions, $dashboardPermissions);
     foreach ($permissions as $permission) {
         \App\Clusters\AuthCluster\Models\AccessControl\Permission::create($permission);
     }
 }
 public function detachPermission($permission)
 {
     $cacheKey = $this->getPermissionsCacheKey();
     $permission = Permission::where('name', '=', $permission)->firstOrFail();
     $record = $this->permissionsRelation()->where('permission_id', '=', $permission->id)->where('user_id', '=', $this->id)->first();
     if ($record) {
         $record->delete();
         Cache::forget($cacheKey);
     }
 }
 protected function seedDataGetter($seedName)
 {
     $seedName = strtolower($seedName);
     $role = Role::where('name', '=', $seedName)->firstOrFail();
     $permissions = [];
     $data = [];
     foreach ($this->seedFilesIterator(DIRECTORY_SEPARATOR . $seedName) as $line) {
         $extraData = ['role_id' => $role->id];
         $permissions[] = $this->seedDataComposer($line, $extraData);
     }
     foreach ($permissions as $permission) {
         $permissionId = Permission::where('name', '=', $permission['name'])->firstOrFail()->id;
         $data[] = ['role_id' => $permission['role_id'], 'permission_id' => $permissionId];
     }
     return $data;
 }
 public function update($id)
 {
     $user = User::findOrFail($id);
     $data = \Input::only(['user_permissions', 'user_role']);
     $currentRoleId = $user->role() ? $user->role()->id : NULL;
     if (isset($data['user_role']) && $currentRoleId != $data['user_role']) {
         $user->setRole($data['user_role']);
     }
     if (is_array($data['user_permissions']) && !empty($data['user_permissions'])) {
         $user->permissionsRelation()->delete();
         //Delete all permissions
         foreach ($data['user_permissions'] as $permission) {
             $permission = Permission::findOrFail($permission);
             if ($user->attachPermission($permission->name) === FALSE) {
                 Flash::error('You are trying to assign a disabled permission to this role!');
                 goto redirect;
             }
         }
     }
     Flash::success('User data successfully updated!');
     redirect:
     return redirect()->back();
 }
 public function it_successfully_detaches_permission(FunctionalTester $I)
 {
     $user = $this->userActor->create();
     $permission = 'accessDashboard';
     $permissionId = Permission::where('name', '=', $permission)->firstOrFail()->id;
     $user->setRole('admin');
     $I->assertTrue($user->attachPermission($permission));
     $I->seeRecord($this->UPT, ['user_id' => $user->id, 'permission_id' => $permissionId]);
     $user->detachPermission($permission);
     $I->dontSeeRecord($this->UPT, ['user_id' => $user->id, 'permission_id' => $permissionId]);
 }