Admin base controller (#1465)

* Add Admin::BaseController to wrap admin area

Extracts the setting of the `admin` layout and verifying that users are admins
to a common base class for the admin/ controllers.

* Add basic coverage for admin/reports and admin/settings controllers
master
Matt Jankowski 8 years ago committed by Eugen
parent 1be6aa0c7f
commit dbe9f33fdc
  1. 7
      app/controllers/admin/accounts_controller.rb
  2. 9
      app/controllers/admin/base_controller.rb
  3. 8
      app/controllers/admin/domain_blocks_controller.rb
  4. 8
      app/controllers/admin/pubsubhubbub_controller.rb
  5. 7
      app/controllers/admin/reports_controller.rb
  6. 8
      app/controllers/admin/settings_controller.rb
  7. 14
      spec/controllers/admin/reports_controller_spec.rb
  8. 14
      spec/controllers/admin/settings_controller_spec.rb

@ -1,11 +1,9 @@
# frozen_string_literal: true
class Admin::AccountsController < ApplicationController
before_action :require_admin!
module Admin
class AccountsController < BaseController
before_action :set_account, except: :index
layout 'admin'
def index
@accounts = Account.alphabetic.paginate(page: params[:page], per_page: 40)
@ -48,4 +46,5 @@ class Admin::AccountsController < ApplicationController
def account_params
params.require(:account).permit(:silenced, :suspended)
end
end
end

@ -0,0 +1,9 @@
# frozen_string_literal: true
module Admin
class BaseController < ApplicationController
before_action :require_admin!
layout 'admin'
end
end

@ -1,10 +1,7 @@
# frozen_string_literal: true
class Admin::DomainBlocksController < ApplicationController
before_action :require_admin!
layout 'admin'
module Admin
class DomainBlocksController < BaseController
def index
@blocks = DomainBlock.paginate(page: params[:page], per_page: 40)
end
@ -29,4 +26,5 @@ class Admin::DomainBlocksController < ApplicationController
def resource_params
params.require(:domain_block).permit(:domain, :severity)
end
end
end

@ -1,11 +1,9 @@
# frozen_string_literal: true
class Admin::PubsubhubbubController < ApplicationController
before_action :require_admin!
layout 'admin'
module Admin
class PubsubhubbubController < BaseController
def index
@subscriptions = Subscription.order('id desc').includes(:account).paginate(page: params[:page], per_page: 40)
end
end
end

@ -1,11 +1,9 @@
# frozen_string_literal: true
class Admin::ReportsController < ApplicationController
before_action :require_admin!
module Admin
class ReportsController < BaseController
before_action :set_report, except: [:index]
layout 'admin'
def index
@reports = Report.includes(:account, :target_account).order('id desc').paginate(page: params[:page], per_page: 40)
@reports = params[:action_taken].present? ? @reports.resolved : @reports.unresolved
@ -42,4 +40,5 @@ class Admin::ReportsController < ApplicationController
def set_report
@report = Report.find(params[:id])
end
end
end

@ -1,10 +1,7 @@
# frozen_string_literal: true
class Admin::SettingsController < ApplicationController
before_action :require_admin!
layout 'admin'
module Admin
class SettingsController < BaseController
def index
@settings = Setting.all_as_records
end
@ -32,4 +29,5 @@ class Admin::SettingsController < ApplicationController
def settings_params
params.require(:setting).permit(:value)
end
end
end

@ -0,0 +1,14 @@
require 'rails_helper'
RSpec.describe Admin::ReportsController, type: :controller do
describe 'GET #index' do
before do
sign_in Fabricate(:user, admin: true), scope: :user
end
it 'returns http success' do
get :index
expect(response).to have_http_status(:success)
end
end
end

@ -0,0 +1,14 @@
require 'rails_helper'
RSpec.describe Admin::SettingsController, type: :controller do
describe 'GET #index' do
before do
sign_in Fabricate(:user, admin: true), scope: :user
end
it 'returns http success' do
get :index
expect(response).to have_http_status(:success)
end
end
end
Loading…
Cancel
Save