diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb index 34a5a8c35..b33655d34 100644 --- a/app/controllers/posts_controller.rb +++ b/app/controllers/posts_controller.rb @@ -70,6 +70,8 @@ class PostsController < ApplicationController user = User.find(params[:user_id].to_i) request['u'] = user.username_lower if user end + + guardian.ensure_can_see!(post) redirect_to post.url end diff --git a/spec/controllers/posts_controller_spec.rb b/spec/controllers/posts_controller_spec.rb index aee2f0a01..14210d0a6 100644 --- a/spec/controllers/posts_controller_spec.rb +++ b/spec/controllers/posts_controller_spec.rb @@ -821,4 +821,19 @@ describe PostsController do end end + describe "short link" do + let(:topic) { Fabricate(:topic) } + let(:post) { Fabricate(:post, topic: topic) } + + it "redirects to the topic" do + xhr :get, :short_link, post_id: post.id + response.should be_redirect + end + + it "returns a 403 when access is denied" do + Guardian.any_instance.stubs(:can_see?).returns(false) + xhr :get, :short_link, post_id: post.id + response.should be_forbidden + end + end end