diff --git a/app/assets/javascripts/discourse/controllers/static.js.es6 b/app/assets/javascripts/discourse/controllers/static.js.es6 index 0dd1f25b609..f2e18692d0a 100644 --- a/app/assets/javascripts/discourse/controllers/static.js.es6 +++ b/app/assets/javascripts/discourse/controllers/static.js.es6 @@ -3,7 +3,9 @@ export default Em.ObjectController.extend({ actions: { markFaqRead: function() { - Discourse.ajax("/users/read-faq", { method: "POST" }); + if (Discourse.User.current()) { + Discourse.ajax("/users/read-faq", { method: "POST" }); + } } } }); diff --git a/app/controllers/topics_controller.rb b/app/controllers/topics_controller.rb index 6818f79560b..721f0373c7c 100644 --- a/app/controllers/topics_controller.rb +++ b/app/controllers/topics_controller.rb @@ -55,9 +55,11 @@ class TopicsController < ApplicationController begin @topic_view = TopicView.new(params[:id] || params[:topic_id], current_user, opts) rescue Discourse::NotFound - topic = Topic.find_by(slug: params[:id].downcase) if params[:id] - raise Discourse::NotFound unless topic - redirect_to_correct_topic(topic, opts[:post_number]) && return + if params[:id] + topic = Topic.find_by(slug: params[:id].downcase) + return redirect_to_correct_topic(topic, opts[:post_number]) if topic + end + raise Discourse::NotFound end page = params[:page].to_i @@ -150,8 +152,9 @@ class TopicsController < ApplicationController [:title, :raw].each { |key| check_length_of(key, params[key]) } # Only suggest similar topics if the site has a minimum amount of topics present. - topics = Topic.similar_to(title, raw, current_user).to_a if Topic.count_exceeds_minimum? + return render json: [] unless Topic.count_exceeds_minimum? + topics = Topic.similar_to(title, raw, current_user).to_a render_serialized(topics, BasicTopicSerializer) end diff --git a/spec/controllers/posts_controller_spec.rb b/spec/controllers/posts_controller_spec.rb index 651efcb362b..aee2f0a01f2 100644 --- a/spec/controllers/posts_controller_spec.rb +++ b/spec/controllers/posts_controller_spec.rb @@ -799,4 +799,26 @@ describe PostsController do end + describe "view raw" do + describe "by ID" do + it "can be viewed by anonymous" do + post = Fabricate(:post, raw: "123456789") + xhr :get, :markdown_id, id: post.id + response.should be_success + response.body.should == "123456789" + end + end + + describe "by post number" do + it "can be viewed by anonymous" do + topic = Fabricate(:topic) + post = Fabricate(:post, topic: topic, post_number: 1, raw: "123456789") + post.save + xhr :get, :markdown_num, topic_id: topic.id, post_number: 1 + response.should be_success + response.body.should == "123456789" + end + end + end + end