##// END OF EJS Templates
set default category_id instead of the object (#11665)...
set default category_id instead of the object (#11665) Rails 2.3 still has issues with synchronizing the association_id and association attributes of an object. That means, if you set the association with an object first and then just set the id afterwards, the object wins and the setting of the id gets lost. This is not an issue in Rails >= 3.1 anymore. Contributed by Holger Just. git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/branches/1.4-stable@10226 e93f8b46-1217-0410-a6f0-8f06a7374b81

File last commit:

r7826:f680e7f8acc1
r10043:14dcefaa97f9
Show More
groups_controller.rb
172 lines | 5.1 KiB | text/x-ruby | RubyLexer
/ app / controllers / groups_controller.rb
Jean-Philippe Lang
User groups branch merged....
r2755 # Redmine - project management software
Toshi MARUYAMA
remove trailing white-spaces from app/controllers/groups_controller.rb....
r6784 # Copyright (C) 2006-2011 Jean-Philippe Lang
Jean-Philippe Lang
User groups branch merged....
r2755 #
# 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.
Toshi MARUYAMA
remove trailing white-spaces from app/controllers/groups_controller.rb....
r6784 #
Jean-Philippe Lang
User groups branch merged....
r2755 # 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.
Toshi MARUYAMA
remove trailing white-spaces from app/controllers/groups_controller.rb....
r6784 #
Jean-Philippe Lang
User groups branch merged....
r2755 # 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
Jean-Philippe Lang
Adds an admin layout that displays the admin menu in the sidebar....
r3062 layout 'admin'
Toshi MARUYAMA
remove trailing white-spaces from app/controllers/groups_controller.rb....
r6784
Jean-Philippe Lang
User groups branch merged....
r2755 before_filter :require_admin
Toshi MARUYAMA
remove trailing white-spaces from app/controllers/groups_controller.rb....
r6784
Jean-Philippe Lang
User groups branch merged....
r2755 helper :custom_fields
Toshi MARUYAMA
remove trailing white-spaces from app/controllers/groups_controller.rb....
r6784
Jean-Philippe Lang
User groups branch merged....
r2755 # GET /groups
# GET /groups.xml
def index
@groups = Group.find(:all, :order => 'lastname')
respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @groups }
end
end
# GET /groups/1
# GET /groups/1.xml
def show
@group = Group.find(params[:id])
respond_to do |format|
format.html # show.html.erb
format.xml { render :xml => @group }
end
end
# GET /groups/new
# GET /groups/new.xml
def new
@group = Group.new
Toshi MARUYAMA
remove trailing white-spaces from app/controllers/groups_controller.rb....
r6784
Jean-Philippe Lang
User groups branch merged....
r2755 respond_to do |format|
format.html # new.html.erb
format.xml { render :xml => @group }
end
end
# GET /groups/1/edit
def edit
Jean-Philippe Lang
Eager load group projects to avoid N SQL queries....
r3621 @group = Group.find(params[:id], :include => :projects)
Jean-Philippe Lang
User groups branch merged....
r2755 end
# POST /groups
# POST /groups.xml
def create
@group = Group.new(params[:group])
respond_to do |format|
if @group.save
Jean-Philippe Lang
Adds 'Create and continue' button on the new group form....
r6184 format.html {
flash[:notice] = l(:notice_successful_create)
redirect_to(params[:continue] ? new_group_path : groups_path)
}
Jean-Philippe Lang
User groups branch merged....
r2755 format.xml { render :xml => @group, :status => :created, :location => @group }
else
format.html { render :action => "new" }
format.xml { render :xml => @group.errors, :status => :unprocessable_entity }
end
end
end
# PUT /groups/1
# PUT /groups/1.xml
def update
@group = Group.find(params[:id])
respond_to do |format|
if @group.update_attributes(params[:group])
flash[:notice] = l(:notice_successful_update)
format.html { redirect_to(groups_path) }
format.xml { head :ok }
else
format.html { render :action => "edit" }
format.xml { render :xml => @group.errors, :status => :unprocessable_entity }
end
end
end
# DELETE /groups/1
# DELETE /groups/1.xml
def destroy
@group = Group.find(params[:id])
@group.destroy
respond_to do |format|
format.html { redirect_to(groups_url) }
format.xml { head :ok }
end
end
Toshi MARUYAMA
remove trailing white-spaces from app/controllers/groups_controller.rb....
r6784
Jean-Philippe Lang
User groups branch merged....
r2755 def add_users
@group = Group.find(params[:id])
users = User.find_all_by_id(params[:user_ids])
@group.users << users if request.post?
respond_to do |format|
format.html { redirect_to :controller => 'groups', :action => 'edit', :id => @group, :tab => 'users' }
Toshi MARUYAMA
remove trailing white-spaces from app/controllers/groups_controller.rb....
r6784 format.js {
render(:update) {|page|
Jean-Philippe Lang
User groups branch merged....
r2755 page.replace_html "tab-content-users", :partial => 'groups/users'
users.each {|user| page.visual_effect(:highlight, "user-#{user.id}") }
}
}
end
end
Toshi MARUYAMA
remove trailing white-spaces from app/controllers/groups_controller.rb....
r6784
Jean-Philippe Lang
User groups branch merged....
r2755 def remove_user
@group = Group.find(params[:id])
Jean-Philippe Lang
Adds routes for group users....
r7826 @group.users.delete(User.find(params[:user_id])) if request.delete?
Jean-Philippe Lang
User groups branch merged....
r2755 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'} }
end
end
Toshi MARUYAMA
remove trailing white-spaces from app/controllers/groups_controller.rb....
r6784
Jean-Philippe Lang
User groups branch merged....
r2755 def autocomplete_for_user
@group = Group.find(params[:id])
Jean-Philippe Lang
Fixed: list of users for adding to a group may be empty if 100 first users have been added (#8029)....
r5164 @users = User.active.not_in_group(@group).like(params[:q]).all(:limit => 100)
Jean-Philippe Lang
User groups branch merged....
r2755 render :layout => false
end
Toshi MARUYAMA
remove trailing white-spaces from app/controllers/groups_controller.rb....
r6784
Jean-Philippe Lang
User groups branch merged....
r2755 def edit_membership
@group = Group.find(params[:id])
Eric Davis
Refactor: Extract method to the Member model...
r3487 @membership = Member.edit_membership(params[:membership_id], params[:membership], @group)
Jean-Philippe Lang
User groups branch merged....
r2755 @membership.save if request.post?
respond_to do |format|
Jean-Baptiste Barth
Added a warning when a new user or group membership is invalid. #3834...
r3820 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
Jean-Philippe Lang
User groups branch merged....
r2755 end
Toshi MARUYAMA
remove trailing white-spaces from app/controllers/groups_controller.rb....
r6784
Jean-Philippe Lang
User groups branch merged....
r2755 def destroy_membership
@group = Group.find(params[:id])
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
end