fix: Dig params in widget contact end point (#4516)

This commit is contained in:
Muhsin Keloth 2022-04-21 20:39:45 +05:30 committed by GitHub
parent bd0ed322cc
commit b082b0e58c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 6 additions and 19 deletions

View file

@ -71,7 +71,7 @@ class Api::V1::Widget::BaseController < ApplicationController
end
def contact_email
permitted_params[:contact][:email].downcase if permitted_params[:contact].present?
permitted_params.dig(:contact, :email)&.downcase
end
def contact_name
@ -79,7 +79,7 @@ class Api::V1::Widget::BaseController < ApplicationController
end
def contact_phone_number
params[:contact][:phone_number]
permitted_params.dig(:contact, :phone_number)
end
def browser_params

View file

@ -69,7 +69,8 @@ class Api::V1::Widget::ConversationsController < Api::V1::Widget::BaseController
end
def permitted_params
params.permit(:id, :typing_status, :website_token, :email, contact: [:name, :email], message: [:content, :referer_url, :timestamp, :echo_id],
params.permit(:id, :typing_status, :website_token, :email, contact: [:name, :email, :phone_number],
message: [:content, :referer_url, :timestamp, :echo_id],
custom_attributes: {})
end
end

View file

@ -46,7 +46,7 @@ class MessageTemplates::HookExecutionService
# TODO: we should be able to reduce this logic once we have a toggle for email collect messages
def should_send_email_collect?
!contact_has_email? && inbox.web_widget? && !inbox.channel.pre_chat_form_enabled? && !email_collect_was_sent?
!contact_has_email? && inbox.web_widget? && !email_collect_was_sent?
end
def contact_has_email?

View file

@ -150,7 +150,7 @@ RSpec.describe '/api/v1/widget/messages', type: :request do
headers: { 'X-Auth-Token' => token },
as: :json
expect(response).to have_http_status(:internal_server_error)
expect(response).to have_http_status(:success)
end
end

View file

@ -62,20 +62,6 @@ describe ::MessageTemplates::HookExecutionService do
expect(email_collect_service).to have_received(:perform)
end
it 'doesnot calls ::MessageTemplates::Template::EmailCollect when prechat form is enabled' do
contact = create(:contact, email: nil)
conversation = create(:conversation, contact: contact)
# ensure prechat form is enabled
conversation.inbox.channel.update(pre_chat_form_enabled: true)
allow(::MessageTemplates::Template::EmailCollect).to receive(:new).and_return(true)
# described class gets called in message after commit
message = create(:message, conversation: conversation)
expect(::MessageTemplates::Template::EmailCollect).not_to have_received(:new).with(conversation: message.conversation)
end
it 'doesnot calls ::MessageTemplates::Template::EmailCollect on campaign conversations' do
contact = create(:contact, email: nil)
conversation = create(:conversation, contact: contact, campaign: create(:campaign))