mirror of
https://github.com/discourse/discourse.git
synced 2025-01-18 17:52:45 +08:00
FEATURE: new 'poll_maximum_options' site setting to limit the number of options in a poll
This commit is contained in:
parent
f83638c154
commit
2954c99a1e
|
@ -8,6 +8,7 @@
|
|||
en:
|
||||
site_settings:
|
||||
poll_enabled: "Allow users to create polls?"
|
||||
poll_maximum_options: "Maximum number of options allowed in a poll."
|
||||
|
||||
poll:
|
||||
multiple_polls_without_name: "There are multiple polls without a name. Use the '<code>name</code>' attribute to uniquely identify your polls."
|
||||
|
@ -16,8 +17,11 @@ en:
|
|||
default_poll_must_have_at_least_2_options: "Poll must have at least 2 options."
|
||||
named_poll_must_have_at_least_2_options: "Poll named <strong>%{name}</strong> must have at least 2 options."
|
||||
|
||||
default_poll_must_have_less_options: "Poll must have less than %{max} options."
|
||||
named_poll_must_have_less_options: "Poll named <strong>%{name}</strong> must have less than %{max} options."
|
||||
|
||||
default_poll_must_have_different_options: "Poll must have different options."
|
||||
named_poll_must_have_different_options: "Poll name <strong>%{name}</strong> must have different options."
|
||||
named_poll_must_have_different_options: "Poll named <strong>%{name}</strong> must have different options."
|
||||
|
||||
requires_at_least_1_valid_option: "You must select at least 1 valid option."
|
||||
cannot_change_polls_after_5_minutes: "Polls cannot be changed after the first 5 minutes. Contact a moderator if you need to change them."
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
plugins:
|
||||
poll_enabled:
|
||||
default: true
|
||||
poll_maximum_options:
|
||||
default: 10
|
||||
|
|
|
@ -231,6 +231,14 @@ after_initialize do
|
|||
return
|
||||
end
|
||||
|
||||
# maximum # of options
|
||||
if poll["options"].size > SiteSetting.poll_maximum_options
|
||||
poll["name"] == DEFAULT_POLL_NAME ?
|
||||
self.errors.add(:base, I18n.t("poll.default_poll_must_have_less_options", max: SiteSetting.poll_maximum_options)) :
|
||||
self.errors.add(:base, I18n.t("poll.named_poll_must_have_less_options", name: poll["name"], max: SiteSetting.poll_maximum_options))
|
||||
return
|
||||
end
|
||||
|
||||
# store the valid poll
|
||||
polls[poll["name"]] = poll
|
||||
end
|
||||
|
|
|
@ -37,6 +37,18 @@ describe PostsController do
|
|||
expect(json["errors"][0]).to eq(I18n.t("poll.default_poll_must_have_at_least_2_options"))
|
||||
end
|
||||
|
||||
it "should have at most 'SiteSetting.poll_maximum_options' options" do
|
||||
raw = "[poll]"
|
||||
(SiteSetting.poll_maximum_options + 1).times { |n| raw << "\n- #{n}" }
|
||||
raw << "[/poll]"
|
||||
|
||||
xhr :post, :create, { title: title, raw: raw }
|
||||
|
||||
expect(response).not_to be_success
|
||||
json = ::JSON.parse(response.body)
|
||||
expect(json["errors"][0]).to eq(I18n.t("poll.default_poll_must_have_less_options", max: SiteSetting.poll_maximum_options))
|
||||
end
|
||||
|
||||
describe "edit window" do
|
||||
|
||||
describe "within the first 5 minutes" do
|
||||
|
|
Loading…
Reference in New Issue
Block a user