From 8af9952b258e8642a6c6b78f61845278c4f5f7a3 Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Tue, 18 Jun 2013 15:54:02 -0400 Subject: [PATCH] Change all headers to X-Discourse-* instead of Discourse-* --- app/mailers/user_notifications.rb | 3 +++ lib/email/message_builder.rb | 6 +++--- lib/email/sender.rb | 6 +++--- spec/components/email/message_builder_spec.rb | 14 +++++++------- spec/components/email/sender_spec.rb | 6 +++--- spec/mailers/user_notifications_spec.rb | 2 +- 6 files changed, 20 insertions(+), 17 deletions(-) diff --git a/app/mailers/user_notifications.rb b/app/mailers/user_notifications.rb index 45327cf0cfb..5da628fd00c 100644 --- a/app/mailers/user_notifications.rb +++ b/app/mailers/user_notifications.rb @@ -101,6 +101,9 @@ class UserNotifications < ActionMailer::Base username = @notification.data_hash[:display_username] notification_type = Notification.types[opts[:notification].notification_type].to_s + # For now only admins can reply by email + opts.delete(:allow_reply_by_email) unless user.admin? + email_opts = { topic_title: @notification.data_hash[:topic_title], message: @post.raw, diff --git a/lib/email/message_builder.rb b/lib/email/message_builder.rb index 3a0bdcbf66d..321c8d25d1c 100644 --- a/lib/email/message_builder.rb +++ b/lib/email/message_builder.rb @@ -55,11 +55,11 @@ module Email result['List-Unsubscribe'] = "<#{template_args[:user_preferences_url]}>" if @opts[:add_unsubscribe_link] end - result['Discourse-Post-Id'] = @opts[:post_id].to_s if @opts[:post_id] - result['Discourse-Topic-Id'] = @opts[:topic_id].to_s if @opts[:topic_id] + result['X-Discourse-Post-Id'] = @opts[:post_id].to_s if @opts[:post_id] + result['X-Discourse-Topic-Id'] = @opts[:topic_id].to_s if @opts[:topic_id] if allow_reply_by_email? - result['Discourse-Reply-Key'] = reply_key + result['X-Discourse-Reply-Key'] = reply_key result['Reply-To'] = reply_by_email_address else result['Reply-To'] = from_value diff --git a/lib/email/sender.rb b/lib/email/sender.rb index 0c086869581..2e245f2d48a 100644 --- a/lib/email/sender.rb +++ b/lib/email/sender.rb @@ -47,9 +47,9 @@ module Email user_id: @user.try(:id)) email_log.post_id = @messager - add_header_to_log('Discourse-Reply-Key', email_log, :reply_key) - add_header_to_log('Discourse-Post-Id', email_log, :post_id) - add_header_to_log('Discourse-Topic-Id', email_log, :topic_id) + add_header_to_log('X-Discourse-Reply-Key', email_log, :reply_key) + add_header_to_log('X-Discourse-Post-Id', email_log, :post_id) + add_header_to_log('X-Discourse-Topic-Id', email_log, :topic_id) email_log.save! email_log diff --git a/spec/components/email/message_builder_spec.rb b/spec/components/email/message_builder_spec.rb index f3ae0437902..944100893a0 100644 --- a/spec/components/email/message_builder_spec.rb +++ b/spec/components/email/message_builder_spec.rb @@ -29,8 +29,8 @@ describe Email::MessageBuilder do context "reply by email" do context "without allow_reply_by_email" do - it "does not have a Discourse-Reply-Key" do - expect(header_args['Discourse-Reply-Key']).to be_blank + it "does not have a X-Discourse-Reply-Key" do + expect(header_args['X-Discourse-Reply-Key']).to be_blank end it "returns a Reply-To header that's the same as From" do @@ -40,7 +40,7 @@ describe Email::MessageBuilder do context "with allow_reply_by_email" do let(:reply_by_email_builder) { Email::MessageBuilder.new(to_address, allow_reply_by_email: true) } - let(:reply_key) { reply_by_email_builder.header_args['Discourse-Reply-Key'] } + let(:reply_key) { reply_by_email_builder.header_args['X-Discourse-Reply-Key'] } context "With the SiteSetting enabled" do before do @@ -48,7 +48,7 @@ describe Email::MessageBuilder do SiteSetting.stubs(:reply_by_email_address).returns("r+%{reply_key}@reply.myforum.com") end - it "has a Discourse-Reply-Key" do + it "has a X-Discourse-Reply-Key" do expect(reply_key).to be_present expect(reply_key.size).to eq(32) end @@ -63,7 +63,7 @@ describe Email::MessageBuilder do SiteSetting.stubs(:reply_by_email_enabled?).returns(false) end - it "has no Discourse-Reply-Key" do + it "has no X-Discourse-Reply-Key" do expect(reply_key).to be_blank end @@ -83,11 +83,11 @@ describe Email::MessageBuilder do post_id: 4567) } it "passes through a post_id" do - expect(message_with_header_args.header_args['Discourse-Post-Id']).to eq('4567') + expect(message_with_header_args.header_args['X-Discourse-Post-Id']).to eq('4567') end it "passes through a topic_id" do - expect(message_with_header_args.header_args['Discourse-Topic-Id']).to eq('1234') + expect(message_with_header_args.header_args['X-Discourse-Topic-Id']).to eq('1234') end end diff --git a/spec/components/email/sender_spec.rb b/spec/components/email/sender_spec.rb index 2b904b87e75..2bbc764965c 100644 --- a/spec/components/email/sender_spec.rb +++ b/spec/components/email/sender_spec.rb @@ -51,8 +51,8 @@ describe Email::Sender do context "email log with a post id and topic id" do before do - message.header['Discourse-Post-Id'] = 3344 - message.header['Discourse-Topic-Id'] = 5577 + message.header['X-Discourse-Post-Id'] = 3344 + message.header['X-Discourse-Topic-Id'] = 5577 end let(:email_log) { EmailLog.last } @@ -63,7 +63,7 @@ describe Email::Sender do context "email log with a reply key" do before do - message.header['Discourse-Reply-Key'] = reply_key + message.header['X-Discourse-Reply-Key'] = reply_key end let(:email_log) { EmailLog.last } diff --git a/spec/mailers/user_notifications_spec.rb b/spec/mailers/user_notifications_spec.rb index bc88c41d123..2ee2c4f14db 100644 --- a/spec/mailers/user_notifications_spec.rb +++ b/spec/mailers/user_notifications_spec.rb @@ -2,7 +2,7 @@ require "spec_helper" describe UserNotifications do - let(:user) { Fabricate(:user) } + let(:user) { Fabricate(:admin) } describe ".signup" do subject { UserNotifications.signup(user) }