FIX: Allow users to create polls in PMs with non human users (#9055)

This commit is contained in:
Dan Ungureanu 2020-03-02 21:29:40 +02:00 committed by GitHub
parent a653737a66
commit c62d5b139b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 31 additions and 1 deletions

View File

@ -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

View File

@ -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"))

View File

@ -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