FEATURE: Allow posting via email to read-only mailing list mirror category

This commit is contained in:
Gerhard Schlager 2018-01-04 13:38:06 +01:00
parent d7cd7e4dc7
commit e0d73a957d
3 changed files with 31 additions and 5 deletions

View File

@ -451,7 +451,7 @@ module Email
category = destination[:obj]
raise StrangersNotAllowedError if user.staged? && !category.email_in_allow_strangers
raise InsufficientTrustLevelError if !user.has_trust_level?(SiteSetting.email_in_min_trust)
raise InsufficientTrustLevelError if !user.has_trust_level?(SiteSetting.email_in_min_trust) && !sent_to_mailinglist_mirror?
create_topic(user: user,
raw: body,
@ -753,6 +753,11 @@ module Email
options[:raw] << Email::Receiver.elided_html(options[:elided])
end
if sent_to_mailinglist_mirror?
options[:skip_validations] = true
options[:skip_guardian] = true
end
user = options.delete(:user)
result = NewPostManager.new(user, options).perform

View File

@ -130,7 +130,7 @@ class PostCreator
return false unless skip_validations? || validate_child(topic_creator)
else
@topic = Topic.find_by(id: @opts[:topic_id])
if (@topic.blank? || !guardian.can_create?(Post, @topic))
unless @topic.present? && (@opts[:skip_guardian] || guardian.can_create?(Post, @topic))
errors[:base] << I18n.t(:topic_not_found)
return false
end

View File

@ -798,12 +798,12 @@ describe Email::Receiver do
end
end
context "mailinglist mirror" do
context "mailing list mirror" do
let!(:category) { Fabricate(:mailinglist_mirror_category) }
before do
SiteSetting.block_auto_generated_emails = true
SiteSetting.find_related_post_with_key = true
Fabricate(:mailinglist_mirror_category)
end
it "should allow creating topic even when email is autogenerated" do
@ -817,5 +817,26 @@ describe Email::Receiver do
expect { process(:mailinglist_reply) }.to change { topic.posts.count }
end
context "read-only category" do
before do
category.set_permissions(everyone: :readonly)
category.save
Fabricate(:user, email: "alice@foo.com")
Fabricate(:user, email: "bob@bar.com")
end
it "should allow creating topic within read-only category" do
expect { process(:mailinglist) }.to change { Topic.count }
end
it "should allow replying within read-only category" do
process(:mailinglist)
topic = Topic.last
expect { process(:mailinglist_reply) }.to change { topic.posts.count }
end
end
end
end