2014-11-02 19:44:15 +00:00
|
|
|
# Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/
|
|
|
|
|
|
|
|
class ObjectManagerAttributesController < ApplicationController
|
2015-05-07 11:23:55 +00:00
|
|
|
before_action :authentication_check
|
2014-11-02 19:44:15 +00:00
|
|
|
|
|
|
|
# GET /object_manager_attributes_list
|
|
|
|
def list
|
2015-02-15 09:12:27 +00:00
|
|
|
return if deny_if_not_role(Z_ROLENAME_ADMIN)
|
2015-04-27 13:42:53 +00:00
|
|
|
render json: {
|
2015-05-05 10:51:19 +00:00
|
|
|
objects: ObjectManager.list_frontend_objects,
|
2014-11-02 19:44:15 +00:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
# GET /object_manager_attributes
|
|
|
|
def index
|
2015-02-15 09:12:27 +00:00
|
|
|
return if deny_if_not_role(Z_ROLENAME_ADMIN)
|
2015-04-27 13:42:53 +00:00
|
|
|
render json: ObjectManager::Attribute.list_full
|
2014-11-02 19:44:15 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
# GET /object_manager_attributes/1
|
|
|
|
def show
|
2015-02-15 09:12:27 +00:00
|
|
|
return if deny_if_not_role(Z_ROLENAME_ADMIN)
|
2014-11-02 19:44:15 +00:00
|
|
|
model_show_render(ObjectManager::Attribute, params)
|
|
|
|
end
|
|
|
|
|
|
|
|
# POST /object_manager_attributes
|
|
|
|
def create
|
2015-02-15 09:12:27 +00:00
|
|
|
return if deny_if_not_role(Z_ROLENAME_ADMIN)
|
2016-05-19 08:20:38 +00:00
|
|
|
check_params
|
2016-05-23 22:48:32 +00:00
|
|
|
|
|
|
|
# check if attribute already exists
|
|
|
|
exists = ObjectManager::Attribute.get(
|
2016-05-19 08:20:38 +00:00
|
|
|
object: params[:object],
|
|
|
|
name: params[:name],
|
|
|
|
)
|
2016-05-23 22:48:32 +00:00
|
|
|
if exists
|
|
|
|
render json: model_match_error('already exists'), status: :unprocessable_entity
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
begin
|
|
|
|
object_manager_attribute = ObjectManager::Attribute.add(
|
|
|
|
object: params[:object],
|
|
|
|
name: params[:name],
|
|
|
|
display: params[:display],
|
|
|
|
data_type: params[:data_type],
|
|
|
|
data_option: params[:data_option],
|
|
|
|
active: params[:active],
|
|
|
|
screens: params[:screens],
|
|
|
|
position: 1550,
|
|
|
|
editable: true,
|
|
|
|
)
|
|
|
|
render json: object_manager_attribute.attributes_with_associations, status: :created
|
|
|
|
rescue => e
|
|
|
|
logger.error e.message
|
|
|
|
logger.error e.backtrace.inspect
|
|
|
|
render json: model_match_error(e.message), status: :unprocessable_entity
|
|
|
|
end
|
2014-11-02 19:44:15 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
# PUT /object_manager_attributes/1
|
|
|
|
def update
|
2015-02-15 09:12:27 +00:00
|
|
|
return if deny_if_not_role(Z_ROLENAME_ADMIN)
|
2016-05-19 08:20:38 +00:00
|
|
|
check_params
|
2016-05-23 22:48:32 +00:00
|
|
|
begin
|
|
|
|
object_manager_attribute = ObjectManager::Attribute.add(
|
|
|
|
object: params[:object],
|
|
|
|
name: params[:name],
|
|
|
|
display: params[:display],
|
|
|
|
data_type: params[:data_type],
|
|
|
|
data_option: params[:data_option],
|
|
|
|
active: params[:active],
|
|
|
|
screens: params[:screens],
|
|
|
|
position: 1550,
|
|
|
|
editable: true,
|
|
|
|
)
|
|
|
|
render json: object_manager_attribute.attributes_with_associations, status: :ok
|
|
|
|
rescue => e
|
|
|
|
logger.error e.message
|
|
|
|
logger.error e.backtrace.inspect
|
|
|
|
render json: model_match_error(e.message), status: :unprocessable_entity
|
|
|
|
end
|
2014-11-02 19:44:15 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
# DELETE /object_manager_attributes/1
|
|
|
|
def destroy
|
2015-02-15 09:12:27 +00:00
|
|
|
return if deny_if_not_role(Z_ROLENAME_ADMIN)
|
2016-05-19 08:20:38 +00:00
|
|
|
object_manager_attribute = ObjectManager::Attribute.find(params[:id])
|
|
|
|
ObjectManager::Attribute.remove(
|
|
|
|
object_lookup_id: object_manager_attribute.object_lookup_id,
|
|
|
|
name: object_manager_attribute.name,
|
|
|
|
)
|
|
|
|
model_destory_render_item
|
|
|
|
end
|
|
|
|
|
|
|
|
# POST /object_manager_attributes_discard_changes
|
|
|
|
def discard_changes
|
|
|
|
return if deny_if_not_role(Z_ROLENAME_ADMIN)
|
|
|
|
ObjectManager::Attribute.discard_changes
|
|
|
|
render json: {}, status: :ok
|
|
|
|
end
|
|
|
|
|
|
|
|
# POST /object_manager_attributes_execute_migrations
|
|
|
|
def execute_migrations
|
|
|
|
return if deny_if_not_role(Z_ROLENAME_ADMIN)
|
|
|
|
ObjectManager::Attribute.migration_execute
|
|
|
|
render json: {}, status: :ok
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def check_params
|
|
|
|
return if !params[:data_option][:null].nil?
|
|
|
|
params[:data_option][:null] = true
|
2014-11-02 19:44:15 +00:00
|
|
|
end
|
|
|
|
end
|