Add an AdminController base class for Admin controllers

Handles stuff that's shared across admin controllers.
This commit is contained in:
Robert Speicher 2012-09-16 07:44:54 -04:00
parent 83f24de352
commit 925183ed7a
9 changed files with 27 additions and 44 deletions

View file

@ -1,8 +1,4 @@
class Admin::DashboardController < ApplicationController
layout "admin"
before_filter :authenticate_user!
before_filter :authenticate_admin!
class Admin::DashboardController < AdminController
def index
@workers = Resque.workers
@pending_jobs = Resque.size(:post_receive)

View file

@ -1,8 +1,4 @@
class Admin::HooksController < ApplicationController
layout "admin"
before_filter :authenticate_user!
before_filter :authenticate_admin!
class Admin::HooksController < AdminController
def index
@hooks = SystemHook.all
@hook = SystemHook.new

View file

@ -1,6 +1,2 @@
class Admin::LogsController < ApplicationController
layout "admin"
before_filter :authenticate_user!
before_filter :authenticate_admin!
class Admin::LogsController < AdminController
end

View file

@ -1,7 +1,4 @@
class Admin::ProjectsController < ApplicationController
layout "admin"
before_filter :authenticate_user!
before_filter :authenticate_admin!
class Admin::ProjectsController < AdminController
before_filter :admin_project, only: [:edit, :show, :update, :destroy, :team_update]
def index

View file

@ -1,5 +1,4 @@
class Admin::ResqueController < ApplicationController
layout 'admin'
class Admin::ResqueController < AdminController
def show
end
end

View file

@ -1,8 +1,4 @@
class Admin::TeamMembersController < ApplicationController
layout "admin"
before_filter :authenticate_user!
before_filter :authenticate_admin!
class Admin::TeamMembersController < AdminController
def edit
@admin_team_member = UsersProject.find(params[:id])
end

View file

@ -1,8 +1,4 @@
class Admin::UsersController < ApplicationController
layout "admin"
before_filter :authenticate_user!
before_filter :authenticate_admin!
class Admin::UsersController < AdminController
def index
@admin_users = User.scoped
@admin_users = @admin_users.filter(params[:filter])

View file

@ -0,0 +1,11 @@
# Provides a base class for Admin controllers to subclass
#
# Automatically sets the layout and ensures an administrator is logged in
class AdminController < ApplicationController
layout 'admin'
before_filter :authenticate_admin!
def authenticate_admin!
return render_404 unless current_user.is_admin?
end
end

View file

@ -84,10 +84,6 @@ class ApplicationController < ActionController::Base
abilities << Ability
end
def authenticate_admin!
return render_404 unless current_user.is_admin?
end
def authorize_project!(action)
return access_denied! unless can?(current_user, action, project)
end