2
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2025-09-06 10:50:21 +08:00

- FEATURE: revamped poll plugin

- add User.staff scope
- inject MessageBus into Ember views (so it can be used by the poll plugin)
- REFACTOR: use more accurate is_first_post? method instead of post_number == 1
- FEATURE: add support for JSON-typed custom fields
- FEATURE: allow plugins to add validation
- FEATURE: add post_custom_fields to PostSerializer
- FEATURE: allow plugins to whitelist post_custom_fields
- FIX: don't bump when post did not save successfully
- FEATURE: polls are supported in any post
- FEATURE: allow for multiple polls in the same post
- FEATURE: multiple choice polls
- FEATURE: rating polls
- FEATURE: new dialect allowing users to preview polls in the composer
This commit is contained in:
Régis Hanol 2015-04-23 19:33:29 +02:00
parent 17dc8b8e4f
commit a737090442
89 changed files with 1334 additions and 1569 deletions

View file

@ -45,29 +45,33 @@ class Plugin::Instance
end
def enabled?
return @enabled_site_setting ? SiteSetting.send(@enabled_site_setting) : true
@enabled_site_setting ? SiteSetting.send(@enabled_site_setting) : true
end
delegate :name, to: :metadata
def add_to_serializer(serializer, attr, &block)
def add_to_serializer(serializer, attr, define_include_method=true, &block)
klass = "#{serializer.to_s.classify}Serializer".constantize
klass.attributes(attr)
klass.attributes(attr) unless attr.to_s.start_with?("include_")
klass.send(:define_method, attr, &block)
return unless define_include_method
# Don't include serialized methods if the plugin is disabled
plugin = self
klass.send(:define_method, "include_#{attr}?") do
plugin.enabled?
end
klass.send(:define_method, "include_#{attr}?") { plugin.enabled? }
end
# Extend a class but check that the plugin is enabled
def add_to_class(klass, attr, &block)
klass = klass.to_s.classify.constantize
hidden_method_name = "#{attr}_without_enable_check".to_sym
klass.send(:define_method, hidden_method_name, &block)
hidden_method_name = :"#{attr}_without_enable_check"
klass.send(:define_method, hidden_method_name) do |*args|
block.call(*args)
end
plugin = self
klass.send(:define_method, attr) do |*args|
@ -75,6 +79,15 @@ class Plugin::Instance
end
end
# Add validation method but check that the plugin is enabled
def validate(klass, attr, &block)
klass = klass.to_s.classify.constantize
klass.send(:define_method, attr, &block)
plugin = self
klass.validate(attr, if: -> { plugin.enabled? })
end
# will make sure all the assets this plugin needs are registered
def generate_automatic_assets!
paths = []