Skip to content

A platform for community discussion. Free, open, simple.

DEV: Fix boolean false params nilled on chat channel update (#38587)

Isaac Janzen3477bc5dd197
diff --git a/plugins/chat/app/controllers/chat/api/channels_controller.rb b/plugins/chat/app/controllers/chat/api/channels_controller.rb
index 9c0127d1a4a..c0930340ee2 100644
--- a/plugins/chat/app/controllers/chat/api/channels_controller.rb
+++ b/plugins/chat/app/controllers/chat/api/channels_controller.rb
@@ -108,7 +108,7 @@ class Chat::Api::ChannelsController < Chat::ApiController
def update
params_to_edit = editable_params(params, channel_from_params)
- params_to_edit.each { |k, v| params_to_edit[k] = nil if params_to_edit[k].blank? }
+ params_to_edit.each { |k, v| params_to_edit[k] = nil if v.is_a?(String) && v.blank? }
if ActiveRecord::Type::Boolean.new.deserialize(params_to_edit[:auto_join_users])
auto_join_limiter(channel_from_params).performed!
end
diff --git a/plugins/chat/spec/requests/chat/api/channels_controller_spec.rb b/plugins/chat/spec/requests/chat/api/channels_controller_spec.rb
index 4085570959b..db72623890a 100644
--- a/plugins/chat/spec/requests/chat/api/channels_controller_spec.rb
+++ b/plugins/chat/spec/requests/chat/api/channels_controller_spec.rb
@@ -603,24 +603,46 @@ RSpec.describe Chat::Api::ChannelsController do
end
describe "when updating threading_enabled" do
- it "sets the new value" do
+ it "can enable threading" do
expect {
put "/chat/api/channels/#{channel.id}", params: { channel: { threading_enabled: true } }
}.to change { channel.reload.threading_enabled }.from(false).to(true)
expect(response.parsed_body["channel"]["threading_enabled"]).to eq(true)
end
+
+ it "can disable threading" do
+ channel.update!(threading_enabled: true)
+
+ expect {
+ put "/chat/api/channels/#{channel.id}",
+ params: {
+ channel: {
+ threading_enabled: false,
+ },
+ },
+ as: :json
+ }.to change { channel.reload.threading_enabled }.from(true).to(false)
+
+ expect(response.status).to eq(200)
+ expect(response.parsed_body["channel"]["threading_enabled"]).to eq(false)
+ end
end
describe "when updating allow_channel_wide_mentions" do
- it "sets the new value" do
- put "/chat/api/channels/#{channel.id}",
- params: {
- channel: {
- allow_channel_wide_mentions: false,
- },
- }
+ it "can disable allow_channel_wide_mentions" do
+ channel.update!(allow_channel_wide_mentions: true)
+ expect {
+ put "/chat/api/channels/#{channel.id}",
+ params: {
+ channel: {
+ allow_channel_wide_mentions: false,
+ },
+ }
+ }.to change { channel.reload.allow_channel_wide_mentions }.from(true).to(false)
+
+ expect(response.status).to eq(200)
expect(response.parsed_body["channel"]["allow_channel_wide_mentions"]).to eq(false)
end
end