diff --git a/app/controllers/robots_controller.rb b/app/controllers/robots_controller.rb new file mode 100644 index 000000000..791986559 --- /dev/null +++ b/app/controllers/robots_controller.rb @@ -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 \ No newline at end of file diff --git a/app/views/hyrax/dashboard/sidebar/_configuration.html.erb b/app/views/hyrax/dashboard/sidebar/_configuration.html.erb new file mode 100644 index 000000000..b1cf1e458 --- /dev/null +++ b/app/views/hyrax/dashboard/sidebar/_configuration.html.erb @@ -0,0 +1,39 @@ + <% if menu.show_configuration? %> +