2019-11-30 12:03:42 +00:00
|
|
|
class Api::V1::Widget::InboxesController < Api::BaseController
|
|
|
|
before_action :authorize_request
|
2019-12-28 16:26:42 +00:00
|
|
|
before_action :set_web_widget_channel, only: [:update]
|
|
|
|
before_action :set_inbox, only: [:update]
|
2019-11-30 12:03:42 +00:00
|
|
|
|
2019-10-29 07:20:54 +00:00
|
|
|
def create
|
|
|
|
ActiveRecord::Base.transaction do
|
|
|
|
channel = web_widgets.create!(
|
2019-12-28 16:26:42 +00:00
|
|
|
website_name: permitted_params[:website][:website_name],
|
|
|
|
website_url: permitted_params[:website][:website_url],
|
|
|
|
widget_color: permitted_params[:website][:widget_color]
|
2019-10-29 07:20:54 +00:00
|
|
|
)
|
2019-12-28 16:26:42 +00:00
|
|
|
@inbox = inboxes.create!(name: permitted_params[:website][:website_name], channel: channel)
|
2019-10-29 07:20:54 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-12-28 16:26:42 +00:00
|
|
|
def update
|
|
|
|
@channel.update!(
|
|
|
|
widget_color: permitted_params[:website][:widget_color]
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
2019-10-29 07:20:54 +00:00
|
|
|
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
|
|
|
|
|
2019-12-28 16:26:42 +00:00
|
|
|
def set_web_widget_channel
|
|
|
|
@channel = web_widgets.find_by(id: permitted_params[:id])
|
|
|
|
end
|
|
|
|
|
|
|
|
def set_inbox
|
|
|
|
@inbox = @channel.inbox
|
|
|
|
end
|
|
|
|
|
2019-10-29 07:20:54 +00:00
|
|
|
def permitted_params
|
2019-12-28 16:26:42 +00:00
|
|
|
params.permit(:id, website: [:website_name, :website_url, :widget_color])
|
2019-10-29 07:20:54 +00:00
|
|
|
end
|
|
|
|
end
|