FIX: Serialization of staff_writes_only (#26866)

This commit is contained in:
David Taylor 2024-05-03 19:36:13 +01:00 committed by GitHub
parent 6c6a56139e
commit f230767722
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 24 additions and 2 deletions

View File

@ -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

View File

@ -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