FIX: allows polls on closed topics

This commit is contained in:
Régis Hanol 2016-03-21 12:12:25 +01:00
parent e8aaa6d59e
commit b575f97ece
3 changed files with 12 additions and 15 deletions

View File

@ -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;
},

View File

@ -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

View File

@ -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