fix: Twilio validation over blank messaging_service_sid (#5055)

This commit is contained in:
Tejaswini Chile
2022-07-18 20:02:37 +05:30
committed by GitHub
parent fd44f9f28a
commit 00dc65ef73
4 changed files with 84 additions and 4 deletions

View File

@@ -27,6 +27,8 @@ class Api::V1::Accounts::Channels::TwilioChannelsController < Api::V1::Accounts:
end
def phone_number
return if permitted_params[:phone_number].blank?
medium == 'sms' ? permitted_params[:phone_number] : "whatsapp:#{permitted_params[:phone_number]}"
end
@@ -38,7 +40,7 @@ class Api::V1::Accounts::Channels::TwilioChannelsController < Api::V1::Accounts:
@twilio_channel = Current.account.twilio_sms.create!(
account_sid: permitted_params[:account_sid],
auth_token: permitted_params[:auth_token],
messaging_service_sid: permitted_params[:messaging_service_sid],
messaging_service_sid: permitted_params[:messaging_service_sid].presence,
phone_number: phone_number,
medium: medium
)

View File

@@ -28,8 +28,8 @@ class Channel::TwilioSms < ApplicationRecord
validates :auth_token, presence: true
# Must have _one_ of messaging_service_sid _or_ phone_number, and messaging_service_sid is preferred
validates :messaging_service_sid, uniqueness: true, presence: true, unless: :phone_number?
validates :phone_number, absence: true, if: :messaging_service_sid?
validates :messaging_service_sid, uniqueness: true, presence: true, unless: :phone_number.presence
validates :phone_number, absence: true, if: :messaging_service_sid.presence
validates :phone_number, uniqueness: true, allow_nil: true
enum medium: { sms: 0, whatsapp: 1 }