discourse/app/controllers/admin/site_customizations_control...

93 lines
2.7 KiB
Ruby
Raw Normal View History

2013-02-05 14:16:51 -05:00
class Admin::SiteCustomizationsController < Admin::AdminController
2013-02-07 10:45:24 -05:00
before_filter :enable_customization
skip_before_filter :check_xhr, only: [:show]
2013-02-05 14:16:51 -05:00
def index
@site_customizations = SiteCustomization.order(:name)
2013-02-05 14:16:51 -05:00
respond_to do |format|
format.json { render json: @site_customizations }
end
end
def create
@site_customization = SiteCustomization.new(site_customization_params)
2013-02-05 14:16:51 -05:00
@site_customization.user_id = current_user.id
respond_to do |format|
if @site_customization.save
log_site_customization_change(nil, site_customization_params)
2013-02-05 14:16:51 -05:00
format.json { render json: @site_customization, status: :created}
else
format.json { render json: @site_customization.errors, status: :unprocessable_entity }
end
end
end
def update
@site_customization = SiteCustomization.find(params[:id])
log_record = log_site_customization_change(@site_customization, site_customization_params)
2013-02-05 14:16:51 -05:00
respond_to do |format|
if @site_customization.update_attributes(site_customization_params)
format.json { render json: @site_customization, status: :created}
2013-02-05 14:16:51 -05:00
else
log_record.destroy if log_record
2013-02-05 14:16:51 -05:00
format.json { render json: @site_customization.errors, status: :unprocessable_entity }
end
end
end
def destroy
@site_customization = SiteCustomization.find(params[:id])
StaffActionLogger.new(current_user).log_site_customization_destroy(@site_customization)
2013-02-05 14:16:51 -05:00
@site_customization.destroy
respond_to do |format|
format.json { head :no_content }
end
end
def show
@site_customization = SiteCustomization.find(params[:id])
respond_to do |format|
format.json do
check_xhr
render json: SiteCustomizationSerializer.new(@site_customization)
end
format.any(:html, :text) do
raise RenderEmpty.new if request.xhr?
2015-05-19 21:35:16 -04:00
response.headers['Content-Disposition'] = "attachment; filename=#{@site_customization.name.parameterize}.dcstyle.json"
response.sending_file = true
render json: SiteCustomizationSerializer.new(@site_customization)
end
end
end
private
def site_customization_params
2014-11-10 15:51:55 -05:00
params.require(:site_customization)
.permit(:name, :stylesheet, :header, :top, :footer,
:mobile_stylesheet, :mobile_header, :mobile_top, :mobile_footer,
:head_tag, :body_tag,
:position, :enabled, :key,
:stylesheet_baked, :embedded_css)
end
def log_site_customization_change(old_record, new_params)
StaffActionLogger.new(current_user).log_site_customization_change(old_record, new_params)
end
def enable_customization
session[:disable_customization] = false
end
2013-02-05 14:16:51 -05:00
end