Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions app/controllers/errors_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# frozen_string_literal: true

class ErrorsController < ApplicationController
def not_found
render '/errors/not_found', status: 404
end
end
30 changes: 30 additions & 0 deletions app/views/errors/not_found.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<div class="container">
<div class="error-container">
<div class="error-header">
<h1>404: Page not found</h1>
</div>
<div class="error-content">
<p>Looks like something went wrong...</p>
<p>The link you have may be incorrect, or the page you're looking for may
have been removed or renamed.</p>
<h2 class="broken-links">Solutions for broken links</h2>
<div class="options">
<div class="option">
<h3>Find the page name</h3>
<p>Use the search bar to locate the page by name.</p>
</div>
<div class="option">
<h3>Start over</h3>
<p>Try
<%= link_to "starting from the homepage", "/" %>.</p>
</div>
<div class="option">
<h3>Contact us</h3>
<p>Reach out using the
<%= link_to "contact form", "/contact" %>
to let us know what you were looking for.</p>
</div>
</div>
</div>
</div>
</div>
6 changes: 5 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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
30 changes: 30 additions & 0 deletions spec/features/sidekiq_dashboard_access_spec.rb
Original file line number Diff line number Diff line change
@@ -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
Loading