From 49edffd3c38629c631d6088b009e9e416f7c26e7 Mon Sep 17 00:00:00 2001 From: Arpit Jalan Date: Mon, 19 Oct 2015 14:31:29 +0530 Subject: [PATCH] FEATURE: support linking to a specific revision of a topic/post --- app/controllers/posts_controller.rb | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb index 3295fb7e46a..6bc22d2c74d 100644 --- a/app/controllers/posts_controller.rb +++ b/app/controllers/posts_controller.rb @@ -16,7 +16,12 @@ class PostsController < ApplicationController end def markdown_num - markdown Post.find_by(topic_id: params[:topic_id].to_i, post_number: (params[:post_number] || 1).to_i) + if params[:revision].present? + post_revision = find_post_revision_from_topic_id + render text: post_revision.modifications[:raw].last, content_type: 'text/plain' + else + markdown Post.find_by(topic_id: params[:topic_id].to_i, post_number: (params[:post_number] || 1).to_i) + end end def markdown(post) @@ -403,6 +408,22 @@ class PostsController < ApplicationController post_revision end + def find_post_revision_from_topic_id + post = Post.find_by(topic_id: params[:topic_id].to_i, post_number: (params[:post_number] || 1).to_i) + raise Discourse::NotFound unless guardian.can_see?(post) + + revision = params[:revision].to_i + raise Discourse::NotFound if revision < 2 + + post_revision = PostRevision.find_by(post_id: post.id, number: revision) + raise Discourse::NotFound unless post_revision + + post_revision.post = post + guardian.ensure_can_see!(post_revision) + + post_revision + end + private def user_posts(guardian, user_id, opts)