From fd674d10e318e5dfea71dc8f0f94c812dc14c30e Mon Sep 17 00:00:00 2001 From: Dan Brown Date: Fri, 7 Apr 2023 15:57:21 +0100 Subject: [PATCH] Fixed error upon user delete with no migration id Fixes #4162 --- app/Http/Controllers/UserController.php | 2 +- tests/User/UserManagementTest.php | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/UserController.php b/app/Http/Controllers/UserController.php index 2fcfa4289..cd95f7220 100644 --- a/app/Http/Controllers/UserController.php +++ b/app/Http/Controllers/UserController.php @@ -197,7 +197,7 @@ class UserController extends Controller $this->checkPermissionOrCurrentUser('users-manage', $id); $user = $this->userRepo->getById($id); - $newOwnerId = $request->get('new_owner_id', null); + $newOwnerId = intval($request->get('new_owner_id')) ?: null; $this->userRepo->destroy($user, $newOwnerId); diff --git a/tests/User/UserManagementTest.php b/tests/User/UserManagementTest.php index d5cd7ac79..7ccc5b773 100644 --- a/tests/User/UserManagementTest.php +++ b/tests/User/UserManagementTest.php @@ -162,6 +162,16 @@ class UserManagementTest extends TestCase ]); } + public function test_delete_with_empty_owner_migration_id_works() + { + $user = $this->users->editor(); + + $resp = $this->asAdmin()->delete("settings/users/{$user->id}", ['new_owner_id' => '']); + $resp->assertRedirect('/settings/users'); + $this->assertActivityExists(ActivityType::USER_DELETE); + $this->assertSessionHas('success'); + } + public function test_delete_removes_user_preferences() { $editor = $this->users->editor();