Commit 925183ed7a8eb392e008764483f59c319e22a59c
1 parent
83f24de3
Exists in
master
and in
4 other branches
Add an AdminController base class for Admin controllers
Handles stuff that's shared across admin controllers.
Showing
9 changed files
with
27 additions
and
44 deletions
Show diff stats
app/controllers/admin/dashboard_controller.rb
1 | -class Admin::DashboardController < ApplicationController | ||
2 | - layout "admin" | ||
3 | - before_filter :authenticate_user! | ||
4 | - before_filter :authenticate_admin! | ||
5 | - | 1 | +class Admin::DashboardController < AdminController |
6 | def index | 2 | def index |
7 | @workers = Resque.workers | 3 | @workers = Resque.workers |
8 | @pending_jobs = Resque.size(:post_receive) | 4 | @pending_jobs = Resque.size(:post_receive) |
app/controllers/admin/hooks_controller.rb
1 | -class Admin::HooksController < ApplicationController | ||
2 | - layout "admin" | ||
3 | - before_filter :authenticate_user! | ||
4 | - before_filter :authenticate_admin! | ||
5 | - | 1 | +class Admin::HooksController < AdminController |
6 | def index | 2 | def index |
7 | @hooks = SystemHook.all | 3 | @hooks = SystemHook.all |
8 | @hook = SystemHook.new | 4 | @hook = SystemHook.new |
@@ -15,7 +11,7 @@ class Admin::HooksController < ApplicationController | @@ -15,7 +11,7 @@ class Admin::HooksController < ApplicationController | ||
15 | redirect_to admin_hooks_path, notice: 'Hook was successfully created.' | 11 | redirect_to admin_hooks_path, notice: 'Hook was successfully created.' |
16 | else | 12 | else |
17 | @hooks = SystemHook.all | 13 | @hooks = SystemHook.all |
18 | - render :index | 14 | + render :index |
19 | end | 15 | end |
20 | end | 16 | end |
21 | 17 |
app/controllers/admin/logs_controller.rb
app/controllers/admin/projects_controller.rb
1 | -class Admin::ProjectsController < ApplicationController | ||
2 | - layout "admin" | ||
3 | - before_filter :authenticate_user! | ||
4 | - before_filter :authenticate_admin! | 1 | +class Admin::ProjectsController < AdminController |
5 | before_filter :admin_project, only: [:edit, :show, :update, :destroy, :team_update] | 2 | before_filter :admin_project, only: [:edit, :show, :update, :destroy, :team_update] |
6 | 3 | ||
7 | def index | 4 | def index |
@@ -43,7 +40,7 @@ class Admin::ProjectsController < ApplicationController | @@ -43,7 +40,7 @@ class Admin::ProjectsController < ApplicationController | ||
43 | def update | 40 | def update |
44 | owner_id = params[:project].delete(:owner_id) | 41 | owner_id = params[:project].delete(:owner_id) |
45 | 42 | ||
46 | - if owner_id | 43 | + if owner_id |
47 | @admin_project.owner = User.find(owner_id) | 44 | @admin_project.owner = User.find(owner_id) |
48 | end | 45 | end |
49 | 46 | ||
@@ -60,7 +57,7 @@ class Admin::ProjectsController < ApplicationController | @@ -60,7 +57,7 @@ class Admin::ProjectsController < ApplicationController | ||
60 | redirect_to admin_projects_url, notice: 'Project was successfully deleted.' | 57 | redirect_to admin_projects_url, notice: 'Project was successfully deleted.' |
61 | end | 58 | end |
62 | 59 | ||
63 | - private | 60 | + private |
64 | 61 | ||
65 | def admin_project | 62 | def admin_project |
66 | @admin_project = Project.find_by_code(params[:id]) | 63 | @admin_project = Project.find_by_code(params[:id]) |
app/controllers/admin/resque_controller.rb
app/controllers/admin/team_members_controller.rb
1 | -class Admin::TeamMembersController < ApplicationController | ||
2 | - layout "admin" | ||
3 | - before_filter :authenticate_user! | ||
4 | - before_filter :authenticate_admin! | ||
5 | - | 1 | +class Admin::TeamMembersController < AdminController |
6 | def edit | 2 | def edit |
7 | @admin_team_member = UsersProject.find(params[:id]) | 3 | @admin_team_member = UsersProject.find(params[:id]) |
8 | end | 4 | end |
app/controllers/admin/users_controller.rb
1 | -class Admin::UsersController < ApplicationController | ||
2 | - layout "admin" | ||
3 | - before_filter :authenticate_user! | ||
4 | - before_filter :authenticate_admin! | ||
5 | - | 1 | +class Admin::UsersController < AdminController |
6 | def index | 2 | def index |
7 | @admin_users = User.scoped | 3 | @admin_users = User.scoped |
8 | @admin_users = @admin_users.filter(params[:filter]) | 4 | @admin_users = @admin_users.filter(params[:filter]) |
@@ -24,7 +20,7 @@ class Admin::UsersController < ApplicationController | @@ -24,7 +20,7 @@ class Admin::UsersController < ApplicationController | ||
24 | @admin_user = User.find(params[:id]) | 20 | @admin_user = User.find(params[:id]) |
25 | 21 | ||
26 | UsersProject.user_bulk_import( | 22 | UsersProject.user_bulk_import( |
27 | - @admin_user, | 23 | + @admin_user, |
28 | params[:project_ids], | 24 | params[:project_ids], |
29 | params[:project_access] | 25 | params[:project_access] |
30 | ) | 26 | ) |
@@ -41,22 +37,22 @@ class Admin::UsersController < ApplicationController | @@ -41,22 +37,22 @@ class Admin::UsersController < ApplicationController | ||
41 | @admin_user = User.find(params[:id]) | 37 | @admin_user = User.find(params[:id]) |
42 | end | 38 | end |
43 | 39 | ||
44 | - def block | 40 | + def block |
45 | @admin_user = User.find(params[:id]) | 41 | @admin_user = User.find(params[:id]) |
46 | 42 | ||
47 | if @admin_user.block | 43 | if @admin_user.block |
48 | redirect_to :back, alert: "Successfully blocked" | 44 | redirect_to :back, alert: "Successfully blocked" |
49 | - else | 45 | + else |
50 | redirect_to :back, alert: "Error occured. User was not blocked" | 46 | redirect_to :back, alert: "Error occured. User was not blocked" |
51 | end | 47 | end |
52 | end | 48 | end |
53 | 49 | ||
54 | - def unblock | 50 | + def unblock |
55 | @admin_user = User.find(params[:id]) | 51 | @admin_user = User.find(params[:id]) |
56 | 52 | ||
57 | if @admin_user.update_attribute(:blocked, false) | 53 | if @admin_user.update_attribute(:blocked, false) |
58 | redirect_to :back, alert: "Successfully unblocked" | 54 | redirect_to :back, alert: "Successfully unblocked" |
59 | - else | 55 | + else |
60 | redirect_to :back, alert: "Error occured. User was not unblocked" | 56 | redirect_to :back, alert: "Error occured. User was not unblocked" |
61 | end | 57 | end |
62 | end | 58 | end |
@@ -0,0 +1,11 @@ | @@ -0,0 +1,11 @@ | ||
1 | +# Provides a base class for Admin controllers to subclass | ||
2 | +# | ||
3 | +# Automatically sets the layout and ensures an administrator is logged in | ||
4 | +class AdminController < ApplicationController | ||
5 | + layout 'admin' | ||
6 | + before_filter :authenticate_admin! | ||
7 | + | ||
8 | + def authenticate_admin! | ||
9 | + return render_404 unless current_user.is_admin? | ||
10 | + end | ||
11 | +end |
app/controllers/application_controller.rb
@@ -84,10 +84,6 @@ class ApplicationController < ActionController::Base | @@ -84,10 +84,6 @@ class ApplicationController < ActionController::Base | ||
84 | abilities << Ability | 84 | abilities << Ability |
85 | end | 85 | end |
86 | 86 | ||
87 | - def authenticate_admin! | ||
88 | - return render_404 unless current_user.is_admin? | ||
89 | - end | ||
90 | - | ||
91 | def authorize_project!(action) | 87 | def authorize_project!(action) |
92 | return access_denied! unless can?(current_user, action, project) | 88 | return access_denied! unless can?(current_user, action, project) |
93 | end | 89 | end |