mirror of
https://github.com/discourse/discourse.git
synced 2025-01-30 05:27:38 +08:00
FIX: min_trust_to_create_topic affects private messages
This commit is contained in:
parent
805120fc95
commit
59a011e6a9
|
@ -95,7 +95,7 @@ class TopicCreator
|
||||||
|
|
||||||
category = find_category
|
category = find_category
|
||||||
|
|
||||||
@guardian.ensure_can_create!(Topic, category) unless @opts[:skip_validations]
|
@guardian.ensure_can_create!(Topic, category) unless (@opts[:skip_validations] || @opts[:archetype] == Archetype.private_message)
|
||||||
|
|
||||||
topic_params[:category_id] = category.id if category.present?
|
topic_params[:category_id] = category.id if category.present?
|
||||||
|
|
||||||
|
|
|
@ -2,14 +2,15 @@ require 'spec_helper'
|
||||||
|
|
||||||
describe TopicCreator do
|
describe TopicCreator do
|
||||||
|
|
||||||
let(:user) { Fabricate(:user) }
|
let(:user) { Fabricate(:user, trust_level: TrustLevel[2]) }
|
||||||
let(:moderator) { Fabricate(:moderator) }
|
let(:moderator) { Fabricate(:moderator) }
|
||||||
let(:admin) { Fabricate(:admin) }
|
let(:admin) { Fabricate(:admin) }
|
||||||
|
|
||||||
let(:valid_attrs) { Fabricate.attributes_for(:topic) }
|
let(:valid_attrs) { Fabricate.attributes_for(:topic) }
|
||||||
|
let(:pm_valid_attrs) { {raw: 'this is a new post', title: 'this is a new title', archetype: Archetype.private_message, target_usernames: moderator.username} }
|
||||||
|
|
||||||
describe '#create' do
|
describe '#create' do
|
||||||
context 'success cases' do
|
context 'topic success cases' do
|
||||||
before do
|
before do
|
||||||
TopicCreator.any_instance.expects(:save_topic).returns(true)
|
TopicCreator.any_instance.expects(:save_topic).returns(true)
|
||||||
TopicCreator.any_instance.expects(:watch_topic).returns(true)
|
TopicCreator.any_instance.expects(:watch_topic).returns(true)
|
||||||
|
@ -49,6 +50,32 @@ describe TopicCreator do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'private message' do
|
||||||
|
|
||||||
|
context 'success cases' do
|
||||||
|
before do
|
||||||
|
TopicCreator.any_instance.expects(:save_topic).returns(true)
|
||||||
|
TopicCreator.any_instance.expects(:watch_topic).returns(true)
|
||||||
|
SiteSetting.stubs(:allow_duplicate_topic_titles?).returns(true)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "should be possible for a regular user to send private message" do
|
||||||
|
expect(TopicCreator.create(user, Guardian.new(user), pm_valid_attrs)).to be_valid
|
||||||
|
end
|
||||||
|
|
||||||
|
it "min_trust_to_create_topic setting should not be checked when sending private message" do
|
||||||
|
SiteSetting.min_trust_to_create_topic = TrustLevel[4]
|
||||||
|
expect(TopicCreator.create(user, Guardian.new(user), pm_valid_attrs)).to be_valid
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'failure cases' do
|
||||||
|
it "min_trust_to_send_messages setting should be checked when sending private message" do
|
||||||
|
SiteSetting.min_trust_to_send_messages = TrustLevel[4]
|
||||||
|
expect(-> { TopicCreator.create(user, Guardian.new(user), pm_valid_attrs) }).to raise_error(ActiveRecord::Rollback)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue
Block a user