From 61cfd1d2733a717934a723d36f60e7bcd09fad05 Mon Sep 17 00:00:00 2001
From: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
Date: Wed, 3 Jun 2015 14:07:20 +0200
Subject: [PATCH] Wrap group removal into service

Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
---
 app/controllers/admin/groups_controller.rb |  2 +-
 app/controllers/groups_controller.rb       |  2 +-
 app/services/destroy_group_service.rb      | 11 +++++++++++
 lib/api/groups.rb                          |  2 +-
 4 files changed, 14 insertions(+), 3 deletions(-)
 create mode 100644 app/services/destroy_group_service.rb

diff --git a/app/controllers/admin/groups_controller.rb b/app/controllers/admin/groups_controller.rb
index 2dfae13ac5c0e..4d3e48f7f817a 100644
--- a/app/controllers/admin/groups_controller.rb
+++ b/app/controllers/admin/groups_controller.rb
@@ -47,7 +47,7 @@ def members_update
   end
 
   def destroy
-    @group.destroy
+    DestroyGroupService.new(@group, current_user).execute
 
     redirect_to admin_groups_path, notice: 'Group was successfully deleted.'
   end
diff --git a/app/controllers/groups_controller.rb b/app/controllers/groups_controller.rb
index 34f0b257db3b4..2e381822e421b 100644
--- a/app/controllers/groups_controller.rb
+++ b/app/controllers/groups_controller.rb
@@ -82,7 +82,7 @@ def update
   end
 
   def destroy
-    @group.destroy
+    DestroyGroupService.new(@group, current_user).execute
 
     redirect_to root_path, notice: 'Group was removed.'
   end
diff --git a/app/services/destroy_group_service.rb b/app/services/destroy_group_service.rb
new file mode 100644
index 0000000000000..9637a1480a805
--- /dev/null
+++ b/app/services/destroy_group_service.rb
@@ -0,0 +1,11 @@
+class DestroyGroupService
+  attr_accessor :group, :current_user
+
+  def initialize(group, user)
+    @group, @current_user = group, user
+  end
+
+  def execute
+    @group.destroy
+  end
+end
diff --git a/lib/api/groups.rb b/lib/api/groups.rb
index f768c750402b3..e88b6e3177534 100644
--- a/lib/api/groups.rb
+++ b/lib/api/groups.rb
@@ -62,7 +62,7 @@ class Groups < Grape::API
       delete ":id" do
         group = find_group(params[:id])
         authorize! :admin_group, group
-        group.destroy
+        DestroyGroupService.new(group, current_user).execute
       end
 
       # Transfer a project to the Group namespace
-- 
GitLab