Can't select thumbs up or down in discobot's poll example

This happens both here on meta.discourse.org and on my own Discourse installation. Nothing seems to happen when either :thumbsup: or :thumbsdown: are clicked, nor does anything happen when I click “Show results” in @discobot’s poll. To reproduce, initiate the advanced user tutorial and follow through 'til you get the reply from the poll step. I tried this in both Firefox 53.0.3 (64-bit) and Chromium version 58.0.3029.110 Built on Ubuntu, running on Ubuntu 16.04 (64-bit).

I thought that this would be an easy fix, but the source code for this checks out:

https://github.com/discourse/discourse/blob/master/plugins/discourse-narrative-bot/config/locales/server.en.yml#L413

I don’t understand where it went wrong. It seems as if this bit is missing in the finished post:

<i class="fa fa-circle-o" aria-hidden="true"></i>

I was hoping for an easy fix that I could submit myself, but I’m a bit lost now. Posting this via the API seems to work just fine:

post_details = {
    "title": "This is a poll!",
    "raw": "Hey, nice poll! How’d I do in teaching you?\n\n[poll]\n* :+1:\n* :-1:\n[/poll]",
    "category": "1",
    "created_at": "2017-06-01T00:00",
    "tags[]": ["yes", "no", "maybe"]
}

Here is what I found using Pry on my own Discourse installation, my poll looks like this:

raw:
    "[poll type=regular max=16]\n* Everything is going to be alright\n* Everything is not going to be alright\n[/poll]",
cooked:
    "<div class=\"poll\" data-poll-status=\"open\" data-poll-name=\"poll\" data-poll-type=\"regular\" data-poll-max=\"16\">\n<div>\n<div class=\"poll-container\"><ul>\n<li data-poll-option-id=\"374d020e157fb96528625ca6425b4262\">Everything is going to be alright</li>\n<li data-poll-option-id=\"f94147e24ee33997b8f922766b8e7d12\">Everything is not going to be alright</li>\n</ul></div>\n<div class=\"poll-info\"><p><span class=\"info-number\">0</span><span class=\"info-text\">voters</span></p></div>\n</div>\n<div class=\"poll-buttons\"><a title=\"Display the poll results\">Show results</a></div>\n</div>",

…and this was @discobot’s reply:

raw:
    "Hey, nice poll! How’d I do in teaching you?\n\n[poll]\n* :+1:\n* :-1:\n[/poll]\n\nSometimes you may wish to **hide details** in your replies:\n\n- When you’re discussing plot points of a movie or TV show that would be a considered a spoiler.\n\n- When your post needs lots of optional details that may be overwhelming when read all at once.\n\n[details=Select this to see how it works!]\n1. Select the <img src=\"/images/font-awesome-gear.png\" width=\"16\" height=\"16\"> gear in the editor.\n2. Select \"Hide Details\".\n3. Edit the details summary and add your content.\n[/details]\n\nCan you use the <img src=\"/images/font-awesome-gear.png\" width=\"16\" height=\"16\"> gear in the editor to add a details section to your next reply?",
cooked:
    "<p>Hey, nice poll! How’d I do in teaching you?</p>\n\n<div class=\"poll\" data-poll-status=\"open\" data-poll-name=\"poll\">\n<div>\n<div class=\"poll-container\"><ul>\n<li data-poll-option-id=\"dd8f2a6a3f3176720523634d9ed247e4\"><img src=\"https://community.chakralinux.org/images/emoji/emoji_one/+1.png?v=3\" title=\":+1:\" class=\"emoji\" alt=\":+1:\"></li>\n<li data-poll-option-id=\"e7e6f976d74764e3d9d19f99bea8befe\"><img src=\"https://community.chakralinux.org/images/emoji/emoji_one/-1.png?v=3\" title=\":-1:\" class=\"emoji\" alt=\":-1:\"></li>\n</ul></div>\n<div class=\"poll-info\"><p><span class=\"info-number\">0</span><span class=\"info-text\">voters</span></p></div>\n</div>\n<div class=\"poll-buttons\"><a title=\"Display the poll results\">Show results</a></div>\n</div>\n\n<p>Sometimes you may wish to <strong>hide details</strong> in your replies:</p>\n\n<ul>\n<li><p>When you’re discussing plot points of a movie or TV show that would be a considered a spoiler.</p></li>\n<li><p>When your post needs lots of optional details that may be overwhelming when read all at once.</p></li>\n</ul>\n\n<details><summary>Select this to see how it works!</summary>\n\n<ol>\n<li>Select the <img src=\"https://community.chakralinux.org/images/font-awesome-gear.png\" width=\"16\" height=\"16\"> gear in the editor.</li>\n<li>Select \"Hide Details\".</li>\n<li>Edit the details summary and add your content.</li>\n</ol>\n\n</details>\n\n<p>Can you use the <img src=\"https://community.chakralinux.org/images/font-awesome-gear.png\" width=\"16\" height=\"16\"> gear in the editor to add a details section to your next reply?</p>",
2 Likes

confirmed here on meta.

1 Like

This took me a while to figure out @tgxworld - it looks like validations are skipped for discobot’s replies, and the validations are what builds the post JSON.

My question is: is skip_validations necessary for every discobot reply? If we enabled validations for the poll reply it would work. Is there any downside to that?

Otherwise the following patch works, but you see a flash as the post gets saved a second time:

diff --git a/plugins/discourse-narrative-bot/lib/discourse_narrative_bot/advanced_user_narrative.rb b/plugins/discourse-narrative-bot/lib/discourse_narrative_bot/advanced_user_narrative.rb
index 2139a175cd..d84f4fc16e 100644
--- a/plugins/discourse-narrative-bot/lib/discourse_narrative_bot/advanced_user_narrative.rb
+++ b/plugins/discourse-narrative-bot/lib/discourse_narrative_bot/advanced_user_narrative.rb
@@ -321,7 +321,12 @@ module DiscourseNarrativeBot
         RAW

         fake_delay
-        reply_to(@post, raw)
+
+        # Save the post and poll
+        poll_post = reply_to(@post, raw)
+        generated_poll = DiscoursePoll::PollsValidator.new(poll_post).validate_polls
+        poll_post.custom_fields[DiscoursePoll::POLLS_CUSTOM_FIELD] = generated_poll
+        poll_post.save_custom_fields(true)
       else
         fake_delay
         reply_to(@post, I18n.t("#{I18N_KEY}.poll.not_found", i18n_post_args)) unless @data[:attempted]
5 Likes

I think there may be some rate limits for posting the exact same text over and over.

4 Likes

I think the bug here is with the poll plugin where it builds the poll’s fields in a validation which can be skipped. I’ll have a look on Monday.

8 Likes

I reverted

https://github.com/discourse/discourse/commit/cd2869c7677a5085bdfaccf08131079b1bd9fa7a

and backported the commit so that we don’t leave the polls broken. Also, it seems like post validations are already skipped for admin/staff users so I’ll have a closer look into the “Body is too similar to what you recently posted” error.

5 Likes

I tested this both here on meta and on my own installation, by restarting the advanced user tutorial. Both appears to work as they should. Thank you for pointing me in the right direction, I’ll try to learn more about validation.

3 Likes