From 5ff7dfbac67642adaf5a81ac3b419a3a434f98b7 Mon Sep 17 00:00:00 2001 From: "Matt K. Fu" Date: Tue, 23 Apr 2013 18:48:18 +0800 Subject: [PATCH] fronted open switch and backend openness --- app/controllers/admin/dashboards_controller.rb | 5 +++-- app/controllers/admin/sites_controller.rb | 1 + app/controllers/application_controller.rb | 8 ++++++++ app/controllers/orbit_backend_controller.rb | 1 + app/controllers/pages_controller.rb | 7 +++++++ app/jobs/restart_server.rb | 8 ++++++++ app/models/site.rb | 4 ++++ app/views/admin/sites/site_info.html.erb | 8 ++++++++ app/views/layouts/_guest_orbit_menu.erb | 11 +++++++---- app/views/layouts/_orbit_bar.html.erb | 2 +- config/application.rb | 4 +--- config/environment.rb | 1 + config/locales/en.yml | 3 +++ config/locales/zh_tw.yml | 3 +++ 14 files changed, 56 insertions(+), 10 deletions(-) create mode 100644 app/jobs/restart_server.rb diff --git a/app/controllers/admin/dashboards_controller.rb b/app/controllers/admin/dashboards_controller.rb index 756c41b5..29d2459d 100644 --- a/app/controllers/admin/dashboards_controller.rb +++ b/app/controllers/admin/dashboards_controller.rb @@ -5,8 +5,9 @@ class Admin::DashboardsController < OrbitBackendController # before_filter :is_admin? def index - @module_app_contents, @module_app_contents_total = get_module_app_count('bulletin', 'page_context', 'web_link') - @recent_updated = get_recently_updated('bulletin', 'page_context', 'web_link') + check_backend_openness + @module_app_contents, @module_app_contents_total = get_module_app_count('bulletin', 'page_context', 'web_link') + @recent_updated = get_recently_updated('bulletin', 'page_context', 'web_link') @most_visited = get_most_visited('bulletin', 'page_context') end diff --git a/app/controllers/admin/sites_controller.rb b/app/controllers/admin/sites_controller.rb index 33f9582f..e9e581a9 100644 --- a/app/controllers/admin/sites_controller.rb +++ b/app/controllers/admin/sites_controller.rb @@ -16,6 +16,7 @@ class Admin::SitesController < OrbitBackendController def update @site.update_attributes(params[:site]) + site_restart redirect_to :back end diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 7bcd90e0..70e565c2 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -17,7 +17,15 @@ class ApplicationController < ActionController::Base helper_attr :site_valid_locales + def check_backend_openness + if !Me.backend_openness_on + redirect_to '/users/sign_in' if not (authenticate_user! and is_member? ) + end + end + def site_restart + Resque.enqueue(RestartServer) + end def set_current_user User.current = current_or_guest_user diff --git a/app/controllers/orbit_backend_controller.rb b/app/controllers/orbit_backend_controller.rb index 7c25e6fc..b9ede03e 100644 --- a/app/controllers/orbit_backend_controller.rb +++ b/app/controllers/orbit_backend_controller.rb @@ -15,6 +15,7 @@ class OrbitBackendController < ApplicationController private def force_order_for_visitor + check_backend_openness setup_vars set_current_user end diff --git a/app/controllers/pages_controller.rb b/app/controllers/pages_controller.rb index 058b1843..f9bb0c3f 100644 --- a/app/controllers/pages_controller.rb +++ b/app/controllers/pages_controller.rb @@ -1,8 +1,15 @@ class PagesController < ApplicationController include ApplicationHelper before_filter :get_item, :only => [:index_from_link, :show_from_link] + before_filter :check_frontend_open, :only => [:index,:show] # caches_page :index + def check_frontend_open + if Me.frontend_closed + redirect_to '/admin/dashboards' + end + end + def index @item = Page.find_by_name('home') diff --git a/app/jobs/restart_server.rb b/app/jobs/restart_server.rb new file mode 100644 index 00000000..3ed5d072 --- /dev/null +++ b/app/jobs/restart_server.rb @@ -0,0 +1,8 @@ +class RestartServer + @queue = :high + + def self.perform() + temp_directory = "#{Rails.root}/tmp/" + %x[touch #{temp_directory}restart.txt ] + end +end diff --git a/app/models/site.rb b/app/models/site.rb index e2b2f8ed..c4df3fc3 100644 --- a/app/models/site.rb +++ b/app/models/site.rb @@ -11,6 +11,10 @@ class Site field :roaming_id field :private_key, :type => Binary field :public_key, :type => Binary + + field :frontend_closed, :type => Boolean, :default => false + field :backend_openness_on, :type => Boolean, :default => false + field :title_always_on, :type => Boolean, :default => false field :dashbroad_allow_visitor, :type => Boolean, :default => false field :mail_settings, :type => Hash diff --git a/app/views/admin/sites/site_info.html.erb b/app/views/admin/sites/site_info.html.erb index 56ac6adf..f8bd7efb 100644 --- a/app/views/admin/sites/site_info.html.erb +++ b/app/views/admin/sites/site_info.html.erb @@ -35,6 +35,14 @@ <% end %> <% end %> +
+ +
+ <%= f.check_box :frontend_closed %><%= I18n.t('site.frontend_closed') %>
+ <%= f.check_box :backend_openness_on %><%= I18n.t('site.backend_openness_on') %> +

<%= (t 'site.search_help').html_safe %>

+
+
diff --git a/app/views/layouts/_guest_orbit_menu.erb b/app/views/layouts/_guest_orbit_menu.erb index a1b12368..d4574235 100644 --- a/app/views/layouts/_guest_orbit_menu.erb +++ b/app/views/layouts/_guest_orbit_menu.erb @@ -1,5 +1,8 @@ Orbit - \ No newline at end of file + <% if Me.backend_openness_on %> + + <% end %> + \ No newline at end of file diff --git a/app/views/layouts/_orbit_bar.html.erb b/app/views/layouts/_orbit_bar.html.erb index 7d20daf1..c81aeb59 100644 --- a/app/views/layouts/_orbit_bar.html.erb +++ b/app/views/layouts/_orbit_bar.html.erb @@ -38,7 +38,7 @@