FEATURE: support linking to a specific revision of a topic/post

This commit is contained in:
Arpit Jalan 2015-10-19 14:31:29 +05:30
parent dfe3ecb914
commit 49edffd3c3
1 changed files with 22 additions and 1 deletions

View File

@ -16,8 +16,13 @@ class PostsController < ApplicationController
end end
def markdown_num def markdown_num
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) markdown Post.find_by(topic_id: params[:topic_id].to_i, post_number: (params[:post_number] || 1).to_i)
end end
end
def markdown(post) def markdown(post)
if post && guardian.can_see?(post) if post && guardian.can_see?(post)
@ -403,6 +408,22 @@ class PostsController < ApplicationController
post_revision post_revision
end 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 private
def user_posts(guardian, user_id, opts) def user_posts(guardian, user_id, opts)