51 lines
1.4 KiB
Ruby
51 lines
1.4 KiB
Ruby
class Api::V1::Accounts::CustomAttributeDefinitionsController < Api::V1::Accounts::BaseController
|
|
before_action :fetch_custom_attributes_definitions, except: [:create]
|
|
before_action :fetch_custom_attribute_definition, only: [:show, :update, :destroy]
|
|
DEFAULT_ATTRIBUTE_MODEL = 'conversation_attribute'.freeze
|
|
|
|
def index; end
|
|
|
|
def show; end
|
|
|
|
def create
|
|
@custom_attribute_definition = Current.account.custom_attribute_definitions.create!(
|
|
permitted_payload
|
|
)
|
|
end
|
|
|
|
def update
|
|
@custom_attribute_definition.update!(permitted_payload)
|
|
end
|
|
|
|
def destroy
|
|
@custom_attribute_definition.destroy
|
|
head :no_content
|
|
end
|
|
|
|
private
|
|
|
|
def fetch_custom_attributes_definitions
|
|
@custom_attribute_definitions = Current.account.custom_attribute_definitions.where(
|
|
attribute_model: permitted_params[:attribute_model] || DEFAULT_ATTRIBUTE_MODEL
|
|
)
|
|
end
|
|
|
|
def fetch_custom_attribute_definition
|
|
@custom_attribute_definition = Current.account.custom_attribute_definitions.find(permitted_params[:id])
|
|
end
|
|
|
|
def permitted_payload
|
|
params.require(:custom_attribute_definition).permit(
|
|
:attribute_display_name,
|
|
:attribute_description,
|
|
:attribute_display_type,
|
|
:attribute_key,
|
|
:attribute_model,
|
|
:default_value
|
|
)
|
|
end
|
|
|
|
def permitted_params
|
|
params.permit(:id, :filter_type, :attribute_model)
|
|
end
|
|
end
|