diff --git a/app/assets/javascripts/discourse/controllers/raw-email.js.es6 b/app/assets/javascripts/discourse/controllers/raw-email.js.es6 index 24fa2eb85b4..01f637a7bec 100644 --- a/app/assets/javascripts/discourse/controllers/raw-email.js.es6 +++ b/app/assets/javascripts/discourse/controllers/raw-email.js.es6 @@ -14,10 +14,10 @@ import ObjectController from 'discourse/controllers/object'; export default ObjectController.extend(ModalFunctionality, { raw_email: "", - loadEmail: function(postId) { + loadRawEmail: function(postId) { var self = this; - Discourse.Post.load(postId).then(function (result) { - self.set("raw_email", result.get('raw_email')); + Discourse.Post.loadRawEmail(postId).then(function (raw_email) { + self.set("raw_email", raw_email); }); } diff --git a/app/assets/javascripts/discourse/models/_post.js b/app/assets/javascripts/discourse/models/_post.js index ec9bfbbb38b..118afce2997 100644 --- a/app/assets/javascripts/discourse/models/_post.js +++ b/app/assets/javascripts/discourse/models/_post.js @@ -490,6 +490,12 @@ Discourse.Post.reopenClass({ }); }, + loadRawEmail: function(postId) { + return Discourse.ajax("/posts/" + postId + "/raw-email").then(function (result) { + return result.raw_email; + }); + }, + load: function(postId) { return Discourse.ajax("/posts/" + postId + ".json").then(function (result) { return Discourse.Post.create(result); diff --git a/app/assets/javascripts/discourse/routes/topic_route.js b/app/assets/javascripts/discourse/routes/topic_route.js index 23aab8a89d6..462845ef71f 100644 --- a/app/assets/javascripts/discourse/routes/topic_route.js +++ b/app/assets/javascripts/discourse/routes/topic_route.js @@ -75,7 +75,7 @@ Discourse.TopicRoute = Discourse.Route.extend({ showRawEmail: function(post) { Discourse.Route.showModal(this, 'raw-email', post); - this.controllerFor('raw_email').loadEmail(post.get("id")); + this.controllerFor('raw_email').loadRawEmail(post.get("id")); }, mergeTopic: function() { diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb index e52b5f0fd5b..14fbc4acbf6 100644 --- a/app/controllers/posts_controller.rb +++ b/app/controllers/posts_controller.rb @@ -30,6 +30,12 @@ class PostsController < ApplicationController render json: {cooked: post.cooked} end + def raw_email + guardian.ensure_can_view_raw_email! + post = Post.find(params[:id].to_i) + render json: {raw_email: post.raw_email} + end + def short_link post = Post.find(params[:post_id].to_i) # Stuff the user in the request object, because that's what IncomingLink wants diff --git a/app/serializers/post_serializer.rb b/app/serializers/post_serializer.rb index 72bb4a7082e..3ee7ba875c1 100644 --- a/app/serializers/post_serializer.rb +++ b/app/serializers/post_serializer.rb @@ -51,8 +51,7 @@ class PostSerializer < BasicPostSerializer :wiki, :user_custom_fields, :static_doc, - :via_email, - :raw_email + :via_email def topic_slug object.try(:topic).try(:slug) diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml index 43d28447688..debf4e5d23d 100644 --- a/config/locales/client.en.yml +++ b/config/locales/client.en.yml @@ -1384,7 +1384,6 @@ en: history: "History" changed_by: "by {{author}}" - raw_email: title: "Raw Email" not_available: "Not available!" diff --git a/config/routes.rb b/config/routes.rb index eadb0eef195..2af656916bb 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -416,6 +416,7 @@ Discourse::Application.routes.draw do get "/posts/:id/cooked" => "posts#cooked" get "/posts/:id/expand-embed" => "posts#expand_embed" get "/posts/:id/raw" => "posts#markdown_id" + get "/posts/:id/raw-email" => "posts#raw_email" get "raw/:topic_id(/:post_number)" => "posts#markdown_num" resources :invites do diff --git a/lib/guardian/post_guardian.rb b/lib/guardian/post_guardian.rb index 4da4acf03d8..7eae1a89f3b 100644 --- a/lib/guardian/post_guardian.rb +++ b/lib/guardian/post_guardian.rb @@ -193,6 +193,10 @@ module PostGuardian is_staff? end + def can_view_raw_email? + is_staff? + end + def can_unhide?(post) post.try(:hidden) && is_staff? end