diff --git a/lib/read_only_mixin.rb b/lib/read_only_mixin.rb index 7775040aff4..74b88111ec3 100644 --- a/lib/read_only_mixin.rb +++ b/lib/read_only_mixin.rb @@ -38,8 +38,8 @@ module ReadOnlyMixin end def get_or_check_staff_writes_only_mode - check_readonly_mode if @readonly_mode.nil? - @readonly_mode + check_readonly_mode if @staff_writes_only_mode.nil? + @staff_writes_only_mode end def add_readonly_header diff --git a/spec/requests/application_controller_spec.rb b/spec/requests/application_controller_spec.rb index 86d34d8803c..56f414ad0cc 100644 --- a/spec/requests/application_controller_spec.rb +++ b/spec/requests/application_controller_spec.rb @@ -1332,5 +1332,27 @@ RSpec.describe ApplicationController do expect(JSON.parse(preloaded_json["visiblePlugins"])).to eq([]) end end + + describe "readonly serialization" do + it "serializes regular readonly mode correctly" do + Discourse.enable_readonly_mode(Discourse::USER_READONLY_MODE_KEY) + + get "/latest" + expect(JSON.parse(preloaded_json["isReadOnly"])).to eq(true) + expect(JSON.parse(preloaded_json["isStaffWritesOnly"])).to eq(false) + ensure + Discourse.disable_readonly_mode(Discourse::USER_READONLY_MODE_KEY) + end + + it "serializes staff readonly mode correctly" do + Discourse.enable_readonly_mode(Discourse::STAFF_WRITES_ONLY_MODE_KEY) + + get "/latest" + expect(JSON.parse(preloaded_json["isReadOnly"])).to eq(true) + expect(JSON.parse(preloaded_json["isStaffWritesOnly"])).to eq(true) + ensure + Discourse.disable_readonly_mode(Discourse::STAFF_WRITES_ONLY_MODE_KEY) + end + end end end