Prevent the admin (acting) user from still being associated with a deleted company (if deleting the comapny was selected)

This commit is contained in:
snipe
2026-05-30 18:13:23 +01:00
parent 2e91b3dc9a
commit 990c50c5b9
2 changed files with 19 additions and 0 deletions
+3
View File
@@ -924,6 +924,9 @@ class BulkDelete extends Command
->delete();
DB::table('consumables_users')->where('assigned_to', $user->id)->delete();
CheckoutAcceptance::where('assigned_to_id', $user->id)->forceDelete();
if ($deleteType === 'hard') {
DB::table('company_user')->where('user_id', $user->id)->delete();
}
if ($clearLogs) {
$user->userlog()->forceDelete();
+16
View File
@@ -721,6 +721,22 @@ class BulkDeleteTest extends TestCase
$this->assertSoftDeleted($user);
}
public function test_user_hard_delete_removes_company_user_pivot_entries(): void
{
$admin = User::factory()->superuser()->create();
$company = Company::factory()->create();
$user = User::factory()->create(['company_id' => $company->id, 'activated' => 1]);
$user->companies()->syncWithoutDetaching([$company->id]);
$this->assertDatabaseHas('company_user', ['user_id' => $user->id, 'company_id' => $company->id]);
$this->runCommand($admin, [$company->id], ['users'], deleteType: 'hard')
->assertExitCode(0);
$this->assertDatabaseMissing('users', ['id' => $user->id]);
$this->assertDatabaseMissing('company_user', ['user_id' => $user->id]);
}
// ---------------------------------------------------------------------------
// Email report
// ---------------------------------------------------------------------------