From 47f749744f7f3478a6a9c7c64a6dadec54025e23 Mon Sep 17 00:00:00 2001 From: Robert <35533304+merefield@users.noreply.github.com> Date: Tue, 13 Aug 2024 08:29:16 +0100 Subject: [PATCH] FIX: poll when config is on_close only show results when poll is closed (#28299) See: https://meta.discourse.org/t/cant-edit-topic-with-poll-bug-occurs/320845?u=merefield When the Poll is set to "results ON_CLOSE", vote numbers for each option are only streamed to the browser when the vote is Closed. It is therefore not possible to render the Results. The current issue is that when you refresh the page, for those that have voted the default view is results. For this type of poll this should NOT happen. The Results view in this mode should not be possible to see until closure, even for the Author. Because the votes are not yet serialised when this kind of poll remains open, an attempt to display results causes a JavaScript exception and in any case does not make logical sense. So the fix here is making sure the default view, for Polls that have results on close, is the voting view until the Poll is Closed. I've added a test to cover this scenario. Additionally, this requires a refresh of the page when the poll admin actions a Close to ensure the results are serialized in. --- .../discourse/components/poll-options.gjs | 7 +++- .../components/poll-results-standard.gjs | 7 +++- .../javascripts/discourse/components/poll.gjs | 17 +++++++-- .../test/javascripts/component/poll-test.js | 37 +++++++++++++++++++ 4 files changed, 62 insertions(+), 6 deletions(-) diff --git a/plugins/poll/assets/javascripts/discourse/components/poll-options.gjs b/plugins/poll/assets/javascripts/discourse/components/poll-options.gjs index 4423418747f..42043a39790 100644 --- a/plugins/poll/assets/javascripts/discourse/components/poll-options.gjs +++ b/plugins/poll/assets/javascripts/discourse/components/poll-options.gjs @@ -26,7 +26,12 @@ export default class PollOptionsComponent extends Component { this.args.sendOptionSelect(option, rank); }