]> BookStack Code Mirror - bookstack/commitdiff
Fixed error upon user delete with no migration id
authorDan Brown <redacted>
Fri, 7 Apr 2023 14:57:21 +0000 (15:57 +0100)
committerDan Brown <redacted>
Fri, 7 Apr 2023 14:57:21 +0000 (15:57 +0100)
Fixes #4162

app/Http/Controllers/UserController.php
tests/User/UserManagementTest.php

index 2fcfa4289e20ec31f47f1aa5dd52f8e461d73508..cd95f7220766fb6598567afe8ca9d2d7098ac331 100644 (file)
@@ -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);
 
index d5cd7ac7963d671636a6b4ea12f9ca656fcfb6b7..7ccc5b773a7e88a120c4ee214a11c5c44fa44ea1 100644 (file)
@@ -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();