feat: Bulk delete for contacts (#12778)

Introduces a new bulk action `delete` for contacts

ref: https://github.com/chatwoot/chatwoot/pull/12763

## Screens

<img width="1492" height="973" alt="Screenshot 2025-10-31 at 6 27 21 PM"
src="https://github.com/user-attachments/assets/30dab1bb-2c2c-4168-9800-44e0eb5f8e3a"
/>
<img width="1492" height="985" alt="Screenshot 2025-10-31 at 6 27 32 PM"
src="https://github.com/user-attachments/assets/5be610c4-b19e-4614-a164-103b22337382"
/>
This commit is contained in:
Sojan Jose
2025-11-04 17:47:53 -08:00
committed by GitHub
parent e8ae73230d
commit f89d9a4401
11 changed files with 325 additions and 95 deletions

View File

@@ -6,6 +6,7 @@ class Contacts::BulkActionService
end
def perform
return delete_contacts if delete_requested?
return assign_labels if labels_to_add.any?
Rails.logger.warn("Unknown contact bulk operation payload: #{@params.keys}")
@@ -22,6 +23,13 @@ class Contacts::BulkActionService
).perform
end
def delete_contacts
Contacts::BulkDeleteService.new(
account: @account,
contact_ids: ids
).perform
end
def ids
Array(@params[:ids]).compact
end
@@ -29,4 +37,8 @@ class Contacts::BulkActionService
def labels_to_add
@labels_to_add ||= Array(@params.dig(:labels, :add)).reject(&:blank?)
end
def delete_requested?
@params[:action_name] == 'delete'
end
end

View File

@@ -0,0 +1,18 @@
class Contacts::BulkDeleteService
def initialize(account:, contact_ids: [])
@account = account
@contact_ids = Array(contact_ids).compact
end
def perform
return if @contact_ids.blank?
contacts.find_each(&:destroy!)
end
private
def contacts
@account.contacts.where(id: @contact_ids)
end
end