diff --git a/plugins/discourse-narrative-bot/spec/discourse_narrative_bot/advanced_user_narrative_spec.rb b/plugins/discourse-narrative-bot/spec/discourse_narrative_bot/advanced_user_narrative_spec.rb index a44c9e250ca..28fec30417f 100644 --- a/plugins/discourse-narrative-bot/spec/discourse_narrative_bot/advanced_user_narrative_spec.rb +++ b/plugins/discourse-narrative-bot/spec/discourse_narrative_bot/advanced_user_narrative_spec.rb @@ -606,6 +606,19 @@ RSpec.describe DiscourseNarrativeBot::AdvancedUserNarrative do ) end + it 'allows new users to create polls' do + user.update(trust_level: 0) + + post = PostCreator.create(user, topic_id: topic.id, raw: <<~RAW) + [poll type=regular] + * foo + * bar + [/poll] + RAW + + expect(post.errors[:base].size).to eq(0) + end + describe 'when post is not in the right topic' do it 'should not do anything' do other_post diff --git a/plugins/poll/lib/post_validator.rb b/plugins/poll/lib/post_validator.rb index 19f6648e4f7..788fe1e24bb 100644 --- a/plugins/poll/lib/post_validator.rb +++ b/plugins/poll/lib/post_validator.rb @@ -9,7 +9,7 @@ module DiscoursePoll def validate_post min_trust_level = SiteSetting.poll_minimum_trust_level_to_create - if @post&.user&.staff? || @post&.user&.trust_level >= TrustLevel[min_trust_level] + if @post&.user&.staff? || @post&.user&.trust_level >= TrustLevel[min_trust_level] || @post&.topic&.pm_with_non_human_user? true else @post.errors.add(:base, I18n.t("poll.insufficient_rights_to_create")) diff --git a/plugins/poll/spec/controllers/posts_controller_spec.rb b/plugins/poll/spec/controllers/posts_controller_spec.rb index 411247c8f74..8f9dae14a2a 100644 --- a/plugins/poll/spec/controllers/posts_controller_spec.rb +++ b/plugins/poll/spec/controllers/posts_controller_spec.rb @@ -348,6 +348,23 @@ describe PostsController do json = ::JSON.parse(response.body) expect(json["errors"][0]).to eq(I18n.t("poll.insufficient_rights_to_create")) end + + it "skips the check in PMs with bots" do + user = Fabricate(:user, trust_level: 1) + topic = Fabricate(:private_message_topic, topic_allowed_users: [ + Fabricate.build(:topic_allowed_user, user: user), + Fabricate.build(:topic_allowed_user, user: Discourse.system_user) + ]) + Fabricate(:post, topic_id: topic.id, user_id: Discourse::SYSTEM_USER_ID) + + log_in_user(user) + + post :create, params: { + topic_id: topic.id, raw: "[poll]\n- A\n- B\n[/poll]" + }, format: :json + + expect(::JSON.parse(response.body)["errors"]).to eq(nil) + end end describe "regular user with equal trust level" do