mirror of
https://github.com/lingble/chatwoot.git
synced 2025-10-29 18:22:53 +00:00
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]
|
||||
|
||||
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
|
||||
end
|
||||
|
||||
|
||||
@@ -1,14 +1,16 @@
|
||||
class Webhooks::Trigger
|
||||
def self.execute(url, payload)
|
||||
RestClient::Request.execute(
|
||||
response = RestClient::Request.execute(
|
||||
method: :post,
|
||||
url: url, payload: payload.to_json,
|
||||
headers: { content_type: :json, accept: :json },
|
||||
timeout: 5
|
||||
)
|
||||
Rails.logger.info "Performed Request: Code - #{response.code}"
|
||||
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
|
||||
Rails.logger.error "Exception: invalid webhook url #{url} : #{e.message}"
|
||||
Sentry.capture_exception(e)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -324,7 +324,7 @@ RSpec.describe 'Inboxes API', type: :request do
|
||||
|
||||
context 'when it is an authenticated user' do
|
||||
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
|
||||
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(inbox.reload.enable_auto_assignment).to be_falsey
|
||||
expect(JSON.parse(response.body)['name']).to eq 'new test inbox'
|
||||
end
|
||||
|
||||
it 'updates api inbox when administrator' do
|
||||
@@ -384,7 +385,6 @@ RSpec.describe 'Inboxes API', type: :request do
|
||||
headers: admin.create_new_auth_token
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
expect(response.body).to include('test.com')
|
||||
inbox.reload
|
||||
expect(inbox.avatar.attached?).to eq(true)
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user