2021-07-23 11:34:33 +00:00
|
|
|
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
|
2021-08-25 19:40:45 +00:00
|
|
|
@custom_attribute_definition = Current.account.custom_attribute_definitions.find(permitted_params[:id])
|
2021-07-23 11:34:33 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def permitted_payload
|
|
|
|
params.require(:custom_attribute_definition).permit(
|
|
|
|
:attribute_display_name,
|
2021-08-25 19:40:45 +00:00
|
|
|
:attribute_description,
|
2021-07-23 11:34:33 +00:00
|
|
|
:attribute_display_type,
|
|
|
|
:attribute_key,
|
|
|
|
:attribute_model,
|
|
|
|
:default_value
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
def permitted_params
|
2021-08-25 19:40:45 +00:00
|
|
|
params.permit(:id, :filter_type, :attribute_model)
|
2021-07-23 11:34:33 +00:00
|
|
|
end
|
|
|
|
end
|