2009-09-12 12:36:46 +04:00
|
|
|
# Redmine - project management software
|
2012-05-05 16:56:53 +04:00
|
|
|
# Copyright (C) 2006-2012 Jean-Philippe Lang
|
2009-09-12 12:36:46 +04: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 16:19:39 +04:00
|
|
|
#
|
2009-09-12 12:36:46 +04: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 16:19:39 +04:00
|
|
|
#
|
2009-09-12 12:36:46 +04: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 21:21:02 +03:00
|
|
|
layout 'admin'
|
2011-08-31 16:19:39 +04:00
|
|
|
|
2009-09-12 12:36:46 +04:00
|
|
|
before_filter :require_admin
|
2012-06-03 14:40:32 +04:00
|
|
|
before_filter :find_group, :except => [:index, :new, :create]
|
|
|
|
accept_api_auth :index, :show, :create, :update, :destroy, :add_users, :remove_user
|
2011-08-31 16:19:39 +04:00
|
|
|
|
2009-09-12 12:36:46 +04:00
|
|
|
helper :custom_fields
|
2011-08-31 16:19:39 +04:00
|
|
|
|
2009-09-12 12:36:46 +04:00
|
|
|
def index
|
|
|
|
@groups = Group.find(:all, :order => 'lastname')
|
|
|
|
|
|
|
|
respond_to do |format|
|
2012-06-01 23:07:22 +04:00
|
|
|
format.html
|
2012-06-03 14:40:32 +04:00
|
|
|
format.api
|
2009-09-12 12:36:46 +04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def show
|
|
|
|
respond_to do |format|
|
2012-06-01 23:07:22 +04:00
|
|
|
format.html
|
2012-06-03 14:40:32 +04:00
|
|
|
format.api
|
2009-09-12 12:36:46 +04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def new
|
|
|
|
@group = Group.new
|
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
2012-06-01 23:06:16 +04:00
|
|
|
@group = Group.new
|
|
|
|
@group.safe_attributes = params[:group]
|
2009-09-12 12:36:46 +04:00
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
if @group.save
|
2011-07-21 19:55:50 +04:00
|
|
|
format.html {
|
|
|
|
flash[:notice] = l(:notice_successful_create)
|
|
|
|
redirect_to(params[:continue] ? new_group_path : groups_path)
|
|
|
|
}
|
2012-06-03 14:40:32 +04:00
|
|
|
format.api { render :action => 'show', :status => :created, :location => group_url(@group) }
|
2009-09-12 12:36:46 +04:00
|
|
|
else
|
|
|
|
format.html { render :action => "new" }
|
2012-06-03 14:40:32 +04:00
|
|
|
format.api { render_validation_errors(@group) }
|
2009-09-12 12:36:46 +04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-06-01 23:07:22 +04:00
|
|
|
def edit
|
|
|
|
end
|
|
|
|
|
2009-09-12 12:36:46 +04:00
|
|
|
def update
|
2012-06-01 23:06:16 +04:00
|
|
|
@group.safe_attributes = params[:group]
|
2009-09-12 12:36:46 +04:00
|
|
|
|
|
|
|
respond_to do |format|
|
2012-06-01 23:06:16 +04:00
|
|
|
if @group.save
|
2009-09-12 12:36:46 +04:00
|
|
|
flash[:notice] = l(:notice_successful_update)
|
|
|
|
format.html { redirect_to(groups_path) }
|
2012-06-03 14:40:32 +04:00
|
|
|
format.api { head :ok }
|
2009-09-12 12:36:46 +04:00
|
|
|
else
|
|
|
|
format.html { render :action => "edit" }
|
2012-06-03 14:40:32 +04:00
|
|
|
format.api { render_validation_errors(@group) }
|
2009-09-12 12:36:46 +04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
@group.destroy
|
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
format.html { redirect_to(groups_url) }
|
2012-06-03 14:40:32 +04:00
|
|
|
format.api { head :ok }
|
2009-09-12 12:36:46 +04:00
|
|
|
end
|
|
|
|
end
|
2011-08-31 16:19:39 +04:00
|
|
|
|
2009-09-12 12:36:46 +04:00
|
|
|
def add_users
|
2012-06-03 14:40:32 +04:00
|
|
|
users = User.find_all_by_id(params[:user_id] || params[:user_ids])
|
2009-09-12 12:36:46 +04:00
|
|
|
@group.users << users if request.post?
|
|
|
|
respond_to do |format|
|
|
|
|
format.html { redirect_to :controller => 'groups', :action => 'edit', :id => @group, :tab => 'users' }
|
2011-08-31 16:19:39 +04:00
|
|
|
format.js {
|
|
|
|
render(:update) {|page|
|
2009-09-12 12:36:46 +04:00
|
|
|
page.replace_html "tab-content-users", :partial => 'groups/users'
|
|
|
|
users.each {|user| page.visual_effect(:highlight, "user-#{user.id}") }
|
|
|
|
}
|
|
|
|
}
|
2012-06-03 14:40:32 +04:00
|
|
|
format.api { head :ok }
|
2009-09-12 12:36:46 +04:00
|
|
|
end
|
|
|
|
end
|
2011-08-31 16:19:39 +04:00
|
|
|
|
2009-09-12 12:36:46 +04:00
|
|
|
def remove_user
|
2011-11-27 14:47:36 +04:00
|
|
|
@group.users.delete(User.find(params[:user_id])) if request.delete?
|
2009-09-12 12:36:46 +04:00
|
|
|
respond_to do |format|
|
|
|
|
format.html { redirect_to :controller => 'groups', :action => 'edit', :id => @group, :tab => 'users' }
|
|
|
|
format.js { render(:update) {|page| page.replace_html "tab-content-users", :partial => 'groups/users'} }
|
2012-06-03 14:40:32 +04:00
|
|
|
format.api { head :ok }
|
2009-09-12 12:36:46 +04:00
|
|
|
end
|
|
|
|
end
|
2011-08-31 16:19:39 +04:00
|
|
|
|
2009-09-12 12:36:46 +04:00
|
|
|
def autocomplete_for_user
|
2011-04-01 20:47:30 +04:00
|
|
|
@users = User.active.not_in_group(@group).like(params[:q]).all(:limit => 100)
|
2009-09-12 12:36:46 +04:00
|
|
|
render :layout => false
|
|
|
|
end
|
2011-08-31 16:19:39 +04:00
|
|
|
|
2009-09-12 12:36:46 +04:00
|
|
|
def edit_membership
|
2010-03-18 18:49:11 +03:00
|
|
|
@membership = Member.edit_membership(params[:membership_id], params[:membership], @group)
|
2009-09-12 12:36:46 +04:00
|
|
|
@membership.save if request.post?
|
|
|
|
respond_to do |format|
|
2010-08-11 02:37:00 +04:00
|
|
|
if @membership.valid?
|
|
|
|
format.html { redirect_to :controller => 'groups', :action => 'edit', :id => @group, :tab => 'memberships' }
|
|
|
|
format.js {
|
|
|
|
render(:update) {|page|
|
|
|
|
page.replace_html "tab-content-memberships", :partial => 'groups/memberships'
|
|
|
|
page.visual_effect(:highlight, "member-#{@membership.id}")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
format.js {
|
|
|
|
render(:update) {|page|
|
|
|
|
page.alert(l(:notice_failed_to_save_members, :errors => @membership.errors.full_messages.join(', ')))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
2009-09-12 12:36:46 +04:00
|
|
|
end
|
2011-08-31 16:19:39 +04:00
|
|
|
|
2009-09-12 12:36:46 +04:00
|
|
|
def destroy_membership
|
|
|
|
Member.find(params[:membership_id]).destroy if request.post?
|
|
|
|
respond_to do |format|
|
|
|
|
format.html { redirect_to :controller => 'groups', :action => 'edit', :id => @group, :tab => 'memberships' }
|
|
|
|
format.js { render(:update) {|page| page.replace_html "tab-content-memberships", :partial => 'groups/memberships'} }
|
|
|
|
end
|
|
|
|
end
|
2012-06-01 23:41:06 +04:00
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def find_group
|
|
|
|
@group = Group.find(params[:id])
|
|
|
|
rescue ActiveRecord::RecordNotFound
|
|
|
|
render_404
|
|
|
|
end
|
2009-09-12 12:36:46 +04:00
|
|
|
end
|