Skip to content

A platform for community discussion. Free, open, simple.

SECURITY: Respect hidden-post visibility for polls (#45169)

Isaac Janzen9a600a9cc634
diff --git a/plugins/poll/app/controllers/discourse_poll/polls_controller.rb b/plugins/poll/app/controllers/discourse_poll/polls_controller.rb
index a462c4fb683..f41034053ca 100644
--- a/plugins/poll/app/controllers/discourse_poll/polls_controller.rb
+++ b/plugins/poll/app/controllers/discourse_poll/polls_controller.rb
@@ -5,6 +5,7 @@ class DiscoursePoll::PollsController < ::ApplicationController
before_action :ensure_logged_in, except: %i[voters grouped_poll_results]
before_action :ensure_can_see_post
+ before_action :rate_limit_poll_mutations, only: %i[vote remove_vote toggle_status]
def vote
post_id = params.require(:post_id)
@@ -96,6 +97,10 @@ class DiscoursePoll::PollsController < ::ApplicationController
private
+ def rate_limit_poll_mutations
+ RateLimiter.new(current_user, "poll-mutations", 20, 1.minute).performed!
+ end
+
def ensure_can_see_post
post = Post.find_by(id: params.require(:post_id))
return if !post || !guardian.can_see_topic?(post.topic)
diff --git a/plugins/poll/assets/javascripts/discourse/initializers/extend-for-poll.gjs b/plugins/poll/assets/javascripts/discourse/initializers/extend-for-poll.gjs
index 87c1fa54726..6cf2a1971c8 100644
--- a/plugins/poll/assets/javascripts/discourse/initializers/extend-for-poll.gjs
+++ b/plugins/poll/assets/javascripts/discourse/initializers/extend-for-poll.gjs
@@ -1,5 +1,6 @@
import EmberObject from "@ember/object";
import { trackedObject } from "@ember/reactive/collections";
+import { ajax } from "discourse/lib/ajax";
import { bind } from "discourse/lib/decorators";
import { withPluginApi } from "discourse/lib/plugin-api";
import { PIE_CHART_TYPE } from "../components/modal/poll-ui-builder.gjs";
@@ -78,10 +79,38 @@ function initializePolls(api) {
}
@bind
- _onPollMessage(msg) {
- const post = this.get("model.postStream").findLoadedPost(msg.post_id);
- if (post) {
- post.polls = msg.polls;
+ async _onPollMessage(msg) {
+ const postStream = this.get("model.postStream");
+ const post = postStream.findLoadedPost(msg.post_id);
+ if (!post) {
+ return;
+ }
+
+ const refreshes = (this._pollRefreshes ||= new WeakMap());
+ if (refreshes.has(post)) {
+ refreshes.set(post, true);
+ return;
+ }
+
+ try {
+ do {
+ refreshes.set(post, false);
+ // Fetch with current permissions instead of trusting retained content.
+ const refreshed = await ajax(`/posts/${post.id}.json`);
+ if (
+ this.isDestroying ||
+ this.isDestroyed ||
+ this.get("model.postStream") !== postStream ||
+ postStream.findLoadedPost(post.id) !== post
+ ) {
+ return;
+ }
+ post.polls = refreshed.polls || [];
+ } while (refreshes.get(post));
+ } catch {
+ // The post may have been hidden, deleted, or made inaccessible.
+ } finally {
+ refreshes.delete(post);
}
}
}
diff --git a/plugins/poll/lib/poll.rb b/plugins/poll/lib/poll.rb
index 093f856ebb9..6b12b8d9740 100644
--- a/plugins/poll/lib/poll.rb
+++ b/plugins/poll/lib/poll.rb
@@ -217,13 +217,7 @@ class DiscoursePoll::Poll
serialized_poll = PollSerializer.new(poll, root: false, scope: guardian).as_json
- # This payload is broadcast to every subscriber on the topic channel, so
- # we only broadcast public data by serializing it as an anonymous user.
- payload = {
- post_id:,
- polls: [PollSerializer.new(poll, root: false, scope: Guardian.new).as_json],
- }
- post.publish_message!("/polls/#{post.topic_id}", payload)
+ post.publish_poll_message!
serialized_poll
end
@@ -555,13 +549,7 @@ class DiscoursePoll::Poll
serialized_poll = PollSerializer.new(poll, root: false, scope: guardian).as_json
- # This payload is broadcast to every subscriber on the topic channel, so
- # we only broadcast public data by serializing it as an anonymous user.
- payload = {
- post_id:,
- polls: [PollSerializer.new(poll, root: false, scope: Guardian.new).as_json],
- }
- post.publish_message!("/polls/#{post.topic_id}", payload)
+ post.publish_poll_message!
serialized_poll
end
diff --git a/plugins/poll/lib/polls_updater.rb b/plugins/poll/lib/polls_updater.rb
index b8810aa280c..dcf079d72f7 100644
--- a/plugins/poll/lib/polls_updater.rb
+++ b/plugins/poll/lib/polls_updater.rb
@@ -174,15 +174,7 @@ module DiscoursePoll
end
def self.publish_changes(post)
- polls = ::Poll.includes(:closed_by, poll_options: :poll_votes).where(post: post)
- polls =
- ActiveModel::ArraySerializer.new(
- polls,
- each_serializer: PollSerializer,
- root: false,
- scope: Guardian.new(nil),
- ).as_json
- post.publish_message!("/polls/#{post.topic_id}", post_id: post.id, polls: polls)
+ post.publish_poll_message!
end
def self.is_different?(old_poll, new_poll, new_options)
diff --git a/plugins/poll/lib/post_extension.rb b/plugins/poll/lib/post_extension.rb
index 4ae89821b04..91f4efa805b 100644
--- a/plugins/poll/lib/post_extension.rb
+++ b/plugins/poll/lib/post_extension.rb
@@ -4,6 +4,14 @@ module DiscoursePoll
module PostExtension
extend ActiveSupport::Concern
+ def publish_poll_message!
+ # Topic access alone does not grant access to a hidden post's poll content.
+ return if hidden?
+
+ # Retained messages must not contain content whose visibility can change.
+ DB.after_commit { publish_message!("/polls/#{topic_id}", post_id: id) }
+ end
+
prepended do
attr_accessor :extracted_polls
diff --git a/plugins/poll/plugin.rb b/plugins/poll/plugin.rb
index 53c305c8e7f..22bd359fb98 100644
--- a/plugins/poll/plugin.rb
+++ b/plugins/poll/plugin.rb
@@ -125,21 +125,18 @@ after_initialize do
doc.css("div.poll").each { |poll| poll.replace(replacement) }
end
- on(:post_created) do |post, _opts, user|
- guardian = Guardian.new(user)
+ # Drop content-bearing messages retained before invalidation-only broadcasts.
+ MessageBus.register_client_message_filter("/polls/") do |message|
+ message.data.keys.map(&:to_s) == ["post_id"]
+ end
+
+ on(:post_created) do |post, _opts, _user|
DiscoursePoll::Poll.schedule_jobs(post)
next if post.is_first_post?
next if post.custom_fields[DiscoursePoll::HAS_POLLS].blank?
- polls =
- ActiveModel::ArraySerializer.new(
- post.polls,
- each_serializer: PollSerializer,
- root: false,
- scope: guardian,
- ).as_json
- post.publish_message!("/polls/#{post.topic_id}", post_id: post.id, polls: polls)
+ post.publish_poll_message!
end
on(:post_moved) do |new_post, _original_topic_id, old_post|
@@ -216,15 +213,21 @@ after_initialize do
end
end
- add_to_serializer(:post, :polls, include_condition: -> { preloaded_polls.present? }) do
- preloaded_polls.map { |p| PollSerializer.new(p, root: false, scope: scope) }
+ add_to_class(PostSerializer, :can_see_post_polls?) do
+ !object.hidden? || scope.can_see_hidden_post?(object)
end
+ add_to_serializer(
+ :post,
+ :polls,
+ include_condition: -> { preloaded_polls.present? && can_see_post_polls? },
+ ) { preloaded_polls.map { |p| PollSerializer.new(p, root: false, scope: scope) } }
+
add_to_serializer(
:post,
:polls_votes,
include_condition: -> do
- scope.user&.id.present? && preloaded_polls.present? &&
+ scope.user&.id.present? && preloaded_polls.present? && can_see_post_polls? &&
preloaded_polls.any? { |p| p.has_voted?(scope.user) }
end,
) do
diff --git a/plugins/poll/spec/integration/hidden_post_poll_serialization_spec.rb b/plugins/poll/spec/integration/hidden_post_poll_serialization_spec.rb
new file mode 100644
index 00000000000..922ce9cb488
--- /dev/null
+++ b/plugins/poll/spec/integration/hidden_post_poll_serialization_spec.rb
@@ -0,0 +1,226 @@
+# frozen_string_literal: true
+
+RSpec.describe "DiscoursePoll hidden post serialization", type: :request do
+ fab!(:author) { Fabricate(:user, refresh_auto_groups: true) }
+ fab!(:voter) { Fabricate(:user, refresh_auto_groups: true) }
+ fab!(:admin)
+ fab!(:topic)
+ fab!(:first_post) { Fabricate(:post, topic:) }
+ fab!(:poll_post) { Fabricate(:post, user: author, topic:, raw: <<~RAW) }
+ [poll public=true]
+ - Secret option A
+ - Secret option B
+ [/poll]
+ RAW
+
+ before do
+ DiscoursePoll::Poll.vote(
+ voter,
+ poll_post.id,
+ DiscoursePoll::DEFAULT_POLL_NAME,
+ [poll_post.polls.first.poll_options.first.digest],
+ )
+ poll_post.hide!(PostActionType.types[:inappropriate])
+ end
+
+ def serialized_poll_post
+ get "/t/#{topic.id}.json"
+
+ expect(response.status).to eq(200)
+
+ response.parsed_body["post_stream"]["posts"].find { |p| p["id"] == poll_post.id }
+ end
+
+ it "omits polls of hidden posts for viewers who cannot see hidden posts" do
+ serialized = serialized_poll_post
+
+ expect(serialized).not_to have_key("polls")
+ expect(response.body).not_to include("Secret option A")
+ expect(response.body).not_to include(voter.username)
+ end
+
+ it "omits the viewer's own votes on hidden posts" do
+ sign_in(voter)
+
+ serialized = serialized_poll_post
+
+ expect(serialized).not_to have_key("polls")
+ expect(serialized).not_to have_key("polls_votes")
+ end
+
+ it "keeps polls and the viewer's votes visible on ordinary posts" do
+ poll_post.unhide!
+ sign_in(voter)
+
+ serialized = serialized_poll_post
+
+ expect(serialized["polls"].first["options"].map { |o| o["html"] }).to include("Secret option A")
+ expect(serialized["polls_votes"]["poll"]).to contain_exactly(
+ poll_post.polls.first.poll_options.first.digest,
+ )
+ end
+
+ it "keeps hidden polls and votes visible to members of allowed groups" do
+ group = Fabricate(:group)
+ group.add(voter)
+ SiteSetting.hidden_post_visible_groups = group.id.to_s
+ sign_in(voter)
+
+ serialized = serialized_poll_post
+
+ expect(serialized["polls"].first["options"].map { |o| o["html"] }).to include("Secret option A")
+ expect(serialized["polls_votes"]["poll"]).to contain_exactly(
+ poll_post.polls.first.poll_options.first.digest,
+ )
+ end
+
+ it "keeps polls visible to staff" do
+ sign_in(admin)
+
+ serialized = serialized_poll_post
+
+ expect(serialized["polls"].first["options"].map { |o| o["html"] }).to include("Secret option A")
+ end
+
+ describe "poll refresh through the post endpoint" do
+ it "returns current poll data for a visible post" do
+ poll_post.unhide!
+ get "/posts/#{poll_post.id}.json"
+
+ expect(response.status).to eq(200)
+ expect(response.parsed_body["polls"].first["options"].map { |o| o["html"] }).to include(
+ "Secret option A",
+ )
+ end
+
+ it "preserves refresh access for the hidden post's author" do
+ sign_in(author)
+ get "/posts/#{poll_post.id}.json"
+
+ expect(response.status).to eq(200)
+ expect(response.parsed_body["polls"]).to be_present
+ end
+
+ it "denies refresh access for viewers who cannot see the hidden post" do
+ get "/posts/#{poll_post.id}.json"
+
+ expect(response.status).to eq(404)
+ end
+ end
+
+ describe "poll mutation rate limits" do
+ before do
+ poll_post.unhide!
+ sign_in(author)
+ RateLimiter.enable
+ 20.times { RateLimiter.new(author, "poll-mutations", 20, 1.minute).performed! }
+ end
+
+ it "rate limits votes" do
+ put "/polls/vote.json",
+ params: {
+ post_id: poll_post.id,
+ poll_name: "poll",
+ options: [poll_post.polls.first.poll_options.first.digest],
+ }
+
+ expect(response.status).to eq(429)
+ end
+
+ it "shares the limit with vote removals" do
+ delete "/polls/vote.json", params: { post_id: poll_post.id, poll_name: "poll" }
+
+ expect(response.status).to eq(429)
+ end
+
+ it "shares the limit with status changes" do
+ put "/polls/toggle_status.json",
+ params: {
+ post_id: poll_post.id,
+ poll_name: "poll",
+ status: "closed",
+ }
+
+ expect(response.status).to eq(429)
+ end
+
+ it "allows mutations again after the rate-limit window" do
+ freeze_time 1.minute.from_now + 1.second
+
+ delete "/polls/vote.json", params: { post_id: poll_post.id, poll_name: "poll" }
+
+ expect(response.status).to eq(200)
+ end
+ end
+
+ describe "poll broadcasts" do
+ def poll_messages(&block)
+ MessageBus.track_publish("/polls/#{topic.id}", &block)
+ end
+
+ it "does not broadcast hidden poll status changes, but returns the poll to its author" do
+ sign_in(author)
+
+ messages =
+ poll_messages do
+ put "/polls/toggle_status.json",
+ params: {
+ post_id: poll_post.id,
+ poll_name: "poll",
+ status: "closed",
+ }
+ end
+
+ expect(response.status).to eq(200)
+ expect(response.parsed_body["poll"]["status"]).to eq("closed")
+ expect(messages).to be_empty
+ end
+
+ it "does not broadcast votes or vote removals on hidden polls" do
+ sign_in(author)
+
+ messages =
+ poll_messages do
+ put "/polls/vote.json",
+ params: {
+ post_id: poll_post.id,
+ poll_name: "poll",
+ options: [poll_post.polls.first.poll_options.first.digest],
+ }
+ end
+
+ expect(response.status).to eq(200)
+ expect(messages).to be_empty
+
+ messages =
+ poll_messages do
+ delete "/polls/vote.json", params: { post_id: poll_post.id, poll_name: "poll" }
+ end
+
+ expect(response.status).to eq(200)
+ expect(messages).to be_empty
+ end
+
+ it "does not broadcast hidden polls from the updater or post-created hook" do
+ expect(poll_messages { DiscoursePoll::PollsUpdater.publish_changes(poll_post) }).to be_empty
+ expect(
+ poll_messages { DiscourseEvent.trigger(:post_created, poll_post, {}, author) },
+ ).to be_empty
+ end
+
+ it "resumes broadcasts when a post is no longer hidden" do
+ poll_post.unhide!
+
+ messages = poll_messages { DiscoursePoll::PollsUpdater.publish_changes(poll_post) }
+
+ expect(messages.size).to eq(1)
+ expect(messages.first.data).to eq(post_id: poll_post.id)
+ end
+ end
+
+ it "keeps polls visible to the hidden post's author" do
+ sign_in(author)
+
+ expect(serialized_poll_post).to have_key("polls")
+ end
+end
diff --git a/plugins/poll/spec/integration/ranked_choice_result_visibility_spec.rb b/plugins/poll/spec/integration/ranked_choice_result_visibility_spec.rb
index 0c70f83ceda..1f8b4b01284 100644
--- a/plugins/poll/spec/integration/ranked_choice_result_visibility_spec.rb
+++ b/plugins/poll/spec/integration/ranked_choice_result_visibility_spec.rb
@@ -96,8 +96,7 @@ RSpec.describe "DiscoursePoll ranked choice result visibility" do
expect(response.parsed_body["poll"]).to have_key("ranked_choice_outcome")
expect(messages.size).to eq(1)
- published_poll = messages.first.data.deep_stringify_keys["polls"].first
- expect(published_poll).not_to have_key("ranked_choice_outcome")
+ expect(messages.first.data).to eq(post_id: post.id)
end
it "shows on-vote outcomes to voters without leaking them to non-voters" do
@@ -118,8 +117,7 @@ RSpec.describe "DiscoursePoll ranked choice result visibility" do
expect(response.parsed_body["poll"]).to have_key("ranked_choice_outcome")
expect(messages.size).to eq(1)
- published_poll = messages.first.data.deep_stringify_keys["polls"].first
- expect(published_poll).not_to have_key("ranked_choice_outcome")
+ expect(messages.first.data).to eq(post_id: post.id)
sign_in(non_voter)
expect(topic_view_poll(post)).not_to have_key("ranked_choice_outcome")
diff --git a/plugins/poll/spec/lib/poll_message_filter_spec.rb b/plugins/poll/spec/lib/poll_message_filter_spec.rb
new file mode 100644
index 00000000000..4ecdae670cf
--- /dev/null
+++ b/plugins/poll/spec/lib/poll_message_filter_spec.rb
@@ -0,0 +1,18 @@
+# frozen_string_literal: true
+
+RSpec.describe MessageBus::Client do
+ let(:client) { described_class.new(client_id: "poll-viewer", message_bus: MessageBus) }
+
+ def message(data)
+ MessageBus::Message.new(1, 1, "/polls/123", data)
+ end
+
+ it "allows invalidation-only messages" do
+ expect(client.allowed?(message(post_id: 123))).to eq(true)
+ end
+
+ it "rejects legacy content-bearing messages, including retained messages from before deployment" do
+ expect(client.allowed?(message(post_id: 123, polls: []))).to eq(false)
+ expect(client.allowed?(message("post_id" => 123, "polls" => []))).to eq(false)
+ end
+end
diff --git a/plugins/poll/spec/lib/polls_updater_spec.rb b/plugins/poll/spec/lib/polls_updater_spec.rb
index 9faac10c54f..e8a26813825 100644
--- a/plugins/poll/spec/lib/polls_updater_spec.rb
+++ b/plugins/poll/spec/lib/polls_updater_spec.rb
@@ -100,7 +100,7 @@ RSpec.describe DiscoursePoll::PollsUpdater do
expect(poll.post.custom_fields[DiscoursePoll::HAS_POLLS]).to eq(true)
expect(message.data[:post_id]).to eq(post.id)
- expect(message.data[:polls][0][:name]).to eq(poll.name)
+ expect(message.data).to eq(post_id: post.id)
end
end
@@ -166,7 +166,7 @@ RSpec.describe DiscoursePoll::PollsUpdater do
expect(poll.post.custom_fields[DiscoursePoll::HAS_POLLS]).to eq(true)
expect(message.data[:post_id]).to eq(post.id)
- expect(message.data[:polls][0][:name]).to eq(poll.name)
+ expect(message.data).to eq(post_id: post.id)
end
end
@@ -197,7 +197,7 @@ RSpec.describe DiscoursePoll::PollsUpdater do
expect(poll.post.custom_fields[DiscoursePoll::HAS_POLLS]).to eq(true)
expect(message.data[:post_id]).to eq(post.id)
- expect(message.data[:polls][0][:name]).to eq(poll.name)
+ expect(message.data).to eq(post_id: post.id)
end
end
diff --git a/plugins/poll/spec/lib/post_extension_spec.rb b/plugins/poll/spec/lib/post_extension_spec.rb
new file mode 100644
index 00000000000..3931bd27ea4
--- /dev/null
+++ b/plugins/poll/spec/lib/post_extension_spec.rb
@@ -0,0 +1,28 @@
+# frozen_string_literal: true
+
+RSpec.describe DiscoursePoll::PostExtension do
+ fab!(:post)
+
+ before { allow(post).to receive(:publish_message!) }
+
+ it "publishes only after the outermost transaction commits" do
+ Post.transaction do
+ Post.transaction(requires_new: true) { post.publish_poll_message! }
+ expect(post).not_to have_received(:publish_message!)
+ end
+
+ expect(post).to have_received(:publish_message!).with(
+ "/polls/#{post.topic_id}",
+ post_id: post.id,
+ )
+ end
+
+ it "does not publish when the transaction rolls back" do
+ Post.transaction do
+ post.publish_poll_message!
+ raise ActiveRecord::Rollback
+ end
+
+ expect(post).not_to have_received(:publish_message!)
+ end
+end
diff --git a/plugins/poll/test/javascripts/acceptance/poll-results-test.js b/plugins/poll/test/javascripts/acceptance/poll-results-test.js
index 4ab1724ec95..81d6566174a 100644
--- a/plugins/poll/test/javascripts/acceptance/poll-results-test.js
+++ b/plugins/poll/test/javascripts/acceptance/poll-results-test.js
@@ -1,5 +1,6 @@
import { click, visit } from "@ember/test-helpers";
import { test } from "qunit";
+import pretender, { response } from "discourse/tests/helpers/create-pretender";
import {
acceptance,
publishToMessageBus,
@@ -1039,6 +1040,59 @@ acceptance("Poll results", function (needs) {
);
});
+ test("coalesces overlapping refreshes and fetches the final state", async function (assert) {
+ await visit("/t/load-more-poll-voters/134");
+ const controller = this.owner.lookup("controller:topic");
+ const post = controller.model.postStream.findLoadedPost(156);
+ const polls = post.polls;
+ let fetches = 0;
+ pretender.get(
+ "/posts/156.json",
+ () =>
+ response({
+ polls: polls.map((poll) => ({ ...poll, voters: ++fetches })),
+ }),
+ 50
+ );
+
+ const refresh = controller._onPollMessage({ post_id: 156 });
+ for (let i = 0; i < 10; i++) {
+ await controller._onPollMessage({ post_id: 156 });
+ }
+ await refresh;
+
+ assert.strictEqual(fetches, 2, "one active fetch and one trailing refresh");
+ assert.strictEqual(
+ post.polls[0].voters,
+ 2,
+ "the trailing response supplies the final state"
+ );
+
+ await controller._onPollMessage({ post_id: 156 });
+ assert.strictEqual(fetches, 3, "later invalidations still refresh");
+ });
+
+ test("ignores invalidations for unloaded posts", async function (assert) {
+ await visit("/t/load-more-poll-voters/134");
+ let fetches = 0;
+ pretender.get("/posts/999999.json", () => {
+ fetches++;
+ return response({});
+ });
+
+ await publishToMessageBus("/polls/134", { post_id: 999999 });
+ assert.strictEqual(fetches, 0, "unloaded posts must not be fetched");
+ assert.dom(".poll-container").exists();
+ });
+
+ test("handles a post becoming inaccessible before refresh", async function (assert) {
+ await visit("/t/load-more-poll-voters/134");
+ pretender.get("/posts/156.json", () => response(404, {}));
+
+ await publishToMessageBus("/polls/134", { post_id: 156 });
+ assert.dom(".poll-container").exists();
+ });
+
test("can load more voters", async function (assert) {
await visit("/t/load-more-poll-voters/134");
assert
@@ -1048,44 +1102,48 @@ acceptance("Poll results", function (needs) {
.dom(".poll-container .results li:nth-child(2) .poll-voters li")
.doesNotExist("initially, no voter shown on second option");
- await publishToMessageBus("/polls/134", {
- post_id: "156",
- polls: [
- {
- name: "poll",
- type: "regular",
- status: "open",
- public: true,
- results: "always",
- options: [
- {
- id: "db753fe0bc4e72869ac1ad8765341764",
- html: 'Option <span class="hashtag">#1</span>',
- votes: 2,
- },
- {
- id: "d8c22ff912e03740d9bc19e133e581e0",
- html: 'Option <span class="hashtag">#2</span>',
- votes: 0,
- },
- ],
- voters: 2,
- preloaded_voters: {
- db753fe0bc4e72869ac1ad8765341764: [
+ pretender.get("/posts/156.json", () =>
+ response({
+ post_id: "156",
+ polls: [
+ {
+ name: "poll",
+ type: "regular",
+ status: "open",
+ public: true,
+ results: "always",
+ options: [
{
- id: 1,
- username: "bianca",
- name: null,
- avatar_template:
- "/letter_avatar_proxy/v4/letter/b/3be4f8/{size}.png",
+ id: "db753fe0bc4e72869ac1ad8765341764",
+ html: 'Option <span class="hashtag">#1</span>',
+ votes: 2,
+ },
+ {
+ id: "d8c22ff912e03740d9bc19e133e581e0",
+ html: 'Option <span class="hashtag">#2</span>',
+ votes: 0,
},
],
+ voters: 2,
+ preloaded_voters: {
+ db753fe0bc4e72869ac1ad8765341764: [
+ {
+ id: 1,
+ username: "bianca",
+ name: null,
+ avatar_template:
+ "/letter_avatar_proxy/v4/letter/b/3be4f8/{size}.png",
+ },
+ ],
+ },
+ chart_type: "bar",
+ title: null,
},
- chart_type: "bar",
- title: null,
- },
- ],
- });
+ ],
+ })
+ );
+
+ await publishToMessageBus("/polls/134", { post_id: "156" });
assert
.dom(".poll-container .results li:nth-child(1) .poll-voters li")
@@ -1149,69 +1207,73 @@ acceptance("Poll results", function (needs) {
"after clicking fetch voters button, two voters shown on first option"
);
- await publishToMessageBus("/polls/135", {
- post_id: "158",
- polls: [
- {
- name: "poll",
- type: "ranked_choice",
- status: "open",
- public: true,
- results: "always",
- options: [
- {
- id: "def034c6770c6fd3754c054ef9ec4721",
- html: "This",
- votes: 3,
- },
- {
- id: "d8c22ff912e03740d9bc19e133e581e0",
- html: "That",
- votes: 0,
- },
- ],
- voters: 3,
- preloaded_voters: {
- def034c6770c6fd3754c054ef9ec4721: [
+ pretender.get("/posts/158.json", () =>
+ response({
+ post_id: "158",
+ polls: [
+ {
+ name: "poll",
+ type: "ranked_choice",
+ status: "open",
+ public: true,
+ results: "always",
+ options: [
{
- rank: 1,
- user: {
- id: 1,
- username: "bianca",
- name: null,
- avatar_template:
- "/letter_avatar_proxy/v4/letter/b/3be4f8/{size}.png",
- },
+ id: "def034c6770c6fd3754c054ef9ec4721",
+ html: "This",
+ votes: 3,
},
{
- rank: 1,
- user: {
- id: 7,
- username: "foo",
- name: null,
- avatar_template:
- "/letter_avatar_proxy/v4/letter/f/b19c9b/{size}.png",
- title: null,
- },
- },
- {
- rank: 1,
- user: {
- id: 11,
- username: "bar",
- name: null,
- avatar_template:
- "/letter_avatar_proxy/v4/letter/f/f33bef/{size}.png",
- title: null,
- },
+ id: "d8c22ff912e03740d9bc19e133e581e0",
+ html: "That",
+ votes: 0,
},
],
+ voters: 3,
+ preloaded_voters: {
+ def034c6770c6fd3754c054ef9ec4721: [
+ {
+ rank: 1,
+ user: {
+ id: 1,
+ username: "bianca",
+ name: null,
+ avatar_template:
+ "/letter_avatar_proxy/v4/letter/b/3be4f8/{size}.png",
+ },
+ },
+ {
+ rank: 1,
+ user: {
+ id: 7,
+ username: "foo",
+ name: null,
+ avatar_template:
+ "/letter_avatar_proxy/v4/letter/f/b19c9b/{size}.png",
+ title: null,
+ },
+ },
+ {
+ rank: 1,
+ user: {
+ id: 11,
+ username: "bar",
+ name: null,
+ avatar_template:
+ "/letter_avatar_proxy/v4/letter/f/f33bef/{size}.png",
+ title: null,
+ },
+ },
+ ],
+ },
+ chart_type: "bar",
+ title: null,
},
- chart_type: "bar",
- title: null,
- },
- ],
- });
+ ],
+ })
+ );
+
+ await publishToMessageBus("/polls/135", { post_id: "158" });
assert
.dom(