FIX: properly disable serializable attributes when poll plugin is disabled

FIX: properly disable serializable attributes when poll plugin is disabled

From 92100f82ebed11a3bc53f63b65408e9c92179004 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?R=C3=A9gis=20Hanol?= <regis@hanol.fr>
Date: Tue, 20 Nov 2018 17:28:41 +0100
Subject: [PATCH] FIX: properly disable serializable attributes when poll
 plugin is disabled


diff --git a/plugins/poll/plugin.rb b/plugins/poll/plugin.rb
index fd3070b..001fd7d 100644
--- a/plugins/poll/plugin.rb
+++ b/plugins/poll/plugin.rb
@@ -474,7 +474,7 @@ after_initialize do
   end
 
   add_to_serializer(:post, :include_polls?) do
-    preloaded_polls.present?
+    SiteSetting.poll_enabled && preloaded_polls.present?
   end
 
   add_to_serializer(:post, :polls_votes, false) do
@@ -490,6 +490,7 @@ after_initialize do
   end
 
   add_to_serializer(:post, :include_polls_votes?) do
+    SiteSetting.poll_enabled &&
     scope.user&.id.present? &&
     preloaded_polls.present? &&
     preloaded_polls.any? { |p| p.has_voted?(scope.user) }

GitHub

This commit has been mentioned on Discourse Meta. There might be relevant details there:

I wonder, should add_to_serializer just handle this automatically? On the :person_fencing: here but it seems less error prone.

add_to_serializer already handles it, unless you plan to define your own include_... method which I did :wink:

1 Like