2014-02-03 19:24:49 +00:00
|
|
|
# Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/
|
2013-06-12 15:59:58 +00:00
|
|
|
|
2012-04-10 14:06:46 +00:00
|
|
|
class SettingsController < ApplicationController
|
2015-05-07 11:23:55 +00:00
|
|
|
before_action :authentication_check
|
2012-04-10 14:06:46 +00:00
|
|
|
|
|
|
|
# GET /settings
|
|
|
|
def index
|
2015-02-15 09:12:27 +00:00
|
|
|
return if deny_if_not_role(Z_ROLENAME_ADMIN)
|
2012-09-20 12:08:02 +00:00
|
|
|
model_index_render(Setting, params)
|
2012-04-10 14:06:46 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
# GET /settings/1
|
|
|
|
def show
|
2015-02-15 09:12:27 +00:00
|
|
|
return if deny_if_not_role(Z_ROLENAME_ADMIN)
|
2012-09-20 12:08:02 +00:00
|
|
|
model_show_render(Setting, params)
|
2012-04-10 14:06:46 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
# POST /settings
|
|
|
|
def create
|
2015-02-15 09:12:27 +00:00
|
|
|
return if deny_if_not_role(Z_ROLENAME_ADMIN)
|
2012-09-20 12:08:02 +00:00
|
|
|
model_create_render(Setting, params)
|
2012-04-10 14:06:46 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
# PUT /settings/1
|
|
|
|
def update
|
2015-02-15 09:12:27 +00:00
|
|
|
return if deny_if_not_role(Z_ROLENAME_ADMIN)
|
2015-07-16 13:36:59 +00:00
|
|
|
return if !check_access
|
2012-09-20 12:08:02 +00:00
|
|
|
model_update_render(Setting, params)
|
2012-04-10 14:06:46 +00:00
|
|
|
end
|
|
|
|
|
2015-07-12 01:32:40 +00:00
|
|
|
# PUT /settings/image/:id
|
|
|
|
def update_image
|
2015-07-16 13:36:59 +00:00
|
|
|
return if deny_if_not_role(Z_ROLENAME_ADMIN)
|
2015-07-12 01:32:40 +00:00
|
|
|
|
|
|
|
if !params[:logo]
|
|
|
|
render json: {
|
|
|
|
result: 'invalid',
|
|
|
|
message: 'Need logo param',
|
|
|
|
}
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
# validate image
|
|
|
|
if params[:logo] !~ /^data:image/i
|
|
|
|
render json: {
|
|
|
|
result: 'invalid',
|
|
|
|
message: 'Invalid payload, need data:image in logo param',
|
|
|
|
}
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
# process image
|
|
|
|
file = StaticAssets.data_url_attributes(params[:logo])
|
|
|
|
if !file[:content] || !file[:mime_type]
|
|
|
|
render json: {
|
|
|
|
result: 'invalid',
|
|
|
|
message: 'Unable to process image upload.',
|
|
|
|
}
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
# store image 1:1
|
|
|
|
StaticAssets.store_raw(file[:content], file[:mime_type])
|
|
|
|
|
|
|
|
# store resized image 1:1
|
|
|
|
setting = Setting.find_by(name: 'product_logo')
|
|
|
|
if params[:logo_resize] && params[:logo_resize] =~ /^data:image/i
|
|
|
|
|
|
|
|
# data:image/png;base64
|
2016-05-10 13:06:51 +00:00
|
|
|
file = StaticAssets.data_url_attributes(params[:logo_resize])
|
2015-07-12 01:32:40 +00:00
|
|
|
|
|
|
|
# store image 1:1
|
2016-05-25 07:19:45 +00:00
|
|
|
setting.state = StaticAssets.store(file[:content], file[:mime_type])
|
2015-07-12 01:32:40 +00:00
|
|
|
setting.save
|
|
|
|
end
|
|
|
|
|
|
|
|
render json: {
|
|
|
|
result: 'ok',
|
|
|
|
settings: [setting],
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2012-04-10 14:06:46 +00:00
|
|
|
# DELETE /settings/1
|
|
|
|
def destroy
|
2015-02-15 09:12:27 +00:00
|
|
|
return if deny_if_not_role(Z_ROLENAME_ADMIN)
|
2015-08-29 11:46:48 +00:00
|
|
|
return if !check_access
|
2012-09-20 12:08:02 +00:00
|
|
|
model_destory_render(Setting, params)
|
2012-04-10 14:06:46 +00:00
|
|
|
end
|
2015-07-16 13:36:59 +00:00
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def check_access
|
|
|
|
return true if !Setting.get('system_online_service')
|
|
|
|
|
|
|
|
setting = Setting.find(params[:id])
|
|
|
|
return true if setting.preferences && !setting.preferences[:online_service_disable]
|
|
|
|
|
|
|
|
response_access_deny
|
2015-07-16 14:41:28 +00:00
|
|
|
false
|
2015-07-16 13:36:59 +00:00
|
|
|
end
|
2012-04-10 14:06:46 +00:00
|
|
|
end
|