mirror of
https://github.com/discourse/discourse.git
synced 2025-06-28 04:44:07 +08:00
FEATURE: Allow posting via email to read-only mailing list mirror category
This commit is contained in:
@ -451,7 +451,7 @@ module Email
|
|||||||
category = destination[:obj]
|
category = destination[:obj]
|
||||||
|
|
||||||
raise StrangersNotAllowedError if user.staged? && !category.email_in_allow_strangers
|
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,
|
create_topic(user: user,
|
||||||
raw: body,
|
raw: body,
|
||||||
@ -753,6 +753,11 @@ module Email
|
|||||||
options[:raw] << Email::Receiver.elided_html(options[:elided])
|
options[:raw] << Email::Receiver.elided_html(options[:elided])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if sent_to_mailinglist_mirror?
|
||||||
|
options[:skip_validations] = true
|
||||||
|
options[:skip_guardian] = true
|
||||||
|
end
|
||||||
|
|
||||||
user = options.delete(:user)
|
user = options.delete(:user)
|
||||||
result = NewPostManager.new(user, options).perform
|
result = NewPostManager.new(user, options).perform
|
||||||
|
|
||||||
|
@ -130,7 +130,7 @@ class PostCreator
|
|||||||
return false unless skip_validations? || validate_child(topic_creator)
|
return false unless skip_validations? || validate_child(topic_creator)
|
||||||
else
|
else
|
||||||
@topic = Topic.find_by(id: @opts[:topic_id])
|
@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)
|
errors[:base] << I18n.t(:topic_not_found)
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
@ -799,11 +799,11 @@ describe Email::Receiver do
|
|||||||
end
|
end
|
||||||
|
|
||||||
context "mailing list mirror" do
|
context "mailing list mirror" do
|
||||||
|
let!(:category) { Fabricate(:mailinglist_mirror_category) }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
SiteSetting.block_auto_generated_emails = true
|
SiteSetting.block_auto_generated_emails = true
|
||||||
SiteSetting.find_related_post_with_key = true
|
SiteSetting.find_related_post_with_key = true
|
||||||
|
|
||||||
Fabricate(:mailinglist_mirror_category)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should allow creating topic even when email is autogenerated" do
|
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 }
|
expect { process(:mailinglist_reply) }.to change { topic.posts.count }
|
||||||
end
|
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
|
||||||
end
|
end
|
||||||
|
Reference in New Issue
Block a user