2019-11-30 12:03:42 +00:00
|
|
|
class Api::V1::Widget::InboxesController < Api::BaseController
|
|
|
|
before_action :authorize_request
|
|
|
|
|
2019-10-29 07:20:54 +00:00
|
|
|
def create
|
|
|
|
ActiveRecord::Base.transaction do
|
|
|
|
channel = web_widgets.create!(
|
|
|
|
website_name: permitted_params[:website_name],
|
2019-12-14 12:44:35 +00:00
|
|
|
website_url: permitted_params[:website_url],
|
|
|
|
widget_color: permitted_params[:widget_color]
|
2019-10-29 07:20:54 +00:00
|
|
|
)
|
2019-11-30 12:03:42 +00:00
|
|
|
@inbox = inboxes.create!(name: permitted_params[:website_name], channel: channel)
|
2019-10-29 07:20:54 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2019-11-30 12:03:42 +00:00
|
|
|
def authorize_request
|
|
|
|
authorize ::Inbox
|
|
|
|
end
|
|
|
|
|
2019-10-29 07:20:54 +00:00
|
|
|
def inboxes
|
|
|
|
current_account.inboxes
|
|
|
|
end
|
|
|
|
|
|
|
|
def web_widgets
|
|
|
|
current_account.web_widgets
|
|
|
|
end
|
|
|
|
|
|
|
|
def permitted_params
|
2019-12-14 12:44:35 +00:00
|
|
|
params.fetch(:website).permit(:website_name, :website_url, :widget_color)
|
2019-10-29 07:20:54 +00:00
|
|
|
end
|
|
|
|
end
|