FEATURE: Admins should be able to create polls even when plugin is disabled.
This commit is contained in:
parent
467b35df14
commit
c3cab98998
|
@ -7,6 +7,7 @@ export function cook(text) {
|
|||
|
||||
const opts = {
|
||||
getURL: Discourse.getURLWithCDN,
|
||||
currentUser: Discourse.__container__.lookup('current-user:main'),
|
||||
siteSettings
|
||||
};
|
||||
|
||||
|
|
|
@ -12,7 +12,17 @@ export function registerOption(fn) {
|
|||
export function buildOptions(state) {
|
||||
setup();
|
||||
|
||||
const { siteSettings, getURL, lookupAvatar, getTopicInfo, topicId, categoryHashtagLookup } = state;
|
||||
const {
|
||||
siteSettings,
|
||||
getURL,
|
||||
lookupAvatar,
|
||||
getTopicInfo,
|
||||
topicId,
|
||||
categoryHashtagLookup,
|
||||
userId,
|
||||
getCurrentUser,
|
||||
currentUser
|
||||
} = state;
|
||||
|
||||
const features = {
|
||||
'bold-italics': true,
|
||||
|
@ -34,6 +44,9 @@ export function buildOptions(state) {
|
|||
getTopicInfo,
|
||||
topicId,
|
||||
categoryHashtagLookup,
|
||||
userId,
|
||||
getCurrentUser,
|
||||
currentUser,
|
||||
mentionLookup: state.mentionLookup,
|
||||
};
|
||||
|
||||
|
|
|
@ -197,12 +197,16 @@ class Post < ActiveRecord::Base
|
|||
if cook_method == Post.cook_methods[:email]
|
||||
cooked = EmailCook.new(raw).cook
|
||||
else
|
||||
cooked = if !self.user || SiteSetting.tl3_links_no_follow || !self.user.has_trust_level?(TrustLevel[3])
|
||||
cloned = args.dup
|
||||
cloned[1] ||= {}
|
||||
|
||||
post_user = self.user
|
||||
cloned[1][:user_id] = post_user.id if post_user
|
||||
|
||||
cooked = if !post_user || SiteSetting.tl3_links_no_follow || !post_user.has_trust_level?(TrustLevel[3])
|
||||
post_analyzer.cook(*args)
|
||||
else
|
||||
# At trust level 3, we don't apply nofollow to links
|
||||
cloned = args.dup
|
||||
cloned[1] ||= {}
|
||||
cloned[1][:omit_nofollow] = true
|
||||
post_analyzer.cook(*cloned)
|
||||
end
|
||||
|
|
|
@ -114,7 +114,7 @@ module PrettyText
|
|||
end
|
||||
end
|
||||
|
||||
def self.markdown(text, opts=nil)
|
||||
def self.markdown(text, opts={})
|
||||
# we use the exact same markdown converter as the client
|
||||
# TODO: use the same extensions on both client and server (in particular the template for mentions)
|
||||
baked = nil
|
||||
|
@ -143,7 +143,10 @@ module PrettyText
|
|||
context.eval("__optInput.topicId = #{opts[:topicId].to_i};")
|
||||
end
|
||||
|
||||
context.eval("__optInput.userId = #{opts[:user_id].to_i};") if opts[:user_id]
|
||||
|
||||
context.eval("__optInput.getURL = __getURL;")
|
||||
context.eval("__optInput.getCurrentUser = __getCurrentUser;")
|
||||
context.eval("__optInput.lookupAvatar = __lookupAvatar;")
|
||||
context.eval("__optInput.getTopicInfo = __getTopicInfo;")
|
||||
context.eval("__optInput.categoryHashtagLookup = __categoryLookup;")
|
||||
|
|
|
@ -68,6 +68,12 @@ module PrettyText
|
|||
nil
|
||||
end
|
||||
end
|
||||
|
||||
def get_current_user(user_id)
|
||||
user = User.find_by(id: user_id)
|
||||
staff = user ? user.staff? : false
|
||||
{ staff: staff }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -46,6 +46,10 @@ function __lookupAvatar(p) {
|
|||
return __utils.avatarImg({size: "tiny", avatarTemplate: __helpers.avatar_template(p) }, __getURL);
|
||||
}
|
||||
|
||||
function __getCurrentUser(userId) {
|
||||
return __helpers.get_current_user(userId);
|
||||
}
|
||||
|
||||
I18n = {
|
||||
t: function(a,b) { return __helpers.t(a,b); }
|
||||
};
|
||||
|
|
|
@ -2,6 +2,10 @@ import { withPluginApi } from 'discourse/lib/plugin-api';
|
|||
import showModal from 'discourse/lib/show-modal';
|
||||
|
||||
function initializePollUIBuilder(api) {
|
||||
const siteSettings = api.container.lookup('site-settings:main');
|
||||
|
||||
if (!siteSettings.poll_enabled && (api.getCurrentUser() && !api.getCurrentUser().staff)) return;
|
||||
|
||||
const ComposerController = api.container.lookupFactory("controller:composer");
|
||||
ComposerController.reopen({
|
||||
actions: {
|
||||
|
|
|
@ -7,7 +7,9 @@ const WHITELISTED_ATTRIBUTES = ["type", "name", "min", "max", "step", "order", "
|
|||
const ATTRIBUTES_REGEX = new RegExp("(" + WHITELISTED_ATTRIBUTES.join("|") + ")=['\"]?[^\\s\\]]+['\"]?", "g");
|
||||
|
||||
registerOption((siteSettings, opts) => {
|
||||
opts.features.poll = !!siteSettings.poll_enabled;
|
||||
const currentUser = (opts.getCurrentUser && opts.getCurrentUser(opts.userId)) || opts.currentUser;
|
||||
|
||||
opts.features.poll = !!siteSettings.poll_enabled || currentUser.staff;
|
||||
opts.pollMaximumOptions = siteSettings.poll_maximum_options;
|
||||
});
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ module DiscoursePoll
|
|||
def validate_polls
|
||||
polls = {}
|
||||
|
||||
extracted_polls = DiscoursePoll::Poll::extract(@post.raw, @post.topic_id)
|
||||
extracted_polls = DiscoursePoll::Poll::extract(@post.raw, @post.topic_id, @post.user_id)
|
||||
|
||||
extracted_polls.each do |poll|
|
||||
# polls should have a unique name
|
||||
|
|
|
@ -4,8 +4,6 @@
|
|||
# authors: Vikhyat Korrapati (vikhyat), Régis Hanol (zogstrip)
|
||||
# url: https://github.com/discourse/discourse/tree/master/plugins/poll
|
||||
|
||||
enabled_site_setting :poll_enabled
|
||||
|
||||
register_asset "stylesheets/common/poll.scss"
|
||||
register_asset "stylesheets/common/poll-ui-builder.scss"
|
||||
register_asset "stylesheets/desktop/poll.scss", :desktop
|
||||
|
@ -145,10 +143,10 @@ after_initialize do
|
|||
end
|
||||
end
|
||||
|
||||
def extract(raw, topic_id)
|
||||
def extract(raw, topic_id, user_id = nil)
|
||||
# TODO: we should fix the callback mess so that the cooked version is available
|
||||
# in the validators instead of cooking twice
|
||||
cooked = PrettyText.cook(raw, topic_id: topic_id)
|
||||
cooked = PrettyText.cook(raw, topic_id: topic_id, user_id: user_id)
|
||||
parsed = Nokogiri::HTML(cooked)
|
||||
|
||||
extracted_polls = []
|
||||
|
@ -252,6 +250,8 @@ after_initialize do
|
|||
end
|
||||
|
||||
validate(:post, :validate_polls) do
|
||||
return if !SiteSetting.poll_enabled? && (self.user && !self.user.staff?)
|
||||
|
||||
# only care when raw has changed!
|
||||
return unless self.raw_changed?
|
||||
|
||||
|
|
Loading…
Reference in New Issue