2020-04-03 07:34:58 +00:00
|
|
|
class Api::V1::Widget::LabelsController < Api::V1::Widget::BaseController
|
|
|
|
def create
|
2020-09-20 13:59:39 +00:00
|
|
|
if conversation.present? && label_defined_in_account?
|
2020-09-18 13:20:53 +00:00
|
|
|
conversation.label_list.add(permitted_params[:label])
|
|
|
|
conversation.save!
|
|
|
|
end
|
2020-04-03 07:34:58 +00:00
|
|
|
|
|
|
|
head :no_content
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
2020-09-18 13:20:53 +00:00
|
|
|
if conversation.present?
|
|
|
|
conversation.label_list.remove(permitted_params[:id])
|
|
|
|
conversation.save!
|
|
|
|
end
|
2020-04-03 07:34:58 +00:00
|
|
|
|
|
|
|
head :no_content
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2020-09-20 13:59:39 +00:00
|
|
|
def label_defined_in_account?
|
2020-10-05 12:25:46 +00:00
|
|
|
label = @current_account.labels&.find_by(title: permitted_params[:label])
|
2020-09-20 13:59:39 +00:00
|
|
|
label.present?
|
|
|
|
end
|
|
|
|
|
2020-04-03 07:34:58 +00:00
|
|
|
def permitted_params
|
|
|
|
params.permit(:id, :label, :website_token)
|
|
|
|
end
|
|
|
|
end
|