mirror of
https://github.com/discourse/discourse.git
synced 2025-06-02 04:08:41 +08:00
FIX: Poll: do not attempt to show voter list on private polls (#27714)
* FIX: avoid attempting to enrich results with undefined voters
This commit is contained in:
@ -40,7 +40,7 @@ export default class PollResultsStandardComponent extends Component {
|
|||||||
const chosen = (this.args.vote || []).includes(option.id);
|
const chosen = (this.args.vote || []).includes(option.id);
|
||||||
option.percentage = per;
|
option.percentage = per;
|
||||||
option.chosen = chosen;
|
option.chosen = chosen;
|
||||||
let voters = this.args.voters[option.id] || [];
|
let voters = this.args.isPublic ? this.args.voters[option.id] || [] : [];
|
||||||
option.voters = [...voters];
|
option.voters = [...voters];
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -82,16 +82,18 @@ export default class PollResultsStandardComponent extends Component {
|
|||||||
style={{htmlSafe (concat "width:" option.percentage "%")}}
|
style={{htmlSafe (concat "width:" option.percentage "%")}}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<PollVoters
|
{{#if @isPublic}}
|
||||||
@postId={{@postId}}
|
<PollVoters
|
||||||
@pollType={{@pollType}}
|
@postId={{@postId}}
|
||||||
@optionId={{option.id}}
|
@pollType={{@pollType}}
|
||||||
@pollName={{@pollName}}
|
@optionId={{option.id}}
|
||||||
@totalVotes={{option.votes}}
|
@pollName={{@pollName}}
|
||||||
@voters={{option.voters}}
|
@totalVotes={{option.votes}}
|
||||||
@fetchVoters={{@fetchVoters}}
|
@voters={{option.voters}}
|
||||||
@loading={{option.loading}}
|
@fetchVoters={{@fetchVoters}}
|
||||||
/>
|
@loading={{option.loading}}
|
||||||
|
/>
|
||||||
|
{{/if}}
|
||||||
</div>
|
</div>
|
||||||
</li>
|
</li>
|
||||||
{{/each}}
|
{{/each}}
|
||||||
|
@ -2,7 +2,7 @@ import { render } from "@ember/test-helpers";
|
|||||||
import hbs from "htmlbars-inline-precompile";
|
import hbs from "htmlbars-inline-precompile";
|
||||||
import { module, test } from "qunit";
|
import { module, test } from "qunit";
|
||||||
import { setupRenderingTest } from "discourse/tests/helpers/component-test";
|
import { setupRenderingTest } from "discourse/tests/helpers/component-test";
|
||||||
import { queryAll } from "discourse/tests/helpers/qunit-helpers";
|
import { exists, queryAll } from "discourse/tests/helpers/qunit-helpers";
|
||||||
|
|
||||||
const TWO_OPTIONS = [
|
const TWO_OPTIONS = [
|
||||||
{ id: "1ddc47be0d2315b9711ee8526ca9d83f", html: "This", votes: 5, rank: 0 },
|
{ id: "1ddc47be0d2315b9711ee8526ca9d83f", html: "This", votes: 5, rank: 0 },
|
||||||
@ -41,6 +41,7 @@ module("Poll | Component | poll-results-standard", function (hooks) {
|
|||||||
options: TWO_OPTIONS,
|
options: TWO_OPTIONS,
|
||||||
pollName: "Two Choice Poll",
|
pollName: "Two Choice Poll",
|
||||||
pollType: "single",
|
pollType: "single",
|
||||||
|
isPublic: true,
|
||||||
postId: 123,
|
postId: 123,
|
||||||
vote: ["1ddc47be0d2315b9711ee8526ca9d83f"],
|
vote: ["1ddc47be0d2315b9711ee8526ca9d83f"],
|
||||||
voters: PRELOADEDVOTERS,
|
voters: PRELOADEDVOTERS,
|
||||||
@ -52,6 +53,7 @@ module("Poll | Component | poll-results-standard", function (hooks) {
|
|||||||
@options={{this.options}}
|
@options={{this.options}}
|
||||||
@pollName={{this.pollName}}
|
@pollName={{this.pollName}}
|
||||||
@pollType={{this.pollType}}
|
@pollType={{this.pollType}}
|
||||||
|
@isPublic={{this.isPublic}}
|
||||||
@postId={{this.postId}}
|
@postId={{this.postId}}
|
||||||
@vote={{this.vote}}
|
@vote={{this.vote}}
|
||||||
@voters={{this.voters}}
|
@voters={{this.voters}}
|
||||||
@ -61,6 +63,35 @@ module("Poll | Component | poll-results-standard", function (hooks) {
|
|||||||
|
|
||||||
assert.strictEqual(queryAll(".option .percentage")[0].innerText, "56%");
|
assert.strictEqual(queryAll(".option .percentage")[0].innerText, "56%");
|
||||||
assert.strictEqual(queryAll(".option .percentage")[1].innerText, "44%");
|
assert.strictEqual(queryAll(".option .percentage")[1].innerText, "44%");
|
||||||
|
assert.ok(exists("ul.poll-voters-list"));
|
||||||
|
});
|
||||||
|
|
||||||
|
test("Omits voters for private polls", async function (assert) {
|
||||||
|
this.setProperties({
|
||||||
|
options: TWO_OPTIONS,
|
||||||
|
pollName: "Two Choice Poll",
|
||||||
|
pollType: "single",
|
||||||
|
isPublic: false,
|
||||||
|
postId: 123,
|
||||||
|
vote: ["1ddc47be0d2315b9711ee8526ca9d83f"],
|
||||||
|
voters: PRELOADEDVOTERS,
|
||||||
|
votersCount: 9,
|
||||||
|
fetchVoters: () => {},
|
||||||
|
});
|
||||||
|
|
||||||
|
await render(hbs`<PollResultsStandard
|
||||||
|
@options={{this.options}}
|
||||||
|
@pollName={{this.pollName}}
|
||||||
|
@pollType={{this.pollType}}
|
||||||
|
@isPublic={{this.isPublic}}
|
||||||
|
@postId={{this.postId}}
|
||||||
|
@vote={{this.vote}}
|
||||||
|
@voters={{this.voters}}
|
||||||
|
@votersCount={{this.votersCount}}
|
||||||
|
@fetchVoters={{this.fetchVoters}}
|
||||||
|
/>`);
|
||||||
|
|
||||||
|
assert.ok(!exists("ul.poll-voters-list"));
|
||||||
});
|
});
|
||||||
|
|
||||||
test("options in ascending order", async function (assert) {
|
test("options in ascending order", async function (assert) {
|
||||||
|
Reference in New Issue
Block a user