Skip to content
Snippets Groups Projects
Commit 925183ed authored by Robert Speicher's avatar Robert Speicher
Browse files

Add an AdminController base class for Admin controllers

Handles stuff that's shared across admin controllers.
parent 83f24de3
No related branches found
No related tags found
1 merge request!1477Routing specs and cleanup
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)
Loading
Loading
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
Loading
Loading
@@ -15,7 +11,7 @@ class Admin::HooksController < ApplicationController
redirect_to admin_hooks_path, notice: 'Hook was successfully created.'
else
@hooks = SystemHook.all
render :index
render :index
end
end
 
Loading
Loading
class Admin::LogsController < ApplicationController
layout "admin"
before_filter :authenticate_user!
before_filter :authenticate_admin!
class Admin::LogsController < AdminController
end
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
Loading
Loading
@@ -43,7 +40,7 @@ class Admin::ProjectsController < ApplicationController
def update
owner_id = params[:project].delete(:owner_id)
 
if owner_id
if owner_id
@admin_project.owner = User.find(owner_id)
end
 
Loading
Loading
@@ -60,7 +57,7 @@ class Admin::ProjectsController < ApplicationController
redirect_to admin_projects_url, notice: 'Project was successfully deleted.'
end
 
private
private
 
def admin_project
@admin_project = Project.find_by_code(params[:id])
Loading
Loading
class Admin::ResqueController < ApplicationController
layout 'admin'
class Admin::ResqueController < AdminController
def show
end
end
\ No newline at end of file
end
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
Loading
Loading
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])
Loading
Loading
@@ -24,7 +20,7 @@ class Admin::UsersController < ApplicationController
@admin_user = User.find(params[:id])
 
UsersProject.user_bulk_import(
@admin_user,
@admin_user,
params[:project_ids],
params[:project_access]
)
Loading
Loading
@@ -41,22 +37,22 @@ class Admin::UsersController < ApplicationController
@admin_user = User.find(params[:id])
end
 
def block
def block
@admin_user = User.find(params[:id])
 
if @admin_user.block
redirect_to :back, alert: "Successfully blocked"
else
else
redirect_to :back, alert: "Error occured. User was not blocked"
end
end
 
def unblock
def unblock
@admin_user = User.find(params[:id])
 
if @admin_user.update_attribute(:blocked, false)
redirect_to :back, alert: "Successfully unblocked"
else
else
redirect_to :back, alert: "Error occured. User was not unblocked"
end
end
Loading
Loading
# 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
Loading
Loading
@@ -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
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment