Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Speicher <rspeicher@gmail.com>2012-09-16 15:44:54 +0400
committerRobert Speicher <rspeicher@gmail.com>2012-09-16 18:06:29 +0400
commit925183ed7a8eb392e008764483f59c319e22a59c (patch)
tree8b83b70d76864103fddb997adb149dae7cf5c796
parent83f24de3520ba1c49544b268253a0665831c2bd5 (diff)
Add an AdminController base class for Admin controllers
Handles stuff that's shared across admin controllers.
-rw-r--r--app/controllers/admin/dashboard_controller.rb6
-rw-r--r--app/controllers/admin/hooks_controller.rb8
-rw-r--r--app/controllers/admin/logs_controller.rb6
-rw-r--r--app/controllers/admin/projects_controller.rb9
-rw-r--r--app/controllers/admin/resque_controller.rb5
-rw-r--r--app/controllers/admin/team_members_controller.rb6
-rw-r--r--app/controllers/admin/users_controller.rb16
-rw-r--r--app/controllers/admin_controller.rb11
-rw-r--r--app/controllers/application_controller.rb4
9 files changed, 27 insertions, 44 deletions
diff --git a/app/controllers/admin/dashboard_controller.rb b/app/controllers/admin/dashboard_controller.rb
index ad80f4d5903..5152f6fa83d 100644
--- a/app/controllers/admin/dashboard_controller.rb
+++ b/app/controllers/admin/dashboard_controller.rb
@@ -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)
diff --git a/app/controllers/admin/hooks_controller.rb b/app/controllers/admin/hooks_controller.rb
index 7f832fd5697..91a1d633590 100644
--- a/app/controllers/admin/hooks_controller.rb
+++ b/app/controllers/admin/hooks_controller.rb
@@ -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
@@ -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
diff --git a/app/controllers/admin/logs_controller.rb b/app/controllers/admin/logs_controller.rb
index c130b4b85a5..28c321a9e52 100644
--- a/app/controllers/admin/logs_controller.rb
+++ b/app/controllers/admin/logs_controller.rb
@@ -1,6 +1,2 @@
-class Admin::LogsController < ApplicationController
- layout "admin"
- before_filter :authenticate_user!
- before_filter :authenticate_admin!
+class Admin::LogsController < AdminController
end
-
diff --git a/app/controllers/admin/projects_controller.rb b/app/controllers/admin/projects_controller.rb
index 80d11f03ef0..24406525cd8 100644
--- a/app/controllers/admin/projects_controller.rb
+++ b/app/controllers/admin/projects_controller.rb
@@ -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
@@ -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
@@ -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])
diff --git a/app/controllers/admin/resque_controller.rb b/app/controllers/admin/resque_controller.rb
index dc575cc27b2..9d8e7e3051f 100644
--- a/app/controllers/admin/resque_controller.rb
+++ b/app/controllers/admin/resque_controller.rb
@@ -1,5 +1,4 @@
-class Admin::ResqueController < ApplicationController
- layout 'admin'
+class Admin::ResqueController < AdminController
def show
end
-end \ No newline at end of file
+end
diff --git a/app/controllers/admin/team_members_controller.rb b/app/controllers/admin/team_members_controller.rb
index 57803b01e60..073208057ca 100644
--- a/app/controllers/admin/team_members_controller.rb
+++ b/app/controllers/admin/team_members_controller.rb
@@ -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
diff --git a/app/controllers/admin/users_controller.rb b/app/controllers/admin/users_controller.rb
index 1e8f420b098..e2d61864076 100644
--- a/app/controllers/admin/users_controller.rb
+++ b/app/controllers/admin/users_controller.rb
@@ -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])
@@ -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]
)
@@ -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
diff --git a/app/controllers/admin_controller.rb b/app/controllers/admin_controller.rb
new file mode 100644
index 00000000000..bce9f692385
--- /dev/null
+++ b/app/controllers/admin_controller.rb
@@ -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
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index a0040298a15..5ac5c639f39 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -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