From e845138bc1bc17e0de08987ed891dae71d51a93f Mon Sep 17 00:00:00 2001 From: Daniel Waterworth Date: Fri, 10 Nov 2023 14:27:43 -0600 Subject: [PATCH] FIX: Updating presence status in readonly mode should fail gracefully (#24333) --- .rubocop.yml | 12 ++++++++++++ app/controllers/presence_controller.rb | 2 ++ spec/requests/presence_controller_spec.rb | 19 +++++++++++++++++++ 3 files changed, 33 insertions(+) diff --git a/.rubocop.yml b/.rubocop.yml index 68abba36ad9..b2ca15ef254 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -11,3 +11,15 @@ Discourse/NoResetColumnInformationInMigrations: Lint/Debugger: Exclude: - script/**/* + +RSpec/ContextWording: + Prefixes: + - when + - with + - without + - for + - while + - if + - as + - after + - in diff --git a/app/controllers/presence_controller.rb b/app/controllers/presence_controller.rb index ad68f801c94..102edcebf3a 100644 --- a/app/controllers/presence_controller.rb +++ b/app/controllers/presence_controller.rb @@ -42,6 +42,8 @@ class PresenceController < ApplicationController end def update + raise Discourse::ReadOnly if @readonly_mode + client_id = params[:client_id] if !client_id.is_a?(String) || client_id.blank? raise Discourse::InvalidParameters.new(:client_id) diff --git a/spec/requests/presence_controller_spec.rb b/spec/requests/presence_controller_spec.rb index 7b56bb64234..c1ae8784ee8 100644 --- a/spec/requests/presence_controller_spec.rb +++ b/spec/requests/presence_controller_spec.rb @@ -44,6 +44,25 @@ RSpec.describe PresenceController do end describe "#update" do + context "in readonly mode" do + use_redis_snapshotting + + before { Discourse.enable_readonly_mode } + + it "produces 503" do + sign_in(user) + client_id = SecureRandom.hex + + post "/presence/update.json", + params: { + client_id: client_id, + present_channels: [ch1.name, ch2.name], + } + + expect(response.status).to eq(503) + end + end + it "works" do sign_in(user) client_id = SecureRandom.hex