diff --git a/assets/javascripts/discourse/templates/connectors/topic-above-post-stream/test.hbs b/assets/javascripts/discourse/templates/connectors/topic-above-post-stream/test.hbs
new file mode 100644
index 0000000..5f177a3
--- /dev/null
+++ b/assets/javascripts/discourse/templates/connectors/topic-above-post-stream/test.hbs
@@ -0,0 +1,3 @@
+{{#if model.can_vote}}
+
hello world
+{{/if}}
\ No newline at end of file
diff --git a/plugin.rb b/plugin.rb
index f399614..6ceb79d 100755
--- a/plugin.rb
+++ b/plugin.rb
@@ -14,8 +14,41 @@ load File.expand_path('../lib/discourse_feature_voting/engine.rb', __FILE__)
after_initialize do
+ require_dependency 'topic_view_serializer'
+ class ::TopicViewSerializer
+ attributes :can_vote
- Discourse::Application.routes.append do
- mount ::DiscourseFeatureVoting::Engine, at: "/vote"
- end
+ def can_vote
+ return object.topic.category.custom_fields["enable_topic_voting"]
+ end
+ end
+
+ class ::Category
+ after_save :reset_voting_cache
+
+ protected
+ def reset_voting_cache
+ ::Guardian.reset_voting_cache
+ end
+ end
+
+ class ::Guardian
+
+ @@allowed_voting_cache = DistributedCache.new("allowed_voting")
+
+ def self.reset_voting_cache
+ @@allowed_voting_cache["allowed"] =
+ begin
+ Set.new(
+ CategoryCustomField
+ .where(name: "enable_topic_voting", value: "true")
+ .pluck(:category_id)
+ )
+ end
+ end
+ end
+
+ Discourse::Application.routes.append do
+ mount ::DiscourseFeatureVoting::Engine, at: "/vote"
+ end
end
\ No newline at end of file