mirror of
https://github.com/Freika/dawarich.git
synced 2026-01-10 17:21:38 -05:00
Handle Sidekiq access for non-admin users
This commit is contained in:
parent
2d2eeda9e7
commit
9c2d2b8c02
2 changed files with 47 additions and 0 deletions
|
|
@ -9,6 +9,12 @@ Rails.application.routes.draw do
|
|||
mount Sidekiq::Web => '/sidekiq'
|
||||
end
|
||||
|
||||
# We want to return a nice error message if the user is not authorized to access Sidekiq
|
||||
match '/sidekiq' => redirect { |_, request|
|
||||
request.flash[:error] = 'You are not authorized to perform this action.'
|
||||
'/'
|
||||
}, via: :get
|
||||
|
||||
resources :settings, only: :index
|
||||
namespace :settings do
|
||||
resources :background_jobs, only: %i[index create destroy]
|
||||
|
|
|
|||
41
spec/requests/sidekiq_spec.rb
Normal file
41
spec/requests/sidekiq_spec.rb
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe '/sidekiq', type: :request do
|
||||
context 'when user is not authenticated' do
|
||||
it 'redirects to sign in page' do
|
||||
get sidekiq_url
|
||||
|
||||
expect(response).to redirect_to('/users/sign_in')
|
||||
end
|
||||
end
|
||||
|
||||
context 'when user is authenticated' do
|
||||
context 'when user is not admin' do
|
||||
before { sign_in create(:user) }
|
||||
|
||||
it 'redirects to root page' do
|
||||
get sidekiq_url
|
||||
|
||||
expect(response).to redirect_to(root_url)
|
||||
end
|
||||
|
||||
it 'shows flash message' do
|
||||
get sidekiq_url
|
||||
|
||||
expect(flash[:error]).to eq('You are not authorized to perform this action.')
|
||||
end
|
||||
end
|
||||
|
||||
context 'when user is admin' do
|
||||
before { sign_in create(:user, :admin) }
|
||||
|
||||
it 'renders a successful response' do
|
||||
get sidekiq_url
|
||||
|
||||
expect(response).to be_successful
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Loading…
Reference in a new issue