From 98044f0f143552943b8afad0c8133f236a857adb Mon Sep 17 00:00:00 2001
From: Andrey Kumanyaev <me@zzet.org>
Date: Wed, 26 Dec 2012 20:30:11 +0400
Subject: [PATCH] Code duplication removed from controllers

---
 app/controllers/admin/groups_controller.rb | 4 +---
 app/controllers/groups_controller.rb       | 4 +---
 app/models/group.rb                        | 6 ++++++
 3 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/app/controllers/admin/groups_controller.rb b/app/controllers/admin/groups_controller.rb
index 6167c454e66..54c69138a3a 100644
--- a/app/controllers/admin/groups_controller.rb
+++ b/app/controllers/admin/groups_controller.rb
@@ -68,9 +68,7 @@ class Admin::GroupsController < AdminController
   end
 
   def project_teams_update
-    @group.projects.each do |project|
-      project.add_users_ids_to_team(params[:user_ids], params[:project_access])
-    end
+    @group.add_users_to_project_teams(params[:user_ids], params[:project_access])
     redirect_to [:admin, @group], notice: 'Users was successfully added.'
   end
 
diff --git a/app/controllers/groups_controller.rb b/app/controllers/groups_controller.rb
index 5a4595270c1..6646b10ca48 100644
--- a/app/controllers/groups_controller.rb
+++ b/app/controllers/groups_controller.rb
@@ -59,9 +59,7 @@ class GroupsController < ApplicationController
   end
 
   def team_members
-    @group.projects.each do |project|
-      project.add_users_ids_to_team(params[:user_ids], params[:project_access])
-    end
+    @group.add_users_to_project_teams(params[:user_ids], params[:project_access])
     redirect_to people_group_path(@group), notice: 'Users was successfully added.'
   end
 
diff --git a/app/models/group.rb b/app/models/group.rb
index b668f5560ab..5022fcf48f6 100644
--- a/app/models/group.rb
+++ b/app/models/group.rb
@@ -12,6 +12,12 @@
 #
 
 class Group < Namespace
+  def add_users_to_project_teams(user_ids, project_access)
+    projects.each do |project|
+      project.add_users_ids_to_team(user_ids, project_access)
+    end
+  end
+
   def users
     users = User.joins(:users_projects).where(users_projects: {project_id: project_ids})
     users = users << owner
-- 
2.30.9