Prevent the admin (acting) user from still being associated with a deleted company (if deleting the comapny was selected)
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -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
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user