FIX: force enable a user's email_private_messages option when user replies via email (#6478)
* Enable user email PM when posting to group or replying to topic via email * remove extra line * Add test and fix snake_case * Only reenable email_private_messages for PM replies
This commit is contained in:
parent
005e1f5373
commit
b06dccac49
|
@ -621,11 +621,6 @@ module Email
|
||||||
end
|
end
|
||||||
|
|
||||||
def create_group_post(group, user, body, elided, hidden_reason_id)
|
def create_group_post(group, user, body, elided, hidden_reason_id)
|
||||||
# ensure user PM emails are enabled (since user is posting via email)
|
|
||||||
if !user.staged && !user.user_option.email_private_messages
|
|
||||||
user.user_option.update!(email_private_messages: true)
|
|
||||||
end
|
|
||||||
|
|
||||||
message_ids = Email::Receiver.extract_reply_message_ids(@mail, max_message_id_count: 5)
|
message_ids = Email::Receiver.extract_reply_message_ids(@mail, max_message_id_count: 5)
|
||||||
post_ids = []
|
post_ids = []
|
||||||
|
|
||||||
|
@ -648,6 +643,8 @@ module Email
|
||||||
topic: post.topic,
|
topic: post.topic,
|
||||||
skip_validations: true)
|
skip_validations: true)
|
||||||
else
|
else
|
||||||
|
enable_email_pm_setting(user)
|
||||||
|
|
||||||
create_topic(user: user,
|
create_topic(user: user,
|
||||||
raw: body,
|
raw: body,
|
||||||
elided: elided,
|
elided: elided,
|
||||||
|
@ -856,6 +853,7 @@ module Email
|
||||||
def create_reply(options = {})
|
def create_reply(options = {})
|
||||||
raise TopicNotFoundError if options[:topic].nil? || options[:topic].trashed?
|
raise TopicNotFoundError if options[:topic].nil? || options[:topic].trashed?
|
||||||
options[:post] = nil if options[:post]&.trashed?
|
options[:post] = nil if options[:post]&.trashed?
|
||||||
|
enable_email_pm_setting(options[:user]) if options[:topic].archetype == Archetype.private_message
|
||||||
|
|
||||||
if post_action_type = post_action_for(options[:raw])
|
if post_action_type = post_action_for(options[:raw])
|
||||||
create_post_action(options[:user], options[:post], post_action_type)
|
create_post_action(options[:user], options[:post], post_action_type)
|
||||||
|
@ -1073,6 +1071,13 @@ module Email
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def enable_email_pm_setting(user)
|
||||||
|
# ensure user PM emails are enabled (since user is posting via email)
|
||||||
|
if !user.staged && !user.user_option.email_private_messages
|
||||||
|
user.user_option.update!(email_private_messages: true)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -531,6 +531,18 @@ describe Email::Receiver do
|
||||||
|
|
||||||
expect { process(:reply_user_not_matching_but_known) }.to change { topic.posts.count }
|
expect { process(:reply_user_not_matching_but_known) }.to change { topic.posts.count }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "re-enables user's email_private_messages setting when user replies to a private topic" do
|
||||||
|
topic.update_columns(category_id: nil, archetype: Archetype.private_message)
|
||||||
|
topic.allowed_users << user
|
||||||
|
topic.save
|
||||||
|
|
||||||
|
user.user_option.update_columns(email_private_messages: false)
|
||||||
|
expect { process(:reply_user_matching) }.to change { topic.posts.count }
|
||||||
|
user.reload
|
||||||
|
expect(user.user_option.email_private_messages).to eq(true)
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
context "new message to a group" do
|
context "new message to a group" do
|
||||||
|
@ -629,7 +641,7 @@ describe Email::Receiver do
|
||||||
expect(Post.last.raw).to match(/discourse\.rb/)
|
expect(Post.last.raw).to match(/discourse\.rb/)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "enables user's email_private_messages option when user emails group" do
|
it "enables user's email_private_messages setting when user emails new topic to group" do
|
||||||
user = Fabricate(:user, email: "existing@bar.com")
|
user = Fabricate(:user, email: "existing@bar.com")
|
||||||
user.user_option.update_columns(email_private_messages: false)
|
user.user_option.update_columns(email_private_messages: false)
|
||||||
expect { process(:group_existing_user) }.to change(Topic, :count)
|
expect { process(:group_existing_user) }.to change(Topic, :count)
|
||||||
|
|
Loading…
Reference in New Issue