diff --git a/app/assets/javascripts/discourse/controllers/topic_controller.js b/app/assets/javascripts/discourse/controllers/topic_controller.js index 73c68545ca3..84c456c82b6 100644 --- a/app/assets/javascripts/discourse/controllers/topic_controller.js +++ b/app/assets/javascripts/discourse/controllers/topic_controller.js @@ -294,6 +294,10 @@ Discourse.TopicController = Discourse.ObjectController.extend(Discourse.Selected }); }, + expandHidden: function(post) { + post.expandHidden(); + }, + toggleVisibility: function() { this.get('content').toggleStatus('visible'); }, diff --git a/app/assets/javascripts/discourse/models/post.js b/app/assets/javascripts/discourse/models/post.js index f537ccfcb62..05fd6d7c2d7 100644 --- a/app/assets/javascripts/discourse/models/post.js +++ b/app/assets/javascripts/discourse/models/post.js @@ -396,7 +396,17 @@ Discourse.Post = Discourse.Model.extend({ var topic = this.get('topic'); return !topic.isReplyDirectlyBelow(this); - }.property('reply_count') + }.property('reply_count'), + + expandHidden: function() { + var self = this; + return Discourse.ajax("/posts/" + this.get('id') + "/cooked.json").then(function (result) { + self.setProperties({ + cooked: result.cooked, + cooked_hidden: false + }); + }); + } }); Discourse.Post.reopenClass({ diff --git a/app/assets/javascripts/discourse/templates/post.js.handlebars b/app/assets/javascripts/discourse/templates/post.js.handlebars index d1dfbfaf8e5..b841a84912e 100644 --- a/app/assets/javascripts/discourse/templates/post.js.handlebars +++ b/app/assets/javascripts/discourse/templates/post.js.handlebars @@ -63,7 +63,12 @@
-
{{{cooked}}}
+
+ {{{cooked}}} +
+ {{#if cooked_hidden}} + {{i18n post.show_hidden}} + {{/if}} {{#if view.showExpandButton}} {{#if controller.loadingExpanded}} diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb index a88d8d151ec..1241d5d1ba7 100644 --- a/app/controllers/posts_controller.rb +++ b/app/controllers/posts_controller.rb @@ -5,7 +5,7 @@ require_dependency 'distributed_memoizer' class PostsController < ApplicationController # Need to be logged in for all actions here - before_filter :ensure_logged_in, except: [:show, :replies, :by_number, :short_link, :reply_history, :revisions, :expand_embed, :markdown] + before_filter :ensure_logged_in, except: [:show, :replies, :by_number, :short_link, :reply_history, :revisions, :expand_embed, :markdown, :raw, :cooked] skip_before_filter :store_incoming_links, only: [:short_link] skip_before_filter :check_xhr, only: [:markdown,:short_link] @@ -19,6 +19,11 @@ class PostsController < ApplicationController end end + def cooked + post = find_post_from_params + render json: {cooked: post.cooked} + end + def short_link post = Post.find(params[:post_id].to_i) IncomingLink.add(request,current_user) diff --git a/app/serializers/basic_post_serializer.rb b/app/serializers/basic_post_serializer.rb index 22a8600097d..04b91ecad48 100644 --- a/app/serializers/basic_post_serializer.rb +++ b/app/serializers/basic_post_serializer.rb @@ -6,7 +6,8 @@ class BasicPostSerializer < ApplicationSerializer :avatar_template, :uploaded_avatar_id, :created_at, - :cooked + :cooked, + :cooked_hidden def name object.user.try(:name) @@ -24,8 +25,15 @@ class BasicPostSerializer < ApplicationSerializer object.user.try(:uploaded_avatar_id) end + def cooked_hidden + object.hidden && !scope.is_staff? + end + def include_cooked_hidden? + cooked_hidden + end + def cooked - if object.hidden && !scope.is_staff? + if cooked_hidden if scope.current_user && object.user_id == scope.current_user.id I18n.t('flagging.you_must_edit') else diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml index 11f76e011c0..c1f48d1b642 100644 --- a/config/locales/client.en.yml +++ b/config/locales/client.en.yml @@ -953,6 +953,7 @@ en: continue_discussion: "Continuing the discussion from {{postLink}}:" follow_quote: "go to the quoted post" show_full: "Show Full Post" + show_hidden: 'View hidden content.' deleted_by_author: one: "(post withdrawn by author, will be automatically deleted in %{count} hour unless flagged)" other: "(post withdrawn by author, will be automatically deleted in %{count} hours unless flagged)" diff --git a/config/routes.rb b/config/routes.rb index 615308be3e4..e3278f4e4d7 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -361,6 +361,7 @@ Discourse::Application.routes.draw do post "t/:topic_id/notifications" => "topics#set_notifications" , constraints: {topic_id: /\d+/} + get "/posts/:id/cooked" => "posts#cooked" get "/posts/:id/expand-embed" => "posts#expand_embed" get "raw/:topic_id(/:post_number)" => "posts#markdown" diff --git a/spec/controllers/posts_controller_spec.rb b/spec/controllers/posts_controller_spec.rb index 914c9b69d9e..fec4e21834d 100644 --- a/spec/controllers/posts_controller_spec.rb +++ b/spec/controllers/posts_controller_spec.rb @@ -57,6 +57,21 @@ describe PostsController do end end + describe 'cooked' do + before do + post = Post.new(cooked: 'wat') + PostsController.any_instance.expects(:find_post_from_params).returns(post) + end + + it 'returns the cooked conent' do + xhr :get, :cooked, id: 1234 + response.should be_success + json = ::JSON.parse(response.body) + json.should be_present + json['cooked'].should == 'wat' + end + end + describe 'show' do include_examples 'finding and showing post' do let(:action) { :show }