chore: Minor API fixes (#3290)
- Log whether web-hook was successful - Inbox update shouldn't need channel params
This commit is contained in:
@@ -43,7 +43,11 @@ class Api::V1::Accounts::InboxesController < Api::V1::Accounts::BaseController
|
|||||||
@inbox.update_working_hours(params.permit(working_hours: Inbox::OFFISABLE_ATTRS)[:working_hours]) if params[:working_hours]
|
@inbox.update_working_hours(params.permit(working_hours: Inbox::OFFISABLE_ATTRS)[:working_hours]) if params[:working_hours]
|
||||||
|
|
||||||
channel_attributes = get_channel_attributes(@inbox.channel_type)
|
channel_attributes = get_channel_attributes(@inbox.channel_type)
|
||||||
@inbox.channel.update!(permitted_params(channel_attributes)[:channel]) if permitted_params(channel_attributes)[:channel].present?
|
|
||||||
|
# Inbox update doesn't necessarily need channel attributes
|
||||||
|
return if permitted_params(channel_attributes)[:channel].blank?
|
||||||
|
|
||||||
|
@inbox.channel.update!(permitted_params(channel_attributes)[:channel])
|
||||||
update_channel_feature_flags
|
update_channel_feature_flags
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -1,14 +1,16 @@
|
|||||||
class Webhooks::Trigger
|
class Webhooks::Trigger
|
||||||
def self.execute(url, payload)
|
def self.execute(url, payload)
|
||||||
RestClient::Request.execute(
|
response = RestClient::Request.execute(
|
||||||
method: :post,
|
method: :post,
|
||||||
url: url, payload: payload.to_json,
|
url: url, payload: payload.to_json,
|
||||||
headers: { content_type: :json, accept: :json },
|
headers: { content_type: :json, accept: :json },
|
||||||
timeout: 5
|
timeout: 5
|
||||||
)
|
)
|
||||||
|
Rails.logger.info "Performed Request: Code - #{response.code}"
|
||||||
rescue *ExceptionList::REST_CLIENT_EXCEPTIONS => e
|
rescue *ExceptionList::REST_CLIENT_EXCEPTIONS => e
|
||||||
Rails.logger.info "Exception: invalid webhook url #{url} : #{e.message}"
|
Rails.logger.error "Exception: invalid webhook url #{url} : #{e.message}"
|
||||||
rescue StandardError => e
|
rescue StandardError => e
|
||||||
|
Rails.logger.error "Exception: invalid webhook url #{url} : #{e.message}"
|
||||||
Sentry.capture_exception(e)
|
Sentry.capture_exception(e)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -324,7 +324,7 @@ RSpec.describe 'Inboxes API', type: :request do
|
|||||||
|
|
||||||
context 'when it is an authenticated user' do
|
context 'when it is an authenticated user' do
|
||||||
let(:admin) { create(:user, account: account, role: :administrator) }
|
let(:admin) { create(:user, account: account, role: :administrator) }
|
||||||
let(:valid_params) { { enable_auto_assignment: false, channel: { website_url: 'test.com' } } }
|
let(:valid_params) { { name: 'new test inbox', enable_auto_assignment: false } }
|
||||||
|
|
||||||
it 'will not update inbox for agent' do
|
it 'will not update inbox for agent' do
|
||||||
agent = create(:user, account: account, role: :agent)
|
agent = create(:user, account: account, role: :agent)
|
||||||
@@ -345,6 +345,7 @@ RSpec.describe 'Inboxes API', type: :request do
|
|||||||
|
|
||||||
expect(response).to have_http_status(:success)
|
expect(response).to have_http_status(:success)
|
||||||
expect(inbox.reload.enable_auto_assignment).to be_falsey
|
expect(inbox.reload.enable_auto_assignment).to be_falsey
|
||||||
|
expect(JSON.parse(response.body)['name']).to eq 'new test inbox'
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'updates api inbox when administrator' do
|
it 'updates api inbox when administrator' do
|
||||||
@@ -384,7 +385,6 @@ RSpec.describe 'Inboxes API', type: :request do
|
|||||||
headers: admin.create_new_auth_token
|
headers: admin.create_new_auth_token
|
||||||
|
|
||||||
expect(response).to have_http_status(:success)
|
expect(response).to have_http_status(:success)
|
||||||
expect(response.body).to include('test.com')
|
|
||||||
inbox.reload
|
inbox.reload
|
||||||
expect(inbox.avatar.attached?).to eq(true)
|
expect(inbox.avatar.attached?).to eq(true)
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user