mirror of
https://github.com/discourse/discourse.git
synced 2024-11-26 13:53:45 +08:00
FIX: allows polls on closed topics
This commit is contained in:
parent
e8aaa6d59e
commit
b575f97ece
|
@ -8,12 +8,12 @@ export default Ember.Controller.extend({
|
||||||
|
|
||||||
// shows the results when
|
// shows the results when
|
||||||
// - poll is closed
|
// - poll is closed
|
||||||
// - topic is archived/closed
|
// - topic is archived
|
||||||
// - user wants to see the results
|
// - 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),
|
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")
|
@computed("model", "vote", "model.voters", "model.options", "model.status")
|
||||||
poll(poll, vote) {
|
poll(poll, vote) {
|
||||||
|
@ -100,12 +100,11 @@ export default Ember.Controller.extend({
|
||||||
|
|
||||||
castVotesDisabled: Em.computed.not("canCastVotes"),
|
castVotesDisabled: Em.computed.not("canCastVotes"),
|
||||||
|
|
||||||
@computed("loading", "post.user_id", "post.topic.closed", "post.topic.archived")
|
@computed("loading", "post.user_id", "post.topic.archived")
|
||||||
canToggleStatus(loading, userId, topicClosed, topicArchived) {
|
canToggleStatus(loading, userId, topicArchived) {
|
||||||
return this.currentUser &&
|
return this.currentUser &&
|
||||||
(this.currentUser.get("id") === userId || this.currentUser.get("staff")) &&
|
(this.currentUser.get("id") === userId || this.currentUser.get("staff")) &&
|
||||||
!loading &&
|
!loading &&
|
||||||
!topicClosed &&
|
|
||||||
!topicArchived;
|
!topicArchived;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -54,8 +54,8 @@ after_initialize do
|
||||||
raise StandardError.new I18n.t("poll.post_is_deleted")
|
raise StandardError.new I18n.t("poll.post_is_deleted")
|
||||||
end
|
end
|
||||||
|
|
||||||
# topic must be open
|
# topic must not be archived
|
||||||
if post.topic.try(:closed) || post.topic.try(:archived)
|
if post.topic.try(:archived)
|
||||||
raise StandardError.new I18n.t("poll.topic_must_be_open_to_vote")
|
raise StandardError.new I18n.t("poll.topic_must_be_open_to_vote")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -107,8 +107,8 @@ after_initialize do
|
||||||
raise StandardError.new I18n.t("poll.post_is_deleted")
|
raise StandardError.new I18n.t("poll.post_is_deleted")
|
||||||
end
|
end
|
||||||
|
|
||||||
# topic must be open
|
# topic must not be archived
|
||||||
if post.topic.try(:closed) || post.topic.try(:archived)
|
if post.topic.try(:archived)
|
||||||
raise StandardError.new I18n.t("poll.topic_must_be_open_to_toggle_status")
|
raise StandardError.new I18n.t("poll.topic_must_be_open_to_toggle_status")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -41,12 +41,10 @@ describe ::DiscoursePoll::PollsController do
|
||||||
expect(json["poll"]["options"][1]["votes"]).to eq(1)
|
expect(json["poll"]["options"][1]["votes"]).to eq(1)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "ensures topic is not closed" do
|
it "works even if topic is closed" do
|
||||||
topic.update_attribute(:closed, true)
|
topic.update_attribute(:closed, true)
|
||||||
xhr :put, :vote, { post_id: poll.id, poll_name: "poll", options: ["A"] }
|
xhr :put, :vote, { post_id: poll.id, poll_name: "poll", options: ["5c24fc1df56d764b550ceae1b9319125"] }
|
||||||
expect(response).not_to be_success
|
expect(response).to be_success
|
||||||
json = ::JSON.parse(response.body)
|
|
||||||
expect(json["errors"][0]).to eq(I18n.t("poll.topic_must_be_open_to_vote"))
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it "ensures topic is not archived" do
|
it "ensures topic is not archived" do
|
||||||
|
|
Loading…
Reference in New Issue
Block a user