Overriding poll default so "public=true"

I´m a newby but interested in solving the problem so I asked chat-gpt:

Here is the answer:

The script you found is a good start. It’s modifying the poll-ui-builder controller to set the publicPoll property to true when the controller’s onShow() function is called. This is indeed intended to be added as a Theme Component.

However, the code might not be working due to the order of execution. The original onShow() method sets publicPoll to false and then the modification sets publicPoll to true afterwards.

A correct way would be to call the parent’s onShow method first, and then set publicPoll to true:

<script type="text/discourse-plugin" version="0.8">
api.modifyClass("controller:poll-ui-builder", {
  onShow() {
    this._super(...arguments);
    this.set('publicPoll', true);
  }
});
</script>

You can add this script to your theme by following these steps:

  1. Go to the Discourse Admin dashboard.
  2. Under the “Customize” section, click on “Themes”.
  3. Select the theme that you want to modify.
  4. In the theme editing screen, click on “Edit CSS/HTML”.
  5. In the left sidebar, click on “</> Common”.
  6. Paste the above script into the “</> Common” section.
  7. Click on the “Save” button.

This will apply the change to your theme. Please remember that theme changes are only applied to users who are using that particular theme. If you have multiple themes, you’ll need to add this modification to each one.

Also, remember to clear your browser cache or do a hard reload to ensure that the changes are loaded correctly.

I will try to follow these steps with the admin of our Forum, but this takes a while, if someone else here want to try this in first please and give feedback I would be very happy.

Another thing i would love to change is the behaviour of the ui, i want to skip the simple screen, so i asked chat-gpt again:

In your current code, the extended view is controlled by the showAdvanced property. If this is set to true, the advanced view will be shown.

To always show the advanced view, you can modify the onShow() method in the poll-ui-builder controller to set showAdvanced to true. You can add this modification to the theme component you created earlier. Here’s the updated script:

<script type="text/discourse-plugin" version="0.8">
api.modifyClass("controller:poll-ui-builder", {
  onShow() {
    this._super(...arguments);
    this.set('publicPoll', true);
    this.set('showAdvanced', true);
  }
});
</script>

Remember to follow the steps I previously outlined to add this script to your theme. Once the script is saved, the advanced view should always be shown when the poll UI is loaded.

Again, remember to clear your browser cache or do a hard reload to ensure that the changes are loaded correctly.

I would love to try and test by myself somehow, but as mentioned before i´m just a moderator, not the admin of our site, so this will take some days or weeks.

2 Likes