Skip to content

Commit

Permalink
not allow googlebot to make queries
Browse files Browse the repository at this point in the history
not allow googlebot to make queries
  • Loading branch information
kjgarza committed Jan 31, 2020
1 parent b6c2ef4 commit b3fd503
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ gem "google-protobuf", "3.10.0.rc.1"
gem "sprockets", "~> 3.7", ">= 3.7.2"
gem 'uuid', '~> 2.3', '>= 2.3.9'
gem 'strong_migrations', '~> 0.6.0'
gem 'crawler_detect'



group :development, :test do
gem "rspec-rails", "~> 3.8", ">= 3.8.2"
Expand Down
8 changes: 8 additions & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ def set_jsonp_format
end
end

def detect_crawler
#### Crawlers shound't be making queires
if request.is_crawler? && params[:query].present?
render json: {}, status: :not_found
end
end


def set_consumer_header
if current_user
response.headers['X-Credential-Username'] = current_user.uid
Expand Down
1 change: 1 addition & 0 deletions app/controllers/events_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class EventsController < ApplicationController
include BatchLoaderHelper

prepend_before_action :authenticate_user!, except: [:index, :show]
before_action :detect_crawler
before_action :load_event, only: [:show, :destroy]
before_action :set_include, only: [:index, :show, :create, :update]
authorize_resource only: [:destroy]
Expand Down
1 change: 1 addition & 0 deletions app/controllers/old_events_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class OldEventsController < ApplicationController
include Facetable

prepend_before_action :authenticate_user!, except: [:index, :show]
before_action :detect_crawler
before_action :load_event, only: [:show, :destroy]
before_action :set_include, only: [:index, :show, :create, :update]
authorize_resource only: [:destroy]
Expand Down
14 changes: 14 additions & 0 deletions spec/requests/events_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -923,6 +923,20 @@
# expect(attributes["subj-id"]).to eq(event.subj_id)
# end
# end
context "query by source-id by Crawler" do
let(:uri) { "/events?query=datacite" }

# Exclude the token header.
let(:headers) do
{ "HTTP_ACCEPT" => "application/json",
"HTTP_USER_AGENT" => "Mozilla/5.0 (Linux; Android 6.0.1; Nexus 5X Build/MMB29P) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.96 Mobile Safari/537.36 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)" }
end

it "json" do
get uri, nil, headers
expect(last_response.status).to eq(404)
end
end
end

context "destroy" do
Expand Down

0 comments on commit b3fd503

Please sign in to comment.