From 9e173fca3cec7acbb70489de22bd049089bac0db Mon Sep 17 00:00:00 2001 From: Pranav Raj S Date: Thu, 12 Oct 2023 04:30:51 -0700 Subject: [PATCH] fix: Return 404 if conversation is nil (#8098) --- .../api/v1/widget/conversations_controller.rb | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/app/controllers/api/v1/widget/conversations_controller.rb b/app/controllers/api/v1/widget/conversations_controller.rb index 2c72a0361..431ffe2d5 100644 --- a/app/controllers/api/v1/widget/conversations_controller.rb +++ b/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 @@ -41,8 +42,6 @@ class Api::V1::Widget::ConversationsController < Api::V1::Widget::BaseController end def toggle_typing - head :ok && return if conversation.nil? - case permitted_params[:typing_status] when 'on' trigger_typing_event(CONVERSATION_TYPING_ON) @@ -54,8 +53,6 @@ class Api::V1::Widget::ConversationsController < Api::V1::Widget::BaseController end def toggle_status - return head :not_found if conversation.nil? - return head :forbidden unless @web_widget.end_conversation? unless conversation.resolved? @@ -81,6 +78,10 @@ class Api::V1::Widget::ConversationsController < Api::V1::Widget::BaseController 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],