diff --git a/app/controllers/post_history_controller.rb b/app/controllers/post_history_controller.rb index 80a37de1c..543771e02 100644 --- a/app/controllers/post_history_controller.rb +++ b/app/controllers/post_history_controller.rb @@ -8,7 +8,28 @@ def post @history = PostHistory.where(post_id: params[:id]) .includes(:post_history_type, :user, post_history_tags: [:tag]) - .order(created_at: :desc, id: :desc).paginate(per_page: 20, page: params[:page]) - render layout: 'without_sidebar' + .order(created_at: :desc, id: :desc) + .paginate(per_page: 20, page: params[:page]) + + if @post&.help_category.nil? + render layout: 'without_sidebar' + else + render 'post_history/post', layout: 'without_sidebar', locals: { show_content: false } + end + end + + def slug_post + @post = Post.by_slug(params[:slug], current_user) + + if @post.nil? + return not_found + end + + @history = PostHistory.where(post_id: @post.id) + .includes(:post_history_type, :user) + .order(created_at: :desc, id: :desc) + .paginate(per_page: 20, page: params[:page]) + + render 'post_history/post', layout: 'without_sidebar', locals: { show_content: false } end end diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb index 79e03f7b1..5e8b293a8 100644 --- a/app/controllers/posts_controller.rb +++ b/app/controllers/posts_controller.rb @@ -464,13 +464,9 @@ def restore end def document - @post = Post.unscoped.where(doc_slug: params[:slug], community_id: [RequestContext.community_id, nil]).first - not_found && return if @post.nil? + @post = Post.by_slug(params[:slug], current_user) - if @post&.help_category == '$Disabled' - not_found - end - if @post&.help_category == '$Moderator' && !current_user&.is_moderator + if @post.nil? not_found end diff --git a/app/models/post.rb b/app/models/post.rb index 54d1c1e5b..436e84812 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -63,6 +63,23 @@ def self.search(term) match_search term, posts: :body_markdown end + def self.by_slug(slug, user) + post = Post.unscoped.where( + doc_slug: slug, + community_id: [RequestContext.community_id, nil] + ).first + + if post&.help_category == '$Disabled' + return nil + end + + if post&.help_category == '$Moderator' && !user&.is_moderator + return nil + end + + post + end + # Double-define: initial definitions are less efficient, so if we have a record of the post type we'll # override them later with more efficient methods. ['Question', 'Answer', 'PolicyDoc', 'HelpDoc', 'Article'].each do |pt| diff --git a/app/views/post_history/post.html.erb b/app/views/post_history/post.html.erb index c2a5d1e54..c31b586ea 100644 --- a/app/views/post_history/post.html.erb +++ b/app/views/post_history/post.html.erb @@ -1,8 +1,12 @@ +<% @show_content = !!defined?(show_content) ? show_content : true %> +