diff --git a/app/controllers/staff/home_controller.rb b/app/controllers/staff/home_controller.rb new file mode 100644 index 0000000..bdd16f0 --- /dev/null +++ b/app/controllers/staff/home_controller.rb @@ -0,0 +1,8 @@ +# frozen_string_literal: true + +class Staff::HomeController < ApplicationController + # GET /staff + def show + authorize %i[staff home] + end +end diff --git a/app/policies/staff/home_policy.rb b/app/policies/staff/home_policy.rb new file mode 100644 index 0000000..a45fe29 --- /dev/null +++ b/app/policies/staff/home_policy.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +class Staff::HomePolicy < ApplicationPolicy + def show? + account&.is_superuser? + end +end diff --git a/app/views/staff/home/show.html.erb b/app/views/staff/home/show.html.erb new file mode 100644 index 0000000..a23ca3d --- /dev/null +++ b/app/views/staff/home/show.html.erb @@ -0,0 +1,2 @@ +
+
diff --git a/config/routes.rb b/config/routes.rb index 8e06ff6..9a5d42a 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -44,6 +44,8 @@ Rails.application.routes.draw do ######################### namespace :staff do + root to: 'home#show' + authenticate :user, ->(user) { user.account.can_access_sidekiq_web_interface? } do mount Sidekiq::Web, at: '/sidekiq', as: :sidekiq diff --git a/spec/policies/staff/home_policy_spec.rb b/spec/policies/staff/home_policy_spec.rb new file mode 100644 index 0000000..1d42faa --- /dev/null +++ b/spec/policies/staff/home_policy_spec.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +require 'rails_helper' + +RSpec.describe Staff::HomePolicy do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/requests/staff/root_spec.rb b/spec/requests/staff/root_spec.rb new file mode 100644 index 0000000..8fd2c1d --- /dev/null +++ b/spec/requests/staff/root_spec.rb @@ -0,0 +1,26 @@ +# frozen_string_literal: true + +require 'rails_helper' + +RSpec.describe 'GET /staff' do + def make_request + get '/staff' + end + + before do + sign_in current_account.user if current_account&.user + make_request + end + + for_account_types nil, :guest, :usual do + specify do + expect(response).to have_http_status :forbidden + end + end + + for_account_types :superuser do + specify do + expect(response).to have_http_status :ok + end + end +end