From e9f9d22482579761bbcce4a6c96d966405c93dd6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20Hanol?= Date: Tue, 12 Nov 2013 18:13:17 +0100 Subject: [PATCH] add query parameter to temporarily disable customization --- .../controllers/admin_customize_controller.js | 82 ++++++++++--------- .../admin/site_customizations_controller.rb | 6 ++ app/controllers/application_controller.rb | 12 ++- app/models/site_customization.rb | 5 +- .../common/_discourse_stylesheet.html.erb | 4 +- app/views/layouts/application.html.erb | 6 +- app/views/layouts/no_js.html.erb | 29 +++---- 7 files changed, 81 insertions(+), 63 deletions(-) diff --git a/app/assets/javascripts/admin/controllers/admin_customize_controller.js b/app/assets/javascripts/admin/controllers/admin_customize_controller.js index 6e64e1c35..9155200f5 100644 --- a/app/assets/javascripts/admin/controllers/admin_customize_controller.js +++ b/app/assets/javascripts/admin/controllers/admin_customize_controller.js @@ -8,52 +8,56 @@ **/ Discourse.AdminCustomizeController = Ember.ArrayController.extend({ - /** - Create a new customization style + actions: { - @method newCustomization - **/ - newCustomization: function() { - var item = Discourse.SiteCustomization.create({name: I18n.t("admin.customize.new_style")}); - this.pushObject(item); - this.set('selectedItem', item); - }, + /** + Create a new customization style - /** - Select a given style + @method newCustomization + **/ + newCustomization: function() { + var item = Discourse.SiteCustomization.create({name: I18n.t("admin.customize.new_style")}); + this.pushObject(item); + this.set('selectedItem', item); + }, - @method selectStyle - @param {Discourse.SiteCustomization} style The style we are selecting - **/ - selectStyle: function(style) { - this.set('selectedItem', style); - }, + /** + Select a given style - /** - Save the current customization + @method selectStyle + @param {Discourse.SiteCustomization} style The style we are selecting + **/ + selectStyle: function(style) { + this.set('selectedItem', style); + }, - @method save - **/ - save: function() { - this.get('selectedItem').save(); - }, + /** + Save the current customization - /** - Destroy the current customization + @method save + **/ + save: function() { + this.get('selectedItem').save(); + }, + + /** + Destroy the current customization + + @method destroy + **/ + destroy: function() { + var _this = this; + return bootbox.confirm(I18n.t("admin.customize.delete_confirm"), I18n.t("no_value"), I18n.t("yes_value"), function(result) { + var selected; + if (result) { + selected = _this.get('selectedItem'); + selected.destroy(); + _this.set('selectedItem', null); + return _this.removeObject(selected); + } + }); + } - @method destroy - **/ - destroy: function() { - var _this = this; - return bootbox.confirm(I18n.t("admin.customize.delete_confirm"), I18n.t("no_value"), I18n.t("yes_value"), function(result) { - var selected; - if (result) { - selected = _this.get('selectedItem'); - selected.destroy(); - _this.set('selectedItem', null); - return _this.removeObject(selected); - } - }); } }); diff --git a/app/controllers/admin/site_customizations_controller.rb b/app/controllers/admin/site_customizations_controller.rb index d2595a3f1..a545a8226 100644 --- a/app/controllers/admin/site_customizations_controller.rb +++ b/app/controllers/admin/site_customizations_controller.rb @@ -1,5 +1,7 @@ class Admin::SiteCustomizationsController < Admin::AdminController + before_filter :enable_customization + def index @site_customizations = SiteCustomization.all @@ -56,4 +58,8 @@ class Admin::SiteCustomizationsController < Admin::AdminController StaffActionLogger.new(current_user).log_site_customization_change(old_record, new_params) end + def enable_customization + session[:disable_customization] = false + end + end diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 6b82abab6..b52bcfb16 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -27,6 +27,7 @@ class ApplicationController < ActionController::Base before_filter :set_mobile_view before_filter :inject_preview_style + before_filter :disable_customization before_filter :block_if_maintenance_mode before_filter :authorize_mini_profiler before_filter :store_incoming_links @@ -36,8 +37,10 @@ class ApplicationController < ActionController::Base before_filter :redirect_to_login_if_required rescue_from Exception do |exception| - unless [ ActiveRecord::RecordNotFound, ActionController::RoutingError, - ActionController::UnknownController, AbstractController::ActionNotFound].include? exception.class + unless [ActiveRecord::RecordNotFound, + ActionController::RoutingError, + ActionController::UnknownController, + AbstractController::ActionNotFound].include? exception.class begin ErrorLog.report_async!(exception, self, request, current_user) rescue @@ -121,12 +124,15 @@ class ApplicationController < ActionController::Base session[:mobile_view] = params[:mobile_view] if params.has_key?(:mobile_view) end - def inject_preview_style style = request['preview-style'] session[:preview_style] = style if style end + def disable_customization + session[:disable_customization] = params[:customization] == "0" if params.has_key?(:customization) + end + def guardian @guardian ||= Guardian.new(current_user) end diff --git a/app/models/site_customization.rb b/app/models/site_customization.rb index a11cb1da7..f46ea5e59 100644 --- a/app/models/site_customization.rb +++ b/app/models/site_customization.rb @@ -22,9 +22,8 @@ class SiteCustomization < ActiveRecord::Base error.gsub!("'", '\27 ') self.send("#{stylesheet_attr}_baked=", - "#main {display: none;} - footer {white-space: pre; margin-left: 100px;} - footer:after{ content: '#{error}' }") + "footer { white-space: pre; } + footer:after { content: '#{error}' }") end end end diff --git a/app/views/common/_discourse_stylesheet.html.erb b/app/views/common/_discourse_stylesheet.html.erb index 460ef7a24..6c4d0df76 100644 --- a/app/views/common/_discourse_stylesheet.html.erb +++ b/app/views/common/_discourse_stylesheet.html.erb @@ -10,4 +10,6 @@ <%= stylesheet_link_tag "admin"%> <%-end%> -<%= SiteCustomization.custom_stylesheet(session[:preview_style], mobile_view? ? :mobile : :desktop) %> +<%- unless session[:disable_customization] %> + <%= SiteCustomization.custom_stylesheet(session[:preview_style], mobile_view? ? :mobile : :desktop) %> +<%- end %> diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 0ef90532c..c9379ec16 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -31,7 +31,10 @@ - <%= SiteCustomization.custom_header(session[:preview_style], mobile_view? ? :mobile : :desktop) %> + <%- unless session[:disable_customization] %> + <%= SiteCustomization.custom_header(session[:preview_style], mobile_view? ? :mobile : :desktop) %> + <%- end %> +
@@ -57,6 +60,7 @@ <%= render :partial => "common/discourse_javascript" %> + <%= render_google_analytics_code %>