| 
									
										
										
										
											2009-09-12 08:36:46 +00:00
										 |  |  | # Redmine - project management software | 
					
						
							| 
									
										
										
										
											2013-01-12 09:29:31 +00:00
										 |  |  | # Copyright (C) 2006-2013  Jean-Philippe Lang | 
					
						
							| 
									
										
										
										
											2009-09-12 08:36:46 +00:00
										 |  |  | # | 
					
						
							|  |  |  | # This program is free software; you can redistribute it and/or | 
					
						
							|  |  |  | # modify it under the terms of the GNU General Public License | 
					
						
							|  |  |  | # as published by the Free Software Foundation; either version 2 | 
					
						
							|  |  |  | # of the License, or (at your option) any later version. | 
					
						
							| 
									
										
										
										
											2011-08-31 12:19:39 +00:00
										 |  |  | # | 
					
						
							| 
									
										
										
										
											2009-09-12 08:36:46 +00:00
										 |  |  | # This program is distributed in the hope that it will be useful, | 
					
						
							|  |  |  | # but WITHOUT ANY WARRANTY; without even the implied warranty of | 
					
						
							|  |  |  | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
					
						
							|  |  |  | # GNU General Public License for more details. | 
					
						
							| 
									
										
										
										
											2011-08-31 12:19:39 +00:00
										 |  |  | # | 
					
						
							| 
									
										
										
										
											2009-09-12 08:36:46 +00:00
										 |  |  | # You should have received a copy of the GNU General Public License | 
					
						
							|  |  |  | # along with this program; if not, write to the Free Software | 
					
						
							|  |  |  | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class GroupsController < ApplicationController | 
					
						
							| 
									
										
										
										
											2009-12-17 18:21:02 +00:00
										 |  |  |   layout 'admin' | 
					
						
							| 
									
										
										
										
											2011-08-31 12:19:39 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-09-12 08:36:46 +00:00
										 |  |  |   before_filter :require_admin | 
					
						
							| 
									
										
										
										
											2012-06-03 10:40:32 +00:00
										 |  |  |   before_filter :find_group, :except => [:index, :new, :create] | 
					
						
							|  |  |  |   accept_api_auth :index, :show, :create, :update, :destroy, :add_users, :remove_user | 
					
						
							| 
									
										
										
										
											2011-08-31 12:19:39 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-09-12 08:36:46 +00:00
										 |  |  |   helper :custom_fields | 
					
						
							| 
									
										
										
										
											2011-08-31 12:19:39 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-09-12 08:36:46 +00:00
										 |  |  |   def index | 
					
						
							| 
									
										
										
										
											2012-07-08 07:40:31 +00:00
										 |  |  |     @groups = Group.sorted.all | 
					
						
							| 
									
										
										
										
											2009-09-12 08:36:46 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     respond_to do |format| | 
					
						
							| 
									
										
										
										
											2012-06-01 19:07:22 +00:00
										 |  |  |       format.html | 
					
						
							| 
									
										
										
										
											2012-06-03 10:40:32 +00:00
										 |  |  |       format.api | 
					
						
							| 
									
										
										
										
											2009-09-12 08:36:46 +00:00
										 |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def show | 
					
						
							|  |  |  |     respond_to do |format| | 
					
						
							| 
									
										
										
										
											2012-06-01 19:07:22 +00:00
										 |  |  |       format.html | 
					
						
							| 
									
										
										
										
											2012-06-03 10:40:32 +00:00
										 |  |  |       format.api | 
					
						
							| 
									
										
										
										
											2009-09-12 08:36:46 +00:00
										 |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def new | 
					
						
							|  |  |  |     @group = Group.new | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def create | 
					
						
							| 
									
										
										
										
											2012-06-01 19:06:16 +00:00
										 |  |  |     @group = Group.new | 
					
						
							|  |  |  |     @group.safe_attributes = params[:group] | 
					
						
							| 
									
										
										
										
											2009-09-12 08:36:46 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     respond_to do |format| | 
					
						
							|  |  |  |       if @group.save | 
					
						
							| 
									
										
										
										
											2011-07-21 15:55:50 +00:00
										 |  |  |         format.html { | 
					
						
							|  |  |  |           flash[:notice] = l(:notice_successful_create) | 
					
						
							|  |  |  |           redirect_to(params[:continue] ? new_group_path : groups_path) | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2012-06-03 10:40:32 +00:00
										 |  |  |         format.api  { render :action => 'show', :status => :created, :location => group_url(@group) } | 
					
						
							| 
									
										
										
										
											2009-09-12 08:36:46 +00:00
										 |  |  |       else | 
					
						
							|  |  |  |         format.html { render :action => "new" } | 
					
						
							| 
									
										
										
										
											2012-06-03 10:40:32 +00:00
										 |  |  |         format.api  { render_validation_errors(@group) } | 
					
						
							| 
									
										
										
										
											2009-09-12 08:36:46 +00:00
										 |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-06-01 19:07:22 +00:00
										 |  |  |   def edit | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-09-12 08:36:46 +00:00
										 |  |  |   def update | 
					
						
							| 
									
										
										
										
											2012-06-01 19:06:16 +00:00
										 |  |  |     @group.safe_attributes = params[:group] | 
					
						
							| 
									
										
										
										
											2009-09-12 08:36:46 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     respond_to do |format| | 
					
						
							| 
									
										
										
										
											2012-06-01 19:06:16 +00:00
										 |  |  |       if @group.save | 
					
						
							| 
									
										
										
										
											2009-09-12 08:36:46 +00:00
										 |  |  |         flash[:notice] = l(:notice_successful_update) | 
					
						
							|  |  |  |         format.html { redirect_to(groups_path) } | 
					
						
							| 
									
										
										
										
											2012-07-14 08:13:55 +00:00
										 |  |  |         format.api  { render_api_ok } | 
					
						
							| 
									
										
										
										
											2009-09-12 08:36:46 +00:00
										 |  |  |       else | 
					
						
							|  |  |  |         format.html { render :action => "edit" } | 
					
						
							| 
									
										
										
										
											2012-06-03 10:40:32 +00:00
										 |  |  |         format.api  { render_validation_errors(@group) } | 
					
						
							| 
									
										
										
										
											2009-09-12 08:36:46 +00:00
										 |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def destroy | 
					
						
							|  |  |  |     @group.destroy | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     respond_to do |format| | 
					
						
							| 
									
										
										
										
											2012-12-11 17:51:30 +00:00
										 |  |  |       format.html { redirect_to(groups_path) } | 
					
						
							| 
									
										
										
										
											2012-07-14 08:13:55 +00:00
										 |  |  |       format.api  { render_api_ok } | 
					
						
							| 
									
										
										
										
											2009-09-12 08:36:46 +00:00
										 |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2011-08-31 12:19:39 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-09-12 08:36:46 +00:00
										 |  |  |   def add_users | 
					
						
							| 
									
										
										
										
											2012-07-19 16:57:59 +00:00
										 |  |  |     @users = User.find_all_by_id(params[:user_id] || params[:user_ids]) | 
					
						
							|  |  |  |     @group.users << @users if request.post? | 
					
						
							| 
									
										
										
										
											2009-09-12 08:36:46 +00:00
										 |  |  |     respond_to do |format| | 
					
						
							| 
									
										
										
										
											2012-12-11 17:51:30 +00:00
										 |  |  |       format.html { redirect_to edit_group_path(@group, :tab => 'users') } | 
					
						
							| 
									
										
										
										
											2012-07-19 16:57:59 +00:00
										 |  |  |       format.js | 
					
						
							| 
									
										
										
										
											2012-07-14 08:13:55 +00:00
										 |  |  |       format.api { render_api_ok } | 
					
						
							| 
									
										
										
										
											2009-09-12 08:36:46 +00:00
										 |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2011-08-31 12:19:39 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-09-12 08:36:46 +00:00
										 |  |  |   def remove_user | 
					
						
							| 
									
										
										
										
											2011-11-27 10:47:36 +00:00
										 |  |  |     @group.users.delete(User.find(params[:user_id])) if request.delete? | 
					
						
							| 
									
										
										
										
											2009-09-12 08:36:46 +00:00
										 |  |  |     respond_to do |format| | 
					
						
							| 
									
										
										
										
											2012-12-11 17:51:30 +00:00
										 |  |  |       format.html { redirect_to edit_group_path(@group, :tab => 'users') } | 
					
						
							| 
									
										
										
										
											2012-07-19 16:57:59 +00:00
										 |  |  |       format.js | 
					
						
							| 
									
										
										
										
											2012-07-14 08:13:55 +00:00
										 |  |  |       format.api { render_api_ok } | 
					
						
							| 
									
										
										
										
											2009-09-12 08:36:46 +00:00
										 |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2011-08-31 12:19:39 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-09-12 08:36:46 +00:00
										 |  |  |   def autocomplete_for_user | 
					
						
							| 
									
										
										
										
											2013-01-18 17:57:16 +00:00
										 |  |  |     respond_to do |format| | 
					
						
							|  |  |  |       format.js | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2009-09-12 08:36:46 +00:00
										 |  |  |   end | 
					
						
							| 
									
										
										
										
											2011-08-31 12:19:39 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-09-12 08:36:46 +00:00
										 |  |  |   def edit_membership | 
					
						
							| 
									
										
										
										
											2010-03-18 15:49:11 +00:00
										 |  |  |     @membership = Member.edit_membership(params[:membership_id], params[:membership], @group) | 
					
						
							| 
									
										
										
										
											2009-09-12 08:36:46 +00:00
										 |  |  |     @membership.save if request.post? | 
					
						
							|  |  |  |     respond_to do |format| | 
					
						
							| 
									
										
										
										
											2012-12-11 17:51:30 +00:00
										 |  |  |       format.html { redirect_to edit_group_path(@group, :tab => 'memberships') } | 
					
						
							| 
									
										
										
										
											2012-07-19 16:57:59 +00:00
										 |  |  |       format.js | 
					
						
							| 
									
										
										
										
											2010-08-10 22:37:00 +00:00
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2009-09-12 08:36:46 +00:00
										 |  |  |   end | 
					
						
							| 
									
										
										
										
											2011-08-31 12:19:39 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-09-12 08:36:46 +00:00
										 |  |  |   def destroy_membership | 
					
						
							|  |  |  |     Member.find(params[:membership_id]).destroy if request.post? | 
					
						
							|  |  |  |     respond_to do |format| | 
					
						
							| 
									
										
										
										
											2012-12-11 17:51:30 +00:00
										 |  |  |       format.html { redirect_to edit_group_path(@group, :tab => 'memberships') } | 
					
						
							| 
									
										
										
										
											2012-07-19 16:57:59 +00:00
										 |  |  |       format.js | 
					
						
							| 
									
										
										
										
											2009-09-12 08:36:46 +00:00
										 |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2012-06-01 19:41:06 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   private | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def find_group | 
					
						
							|  |  |  |     @group = Group.find(params[:id]) | 
					
						
							|  |  |  |   rescue ActiveRecord::RecordNotFound | 
					
						
							|  |  |  |     render_404 | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2009-09-12 08:36:46 +00:00
										 |  |  | end |