Fixed delete role failing with no migrate role provided

For #4128
This commit is contained in:
Dan Brown 2023-03-25 12:07:59 +00:00
parent 3410cf21cb
commit 0a0fdd7f3e
No known key found for this signature in database
GPG Key ID: 46D9F943C24A2EF9
2 changed files with 18 additions and 1 deletions

View File

@ -151,7 +151,8 @@ class RoleController extends Controller
$this->checkPermission('user-roles-manage');
try {
$this->permissionsRepo->deleteRole($id, $request->get('migrate_role_id', 0));
$migrateRoleId = intval($request->get('migrate_role_id') ?: "0");
$this->permissionsRepo->deleteRole($id, $migrateRoleId);
} catch (PermissionsException $e) {
$this->showErrorNotification($e->getMessage());

View File

@ -163,6 +163,22 @@ class RolesTest extends TestCase
$this->assertEquals($this->user->id, $roleA->users()->first()->id);
}
public function test_delete_with_empty_migrate_option_works()
{
$role = $this->users->attachNewRole($this->user);
$this->assertCount(1, $role->users()->get());
$deletePage = $this->asAdmin()->get("/settings/roles/delete/$role->id");
$this->withHtml($deletePage)->assertElementExists('select[name=migrate_role_id]');
$resp = $this->asAdmin()->delete("/settings/roles/delete/$role->id", [
'migrate_role_id' => '',
]);
$resp->assertRedirect('/settings/roles');
$this->assertDatabaseMissing('roles', ['id' => $role->id]);
}
public function test_entity_permissions_are_removed_on_delete()
{
/** @var Role $roleA */