diff --git a/app/Http/Controllers/Users/UsersController.php b/app/Http/Controllers/Users/UsersController.php index 3d971d9e6b..8df5842929 100755 --- a/app/Http/Controllers/Users/UsersController.php +++ b/app/Http/Controllers/Users/UsersController.php @@ -370,10 +370,10 @@ class UsersController extends Controller ->with('error', trans_choice('admin/users/message.error.delete_has_locations_var', $user->managedLocations()->count(), ['count'=> $user->managedLocations()->count()])); } -// if (($user->managesUsers()) && ($user->managesUsers()->count() > 0)) { -// return redirect()->route('users.index') -// ->with('error', trans_choice('admin/users/message.error.delete_has_users_var', $user->managesUsers()->count(), ['count'=> $user->managesUsers()->count()])); -// } + if (($user->managesUsers()) && ($user->managesUsers()->count() > 0)) { + return redirect()->route('users.index') + ->with('error', trans_choice('admin/users/message.error.delete_has_users_var', $user->managesUsers()->count(), ['count'=> $user->managesUsers()->count()])); + } // Delete the user $user->delete(); diff --git a/tests/Feature/Users/DeleteUsersTest.php b/tests/Feature/Users/DeleteUsersTest.php index 3d2da4bf4e..a9ac1ab1ff 100644 --- a/tests/Feature/Users/DeleteUsersTest.php +++ b/tests/Feature/Users/DeleteUsersTest.php @@ -18,10 +18,12 @@ class DeleteUsersTest extends TestCase $this->actingAs(User::factory()->deleteUsers()->create())->assertFalse($manager->isDeletable()); - $this->actingAs(User::factory()->deleteUsers()->create()) + $response = $this->actingAs(User::factory()->deleteUsers()->viewUsers()->create()) ->delete(route('users.destroy', $manager->id)) ->assertStatus(302) ->assertRedirect(route('users.index')); + + $this->followRedirects($response)->assertSee('Error'); } public function testDisallowUserDeletionIfStillManagingLocations() @@ -31,10 +33,12 @@ class DeleteUsersTest extends TestCase $this->actingAs(User::factory()->deleteUsers()->create())->assertFalse($manager->isDeletable()); - $this->actingAs(User::factory()->deleteUsers()->create()) + $response = $this->actingAs(User::factory()->deleteUsers()->viewUsers()->create()) ->delete(route('users.destroy', $manager->id)) ->assertStatus(302) ->assertRedirect(route('users.index')); + + $this->followRedirects($response)->assertSee('Error'); } public function testAllowUserDeletionIfNotManagingLocations() @@ -42,10 +46,13 @@ class DeleteUsersTest extends TestCase $manager = User::factory()->create(); $this->actingAs(User::factory()->deleteUsers()->create())->assertTrue($manager->isDeletable()); - $this->actingAs(User::factory()->deleteUsers()->create()) + $response = $this->actingAs(User::factory()->deleteUsers()->viewUsers()->create()) ->delete(route('users.destroy', $manager->id)) ->assertStatus(302) ->assertRedirect(route('users.index')); + + $this->followRedirects($response)->assertSee('Success'); + } public function testDisallowUserDeletionIfNoDeletePermissions()