Feature: API Channel (#1052)

This commit is contained in:
Sojan Jose
2020-07-21 12:15:24 +05:30
committed by GitHub
parent fa04098c20
commit 8079bf50a0
40 changed files with 735 additions and 246 deletions

View File

@@ -4,12 +4,12 @@ class Api::V1::Accounts::InboxesController < Api::V1::Accounts::BaseController
before_action :check_authorization
def index
@inboxes = policy_scope(Current.account.inboxes)
@inboxes = policy_scope(Current.account.inboxes.includes(:channel, :avatar_attachment))
end
def create
ActiveRecord::Base.transaction do
channel = web_widgets.create!(permitted_params[:channel].except(:type)) if permitted_params[:channel][:type] == 'web_widget'
channel = create_channel
@inbox = Current.account.inboxes.build(
name: permitted_params[:name],
greeting_message: permitted_params[:greeting_message],
@@ -52,21 +52,28 @@ class Api::V1::Accounts::InboxesController < Api::V1::Accounts::BaseController
@agent_bot = AgentBot.find(params[:agent_bot]) if params[:agent_bot]
end
def web_widgets
Current.account.web_widgets
end
def check_authorization
authorize(Inbox)
end
def create_channel
case permitted_params[:channel][:type]
when 'web_widget'
Current.account.web_widgets.create!(permitted_params[:channel].except(:type))
when 'api'
Current.account.api_channels.create!(permitted_params[:channel].except(:type))
when 'email'
Current.account.email_channels.create!(permitted_params[:channel].except(:type))
end
end
def permitted_params
params.permit(:id, :avatar, :name, :greeting_message, :greeting_enabled, channel:
[:type, :website_url, :widget_color, :welcome_title, :welcome_tagline])
[:type, :website_url, :widget_color, :welcome_title, :welcome_tagline, :webhook_url, :email])
end
def inbox_update_params
params.permit(:enable_auto_assignment, :name, :avatar, :greeting_message, :greeting_enabled,
channel: [:website_url, :widget_color, :welcome_title, :welcome_tagline])
channel: [:website_url, :widget_color, :welcome_title, :welcome_tagline, :webhook_url, :email])
end
end