-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
157 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
class RobotsController < ApplicationController | ||
before_action :authenticate_user!, except: :show | ||
before_action :find_robots_txt | ||
before_action :throw_breadcrumbs, except: :show | ||
layout 'hyrax/dashboard' | ||
|
||
def show | ||
render body: @robots_txt.value | ||
end | ||
|
||
def edit | ||
authorize! :edit, @robots_txt | ||
end | ||
|
||
def update | ||
authorize! :update, @robots_txt | ||
respond_to do |format| | ||
if @robots_txt.update(permitted_params) | ||
format.html { redirect_to edit_robots_path, notice: 'robots.txt updated.' } | ||
else | ||
flash.now[:alert] = "robots.txt could not be updated. #{@robots_txt.errors.full_messages}" | ||
format.html { render :edit } | ||
end | ||
end | ||
end | ||
|
||
private | ||
|
||
def find_robots_txt | ||
@robots_txt = ContentBlock.find_or_create_by(name: 'robots_txt') | ||
end | ||
|
||
def throw_breadcrumbs | ||
add_breadcrumb t(:'hyrax.controls.home'), root_path | ||
add_breadcrumb t(:'hyrax.dashboard.breadcrumbs.admin'), hyrax.dashboard_path | ||
add_breadcrumb t(:'hyrax.admin.sidebar.configuration'), '#' | ||
add_breadcrumb 'robots.txt', edit_robots_path | ||
end | ||
|
||
def permitted_params | ||
params.require(:content_block).permit(:value) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<div class="panel panel-default tabs"> | ||
<div class="tab-content"> | ||
<div id="about" class="tab-pane active"> | ||
<div class="panel panel-default labels"> | ||
<%= simple_form_for @robots_txt, url: robots_path do |f| %> | ||
<div class="panel-body"> | ||
<div class="field form-group"> | ||
<%= f.label :value, 'robots.txt' %><br /> | ||
<%= f.text_area :value, value: f.object.value, class: 'form-control', rows: 20, cols: 120 %> | ||
</div> | ||
</div> | ||
<div class="panel-footer"> | ||
<%= link_to t(:'hyrax.pages.cancel'), hyrax.dashboard_path, class: 'btn btn-default pull-right' %> | ||
<%= f.button :submit, class: 'btn btn-primary pull-right' %> | ||
</div> | ||
<% end %> | ||
</div> | ||
</div> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<% content_for :page_header do %> | ||
<h1><span class="fa fa-sitemap" aria-hidden="true"></span> Editing robots.txt</h1> | ||
<% end %> | ||
|
||
<div class="row"> | ||
<div class="col-md-12"> | ||
<%= render 'form' %> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
require 'rails_helper' | ||
|
||
describe RobotsController do | ||
let(:user) { create(:user) } | ||
let(:admin) { create(:admin) } | ||
let(:robots_txt) { ContentBlock.create(name: 'robots_txt', value: content) } | ||
let(:content) { "User-Agent: *\nDisallow: /concern" } | ||
|
||
after do | ||
ContentBlock.delete('robots_txt') | ||
end | ||
|
||
describe '#show' do | ||
it 'is blank by default' do | ||
get :show | ||
expect(response).to be_successful | ||
expect(response.body).to eq '' | ||
end | ||
|
||
it 'renders the value' do | ||
robots_txt | ||
get :show | ||
expect(response).to be_successful | ||
expect(response.body).to eq content | ||
end | ||
|
||
it 'is route for /robots.txt', type: :routing do | ||
expect(get: '/robots.txt').to route_to(controller: 'robots', action: 'show', format: 'txt') | ||
end | ||
end | ||
|
||
describe '#edit' do | ||
it 'is unavailable to the public' do | ||
get :edit | ||
expect(response).to redirect_to(new_user_session_path(locale: nil)) | ||
end | ||
|
||
it 'is unavailable to regular users' do | ||
sign_in user | ||
get :edit | ||
expect(response).to be_unauthorized | ||
end | ||
|
||
context 'with rendering' do | ||
render_views | ||
it 'is rendered for admins' do | ||
robots_txt | ||
sign_in admin | ||
get :edit | ||
expect(response).to be_successful | ||
expect(response.body).to include(content) | ||
end | ||
end | ||
end | ||
|
||
describe '#update' do | ||
let(:new_content) { 'Disallow: *' } | ||
|
||
it 'is unavailable to the public' do | ||
patch :update, params: { content_block: { value: new_content } } | ||
expect(response).to redirect_to(new_user_session_path(locale: nil)) | ||
end | ||
|
||
it 'is unavailable to regular users' do | ||
sign_in user | ||
patch :update, params: { content_block: { value: new_content } } | ||
expect(response).to be_unauthorized | ||
end | ||
|
||
it 'is updated for admins' do | ||
robots_txt | ||
sign_in admin | ||
patch :update, params: { content_block: { value: new_content } } | ||
expect(response).to redirect_to(edit_robots_path) | ||
get :show | ||
expect(response.body).to eq new_content | ||
end | ||
end | ||
end |