Skip to content

Commit

Permalink
fix: Return 404 if conversation is nil (#8098)
Browse files Browse the repository at this point in the history
  • Loading branch information
pranavrajs committed Oct 12, 2023
1 parent bd918ee commit 9e173fc
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions app/controllers/api/v1/widget/conversations_controller.rb
@@ -1,5 +1,6 @@
class Api::V1::Widget::ConversationsController < Api::V1::Widget::BaseController
include Events::Types
before_action :render_not_found_if_empty, only: [:toggle_typing, :toggle_status, :set_custom_attributes, :destroy_custom_attributes]

def index
@conversation = conversation
Expand Down Expand Up @@ -41,8 +42,6 @@ def transcript
end

def toggle_typing
head :ok && return if conversation.nil?

case permitted_params[:typing_status]
when 'on'
trigger_typing_event(CONVERSATION_TYPING_ON)
Expand All @@ -54,8 +53,6 @@ def toggle_typing
end

def toggle_status
return head :not_found if conversation.nil?

return head :forbidden unless @web_widget.end_conversation?

unless conversation.resolved?
Expand All @@ -81,6 +78,10 @@ def trigger_typing_event(event)
Rails.configuration.dispatcher.dispatch(event, Time.zone.now, conversation: conversation, user: @contact)
end

def render_not_found_if_empty
return head :not_found if conversation.nil?
end

def permitted_params
params.permit(:id, :typing_status, :website_token, :email, contact: [:name, :email, :phone_number],
message: [:content, :referer_url, :timestamp, :echo_id],
Expand Down

0 comments on commit 9e173fc

Please sign in to comment.