diff --git a/app/controllers/errors_controller.rb b/app/controllers/errors_controller.rb new file mode 100644 index 0000000..cb67cff --- /dev/null +++ b/app/controllers/errors_controller.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +class ErrorsController < ApplicationController + def not_found + render '/errors/not_found', status: 404 + end +end diff --git a/app/views/errors/not_found.html.erb b/app/views/errors/not_found.html.erb new file mode 100644 index 0000000..942788e --- /dev/null +++ b/app/views/errors/not_found.html.erb @@ -0,0 +1,30 @@ +
+
+
+

404: Page not found

+
+
+

Looks like something went wrong...

+

The link you have may be incorrect, or the page you're looking for may + have been removed or renamed.

+ +
+
+

Find the page name

+

Use the search bar to locate the page by name.

+
+
+

Start over

+

Try + <%= link_to "starting from the homepage", "/" %>.

+
+
+

Contact us

+

Reach out using the + <%= link_to "contact form", "/contact" %> + to let us know what you were looking for.

+
+
+
+
+
diff --git a/config/routes.rb b/config/routes.rb index a65cc9e..185da92 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -19,7 +19,9 @@ end devise_for :users mount Hydra::RoleManagement::Engine => '/' - mount Sidekiq::Web => '/sidekiq' + authenticate :user, ->(u) { u.admin? } do + mount Sidekiq::Web => '/sidekiq' + end mount Qa::Engine => '/authorities' mount Hyrax::Engine, at: '/' resources :welcome, only: 'index' @@ -40,5 +42,7 @@ collection { delete 'clear' } end + + match '*path', to: 'errors#not_found', via: :all, format: false, defaults: { format: 'html' } # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html end diff --git a/spec/features/sidekiq_dashboard_access_spec.rb b/spec/features/sidekiq_dashboard_access_spec.rb new file mode 100644 index 0000000..96e65e8 --- /dev/null +++ b/spec/features/sidekiq_dashboard_access_spec.rb @@ -0,0 +1,30 @@ +require 'rails_helper' + +RSpec.describe 'Sidekiq Dashboard Access' do + it 'loads sidekiq dashboard for a logged in admin user' do + admin_user = User.create(email: 'admin@example.com', password: 'password') + admin_user.roles << Role.find_or_create_by(name: 'admin') + + sign_in_user(admin_user) + + visit('/sidekiq') + + expect(current_path).to eq('/sidekiq') + end + + it 'redirects users to sign-in page if not logged in as admin' do + visit('/sidekiq') + + expect(current_path).to eq('/users/sign_in') + end + + it 'redirects to a 404 page if visited by logged in non-admin user' do + non_admin_user = User.create(email: 'not_an_admin@example.com', password: 'password') + + sign_in_user(non_admin_user) + + visit('/sidekiq') + + expect(page).to have_content('404: Page not found') + end +end