mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
readonly mode
This commit is contained in:
@@ -8,8 +8,9 @@ Discourse.addInitializer(function() {
|
||||
|
||||
Discourse.MessageBus.alwaysLongPoll = Discourse.Environment === "development";
|
||||
Discourse.MessageBus.start();
|
||||
|
||||
Discourse.MessageBus.subscribe("/global/asset-version", function(version){
|
||||
Discourse.set("assetVersion",version);
|
||||
Discourse.set("assetVersion", version);
|
||||
|
||||
if(Discourse.get("requiresRefresh")) {
|
||||
// since we can do this transparently for people browsing the forum
|
||||
@@ -24,5 +25,15 @@ Discourse.addInitializer(function() {
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
Discourse.set("isReadOnly", Discourse.Site.currentProp("is_readonly"));
|
||||
|
||||
Discourse.MessageBus.subscribe("/global/read-only", function (enabled) {
|
||||
Discourse.set("isReadOnly", enabled);
|
||||
if (enabled) {
|
||||
bootbox.alert(I18n.t("read_only_mode_enabled"));
|
||||
}
|
||||
});
|
||||
|
||||
Discourse.KeyValueStore.init("discourse_", Discourse.MessageBus);
|
||||
}, true);
|
||||
|
||||
@@ -29,7 +29,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 :block_if_readonly_mode
|
||||
before_filter :authorize_mini_profiler
|
||||
before_filter :store_incoming_links
|
||||
before_filter :preload_json
|
||||
@@ -50,7 +50,6 @@ class ApplicationController < ActionController::Base
|
||||
raise
|
||||
end
|
||||
|
||||
|
||||
# Some exceptions
|
||||
class RenderEmpty < Exception; end
|
||||
|
||||
@@ -87,6 +86,11 @@ class ApplicationController < ActionController::Base
|
||||
rescue_discourse_actions("[error: 'invalid access']", 403) # TODO: this breaks json responses
|
||||
end
|
||||
|
||||
rescue_from Discourse::ReadOnly do
|
||||
# can this happen on a not .json format?
|
||||
render json: failed_json.merge(message: I18n.t("read_only_mode_enabled"))
|
||||
end
|
||||
|
||||
def rescue_discourse_actions(message, error)
|
||||
if request.format && request.format.json?
|
||||
# TODO: this doesn't make sense. Stuffing an html page into a json response will cause
|
||||
@@ -249,16 +253,6 @@ class ApplicationController < ActionController::Base
|
||||
end
|
||||
end
|
||||
|
||||
def block_if_maintenance_mode
|
||||
if Discourse.maintenance_mode?
|
||||
if request.format.json?
|
||||
render status: 503, json: failed_json.merge(message: I18n.t('site_under_maintenance'))
|
||||
else
|
||||
render status: 503, file: File.join( Rails.root, 'public', '503.html' ), layout: false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def mini_profiler_enabled?
|
||||
defined?(Rack::MiniProfiler) && current_user.try(:admin?)
|
||||
end
|
||||
@@ -288,6 +282,11 @@ class ApplicationController < ActionController::Base
|
||||
redirect_to :login if SiteSetting.login_required?
|
||||
end
|
||||
|
||||
def block_if_readonly_mode
|
||||
return if request.put? && request.fullpath == "/admin/backups/readonly"
|
||||
raise Discourse::ReadOnly.new unless request.get? || !Discourse.readonly_mode?
|
||||
end
|
||||
|
||||
def build_not_found_page(status=404, layout=false)
|
||||
@top_viewed = Topic.top_viewed(10)
|
||||
@recent = Topic.recent(10)
|
||||
|
||||
@@ -8,7 +8,8 @@ class SiteSerializer < ApplicationSerializer
|
||||
:periods,
|
||||
:top_menu_items,
|
||||
:anonymous_top_menu_items,
|
||||
:uncategorized_category_id # this is hidden so putting it here
|
||||
:uncategorized_category_id, # this is hidden so putting it here
|
||||
:is_readonly
|
||||
|
||||
has_many :categories, serializer: BasicCategorySerializer, embed: :objects
|
||||
has_many :post_action_types, embed: :objects
|
||||
@@ -45,4 +46,8 @@ class SiteSerializer < ApplicationSerializer
|
||||
SiteSetting.uncategorized_category_id
|
||||
end
|
||||
|
||||
def is_readonly
|
||||
Discourse.readonly_mode?
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user