mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FIX: 🈂️ Allow closing polls in multi-locale sites
This commit is contained in:
@@ -9,7 +9,7 @@ Allows you to add a poll to the first post of a topic.
|
||||
|
||||
## Closing the poll
|
||||
|
||||
Change the start of the topic title from "Poll: " to "Closed Poll: ". This feature is disabled if the `allow_user_locale` site setting is enabled.
|
||||
Change the start of the topic title from "Poll: " to "Closed Poll: ". This feature uses the locale of the user who started the topic.
|
||||
|
||||
_Note: closing a topic will also close the poll._
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ export default DiscourseController.extend({
|
||||
showResults: Em.computed.oneWay('poll.closed'),
|
||||
disableRadio: Em.computed.any('poll.closed', 'loading'),
|
||||
showToggleClosePoll: function() {
|
||||
return this.get('poll.post.topic.details.can_edit') && !Discourse.SiteSettings.allow_user_locale;
|
||||
return this.get('poll.post.topic.details.can_edit');
|
||||
}.property('poll.post.topic.details.can_edit'),
|
||||
|
||||
actions: {
|
||||
|
||||
@@ -80,10 +80,12 @@ after_initialize do
|
||||
end
|
||||
|
||||
# Modify topic title.
|
||||
if topic.title =~ /^(#{I18n.t('poll.prefix').strip})\s?:/i
|
||||
topic.title = topic.title.gsub(/^(#{I18n.t('poll.prefix').strip})\s?:/i, I18n.t('poll.closed_prefix') + ':')
|
||||
elsif topic.title =~ /^(#{I18n.t('poll.closed_prefix').strip})\s?:/i
|
||||
topic.title = topic.title.gsub(/^(#{I18n.t('poll.closed_prefix').strip})\s?:/i, I18n.t('poll.prefix') + ':')
|
||||
I18n.with_locale(topic.user.effective_locale) do
|
||||
if topic.title =~ /^(#{I18n.t('poll.prefix').strip})\s?:/i
|
||||
topic.title = topic.title.gsub(/^(#{I18n.t('poll.prefix').strip})\s?:/i, I18n.t('poll.closed_prefix') + ':')
|
||||
elsif topic.title =~ /^(#{I18n.t('poll.closed_prefix').strip})\s?:/i
|
||||
topic.title = topic.title.gsub(/^(#{I18n.t('poll.closed_prefix').strip})\s?:/i, I18n.t('poll.prefix') + ':')
|
||||
end
|
||||
end
|
||||
|
||||
topic.acting_user = current_user
|
||||
|
||||
@@ -21,19 +21,13 @@ module ::PollPlugin
|
||||
return false
|
||||
end
|
||||
|
||||
topic.title =~ /^(#{I18n.t('poll.prefix').strip}|#{I18n.t('poll.closed_prefix').strip})\s?:/i
|
||||
I18n.with_locale(topic.user.effective_locale) do
|
||||
topic.title =~ /^(#{I18n.t('poll.prefix').strip}|#{I18n.t('poll.closed_prefix').strip})\s?:/i
|
||||
end
|
||||
end
|
||||
|
||||
def has_poll_details?
|
||||
if SiteSetting.allow_user_locale?
|
||||
# If we allow users to select their locale of choice we cannot detect polls
|
||||
# by the prefix, so we fall back to checking if the poll details is set in
|
||||
# places to make sure polls are still accessible by users using a different
|
||||
# locale than the one used by the topic creator.
|
||||
not self.details.nil?
|
||||
else
|
||||
self.is_poll?
|
||||
end
|
||||
self.is_poll?
|
||||
end
|
||||
|
||||
# Called during validation of poll posts. Discourse already restricts edits to
|
||||
@@ -60,7 +54,8 @@ module ::PollPlugin
|
||||
end
|
||||
|
||||
def is_closed?
|
||||
@post.topic.closed? || @post.topic.archived? || (!SiteSetting.allow_user_locale? && (@post.topic.title =~ /^#{I18n.t('poll.closed_prefix')}/i) === 0)
|
||||
topic = @post.topic
|
||||
topic.closed? || topic.archived? || (topic.title =~ /^#{I18n.t('poll.closed_prefix', locale: topic.user.effective_locale)}/i) === 0
|
||||
end
|
||||
|
||||
def options
|
||||
|
||||
Reference in New Issue
Block a user