diff --git a/plugins/poll/assets/javascripts/controllers/poll.js.es6 b/plugins/poll/assets/javascripts/controllers/poll.js.es6 index 576bf7433c0..dc5e549a39a 100644 --- a/plugins/poll/assets/javascripts/controllers/poll.js.es6 +++ b/plugins/poll/assets/javascripts/controllers/poll.js.es6 @@ -8,12 +8,12 @@ export default Ember.Controller.extend({ // shows the results when // - poll is closed - // - topic is archived/closed + // - topic is archived // - user wants to see the results - showingResults: Em.computed.or("isClosed", "post.topic.closed", "post.topic.archived", "showResults"), + showingResults: Em.computed.or("isClosed", "post.topic.archived", "showResults"), showResultsDisabled: Em.computed.equal("poll.voters", 0), - hideResultsDisabled: Em.computed.or("isClosed", "post.topic.closed", "post.topic.archived"), + hideResultsDisabled: Em.computed.or("isClosed", "post.topic.archived"), @computed("model", "vote", "model.voters", "model.options", "model.status") poll(poll, vote) { @@ -100,12 +100,11 @@ export default Ember.Controller.extend({ castVotesDisabled: Em.computed.not("canCastVotes"), - @computed("loading", "post.user_id", "post.topic.closed", "post.topic.archived") - canToggleStatus(loading, userId, topicClosed, topicArchived) { + @computed("loading", "post.user_id", "post.topic.archived") + canToggleStatus(loading, userId, topicArchived) { return this.currentUser && (this.currentUser.get("id") === userId || this.currentUser.get("staff")) && !loading && - !topicClosed && !topicArchived; }, diff --git a/plugins/poll/plugin.rb b/plugins/poll/plugin.rb index 45fb14e630f..ce251f91a25 100644 --- a/plugins/poll/plugin.rb +++ b/plugins/poll/plugin.rb @@ -54,8 +54,8 @@ after_initialize do raise StandardError.new I18n.t("poll.post_is_deleted") end - # topic must be open - if post.topic.try(:closed) || post.topic.try(:archived) + # topic must not be archived + if post.topic.try(:archived) raise StandardError.new I18n.t("poll.topic_must_be_open_to_vote") end @@ -107,8 +107,8 @@ after_initialize do raise StandardError.new I18n.t("poll.post_is_deleted") end - # topic must be open - if post.topic.try(:closed) || post.topic.try(:archived) + # topic must not be archived + if post.topic.try(:archived) raise StandardError.new I18n.t("poll.topic_must_be_open_to_toggle_status") end diff --git a/plugins/poll/spec/controllers/polls_controller_spec.rb b/plugins/poll/spec/controllers/polls_controller_spec.rb index bb45816f0db..b1679d7d6ee 100644 --- a/plugins/poll/spec/controllers/polls_controller_spec.rb +++ b/plugins/poll/spec/controllers/polls_controller_spec.rb @@ -41,12 +41,10 @@ describe ::DiscoursePoll::PollsController do expect(json["poll"]["options"][1]["votes"]).to eq(1) end - it "ensures topic is not closed" do + it "works even if topic is closed" do topic.update_attribute(:closed, true) - xhr :put, :vote, { post_id: poll.id, poll_name: "poll", options: ["A"] } - expect(response).not_to be_success - json = ::JSON.parse(response.body) - expect(json["errors"][0]).to eq(I18n.t("poll.topic_must_be_open_to_vote")) + xhr :put, :vote, { post_id: poll.id, poll_name: "poll", options: ["5c24fc1df56d764b550ceae1b9319125"] } + expect(response).to be_success end it "ensures topic is not archived" do