mirror of
https://github.com/discourse/discourse.git
synced 2024-11-29 03:23:43 +08:00
FIX: Allow users to create polls in PMs with non human users (#9055)
This commit is contained in:
parent
a653737a66
commit
c62d5b139b
|
@ -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
|
||||
|
|
|
@ -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"))
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue
Block a user