diff --git a/app/controllers/api/v1/accounts/bulk_actions_controller.rb b/app/controllers/api/v1/accounts/bulk_actions_controller.rb index 832f5a49b..34db47861 100644 --- a/app/controllers/api/v1/accounts/bulk_actions_controller.rb +++ b/app/controllers/api/v1/accounts/bulk_actions_controller.rb @@ -21,6 +21,6 @@ class Api::V1::Accounts::BulkActionsController < Api::V1::Accounts::BaseControll end def permitted_params - params.permit(:type, ids: [], fields: [:status, :assignee_id, :team_id], labels: [add: [], remove: []]) + params.permit(:type, :snoozed_until, ids: [], fields: [:status, :assignee_id, :team_id], labels: [add: [], remove: []]) end end diff --git a/app/jobs/bulk_actions_job.rb b/app/jobs/bulk_actions_job.rb index bc68b2b36..73fa1b151 100644 --- a/app/jobs/bulk_actions_job.rb +++ b/app/jobs/bulk_actions_job.rb @@ -1,4 +1,6 @@ class BulkActionsJob < ApplicationJob + include DateRangeHelper + queue_as :medium attr_accessor :records @@ -23,6 +25,7 @@ class BulkActionsJob < ApplicationJob params = available_params(@params) records.each do |conversation| bulk_add_labels(conversation) + bulk_snoozed_until(conversation) conversation.update(params) if params end end @@ -43,6 +46,10 @@ class BulkActionsJob < ApplicationJob conversation.add_labels(@params[:labels][:add]) if @params[:labels] && @params[:labels][:add] end + def bulk_snoozed_until(conversation) + conversation.snoozed_until = parse_date_time(@params[:snoozed_until].to_s) if @params[:snoozed_until] + end + def remove_labels(conversation) return unless @params[:labels] && @params[:labels][:remove] diff --git a/spec/jobs/bulk_actions_job_spec.rb b/spec/jobs/bulk_actions_job_spec.rb index f227a7f3c..3b0ff8133 100644 --- a/spec/jobs/bulk_actions_job_spec.rb +++ b/spec/jobs/bulk_actions_job_spec.rb @@ -65,5 +65,21 @@ RSpec.describe BulkActionsJob do expect(Conversation.second.assignee_id).to eq(agent.id) expect(Conversation.third.assignee_id).to eq(agent.id) end + + it 'bulk updates the snoozed_until' do + params = { + type: 'Conversation', + fields: { status: 'snoozed', snoozed_until: Time.zone.now }, + ids: Conversation.first(3).pluck(:display_id) + } + + expect(Conversation.first.snoozed_until).to be_nil + + described_class.perform_now(account: account, params: params, user: agent) + + expect(Conversation.first.snoozed_until).to be_present + expect(Conversation.second.snoozed_until).to be_present + expect(Conversation.third.snoozed_until).to be_present + end end end