FEATURE: Allow viewing of raw emails for reviewable queued posts (#7910)

FEATURE: Allow viewing of raw emails for reviewable queued posts (#7910)

If a post arrives via email but must be reviewed, we now show an icon that can be clicked to view the raw contents of the email.

This is useful if Discourse’s email parser is acting odd and the user reviewing the post wants to know what the original contents were before approving/rejecting the post.

diff --git a/app/assets/javascripts/discourse/components/reviewable-queued-post.js.es6 b/app/assets/javascripts/discourse/components/reviewable-queued-post.js.es6
new file mode 100644
index 0000000..1255c5b
--- /dev/null
+++ b/app/assets/javascripts/discourse/components/reviewable-queued-post.js.es6
@@ -0,0 +1,9 @@
+import showModal from "discourse/lib/show-modal";
+
+export default Ember.Component.extend({
+  actions: {
+    showRawEmail() {
+      showModal("raw-email").set("rawEmail", this.reviewable.payload.raw_email);
+    }
+  }
+});
diff --git a/app/assets/javascripts/discourse/templates/components/reviewable-queued-post.hbs b/app/assets/javascripts/discourse/templates/components/reviewable-queued-post.hbs
index fb54fe9..30aff53 100644
--- a/app/assets/javascripts/discourse/templates/components/reviewable-queued-post.hbs
+++ b/app/assets/javascripts/discourse/templates/components/reviewable-queued-post.hbs
@@ -5,6 +5,11 @@
   </div>
   {{category-badge reviewable.category}}
   {{reviewable-tags tags=reviewable.payload.tags tagName=''}}
+  {{#if reviewable.payload.via_email}}
+    <a href {{action "showRawEmail"}} class='show-raw-email'>
+      {{d-icon "far-envelope" title="post.via_email"}}
+    </a>
+  {{/if}}
 {{/reviewable-topic-link}}
 
 <div class='post-contents-wrapper'>
diff --git a/app/assets/stylesheets/common/base/reviewables.scss b/app/assets/stylesheets/common/base/reviewables.scss
index 018ea92..31071ac 100644
--- a/app/assets/stylesheets/common/base/reviewables.scss
+++ b/app/assets/stylesheets/common/base/reviewables.scss
@@ -364,6 +364,10 @@
 }
 
 .reviewable-item {
+  .show-raw-email {
+    color: $primary-medium;
+    font-size: $font-down-2;
+  }
   .post-title {
     background-color: yellow;
   }
diff --git a/app/serializers/reviewable_queued_post_serializer.rb b/app/serializers/reviewable_queued_post_serializer.rb
index ebdd4d0..c2ce6fe 100644
--- a/app/serializers/reviewable_queued_post_serializer.rb
+++ b/app/serializers/reviewable_queued_post_serializer.rb
@@ -16,7 +16,9 @@ class ReviewableQueuedPostSerializer < ReviewableSerializer
     :is_poll,
     :typing_duration_msecs,
     :composer_open_duration_msecs,
-    :tags
+    :tags,
+    :via_email,
+    :raw_email
   )
 
   def reply_to_post_number
diff --git a/lib/new_post_manager.rb b/lib/new_post_manager.rb
index ba5e468..2671230 100644
--- a/lib/new_post_manager.rb
+++ b/lib/new_post_manager.rb
@@ -201,6 +201,8 @@ class NewPostManager
     %w(typing_duration_msecs composer_open_duration_msecs reply_to_post_number).each do |a|
       payload[a] = @args[a].to_i if @args[a]
     end
+    payload[:via_email] = true if !!@args[:via_email]
+    payload[:raw_email] = @args[:raw_email] if @args[:raw_email].present?
 
     reviewable = ReviewableQueuedPost.new(
       created_by: @user,
diff --git a/spec/components/new_post_manager_spec.rb b/spec/components/new_post_manager_spec.rb
index 269ebcb..547f30c 100644
--- a/spec/components/new_post_manager_spec.rb
+++ b/spec/components/new_post_manager_spec.rb
@@ -407,4 +407,34 @@ describe NewPostManager do
       end
     end
   end
+
+  context "via email" do
+    let(:manager) do
+      NewPostManager.new(
+        topic.user,
+        raw: 'this is emailed content',
+        topic_id: topic.id,
+        via_email: true,
+        raw_email: 'raw email contents'
+      )
+    end
+
+      before do
+        SiteSetting.approve_post_count = 100
+        topic.user.trust_level = 0
+      end
+
+    it "will store via_email and raw_email in the enqueued post" do
+      result = manager.perform
+      expect(result.action).to eq(:enqueued)
+      expect(result.reviewable).to be_present
+      expect(result.reviewable.payload['via_email']).to eq(true)
+      expect(result.reviewable.payload['raw_email']).to eq('raw email contents')
+
+      post = result.reviewable.perform(Discourse.system_user, :approve_post).created_post
+      expect(post.via_email).to eq(true)
+      expect(post.raw_email).to eq("raw email contents")
+    end
+  end
+
 end
diff --git a/spec/serializers/reviewable_queued_post_serializer_spec.rb b/spec/serializers/reviewable_queued_post_serializer_spec.rb
index 83bcaac..8fa0a5a 100644
--- a/spec/serializers/reviewable_queued_post_serializer_spec.rb
+++ b/spec/serializers/reviewable_queued_post_serializer_spec.rb
@@ -49,6 +49,8 @@ describe ReviewableQueuedPostSerializer do
 
       expect(payload['raw']).to eq('hello world post contents.')
       expect(payload['title']).to be_blank
+      expect(payload['via_email']).to eq(true)
+      expect(payload['raw_email']).to eq('store_me')
       expect(json[:topic_id]).to eq(reviewable.topic_id)
       expect(json[:topic_url]).to eq(reviewable.topic.url)
       expect(json[:can_edit]).to eq(true)

GitHub sha: e47e0af1

1 Like