##// END OF EJS Templates
Replaces find(:first/:all) calls....
Replaces find(:first/:all) calls. git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@10931 e93f8b46-1217-0410-a6f0-8f06a7374b81

File last commit:

r9861:21ee2e2cf246
r10704:ea296a109a86
Show More
groups_controller.rb
140 lines | 3.8 KiB | text/x-ruby | RubyLexer
/ app / controllers / groups_controller.rb
Jean-Philippe Lang
User groups branch merged....
r2755 # Redmine - project management software
Jean-Philippe Lang
Copyright update....
r9453 # Copyright (C) 2006-2012 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
Jean-Philippe Lang
REST Api for Groups (#8981)....
r9575 before_filter :find_group, :except => [:index, :new, :create]
accept_api_auth :index, :show, :create, :update, :destroy, :add_users, :remove_user
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 def index
Jean-Philippe Lang
Adds a scope for sorting groups....
r9764 @groups = Group.sorted.all
Jean-Philippe Lang
User groups branch merged....
r2755
respond_to do |format|
Jean-Philippe Lang
Removed auto-generated comments....
r9564 format.html
Jean-Philippe Lang
REST Api for Groups (#8981)....
r9575 format.api
Jean-Philippe Lang
User groups branch merged....
r2755 end
end
def show
respond_to do |format|
Jean-Philippe Lang
Removed auto-generated comments....
r9564 format.html
Jean-Philippe Lang
REST Api for Groups (#8981)....
r9575 format.api
Jean-Philippe Lang
User groups branch merged....
r2755 end
end
def new
@group = Group.new
end
def create
Jean-Philippe Lang
Use safe_attributes in GroupsController....
r9563 @group = Group.new
@group.safe_attributes = params[:group]
Jean-Philippe Lang
User groups branch merged....
r2755
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
REST Api for Groups (#8981)....
r9575 format.api { render :action => 'show', :status => :created, :location => group_url(@group) }
Jean-Philippe Lang
User groups branch merged....
r2755 else
format.html { render :action => "new" }
Jean-Philippe Lang
REST Api for Groups (#8981)....
r9575 format.api { render_validation_errors(@group) }
Jean-Philippe Lang
User groups branch merged....
r2755 end
end
end
Jean-Philippe Lang
Removed auto-generated comments....
r9564 def edit
end
Jean-Philippe Lang
User groups branch merged....
r2755 def update
Jean-Philippe Lang
Use safe_attributes in GroupsController....
r9563 @group.safe_attributes = params[:group]
Jean-Philippe Lang
User groups branch merged....
r2755
respond_to do |format|
Jean-Philippe Lang
Use safe_attributes in GroupsController....
r9563 if @group.save
Jean-Philippe Lang
User groups branch merged....
r2755 flash[:notice] = l(:notice_successful_update)
format.html { redirect_to(groups_path) }
Jean-Philippe Lang
Fixed that 200 API responses have a body containing one space (#11388)....
r9792 format.api { render_api_ok }
Jean-Philippe Lang
User groups branch merged....
r2755 else
format.html { render :action => "edit" }
Jean-Philippe Lang
REST Api for Groups (#8981)....
r9575 format.api { render_validation_errors(@group) }
Jean-Philippe Lang
User groups branch merged....
r2755 end
end
end
def destroy
@group.destroy
respond_to do |format|
format.html { redirect_to(groups_url) }
Jean-Philippe Lang
Fixed that 200 API responses have a body containing one space (#11388)....
r9792 format.api { render_api_ok }
Jean-Philippe Lang
User groups branch merged....
r2755 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
Jean-Philippe Lang
Removes RJS from GroupsController....
r9861 @users = User.find_all_by_id(params[:user_id] || params[:user_ids])
@group.users << @users if request.post?
Jean-Philippe Lang
User groups branch merged....
r2755 respond_to do |format|
format.html { redirect_to :controller => 'groups', :action => 'edit', :id => @group, :tab => 'users' }
Jean-Philippe Lang
Removes RJS from GroupsController....
r9861 format.js
Jean-Philippe Lang
Fixed that 200 API responses have a body containing one space (#11388)....
r9792 format.api { render_api_ok }
Jean-Philippe Lang
User groups branch merged....
r2755 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
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' }
Jean-Philippe Lang
Removes RJS from GroupsController....
r9861 format.js
Jean-Philippe Lang
Fixed that 200 API responses have a body containing one space (#11388)....
r9792 format.api { render_api_ok }
Jean-Philippe Lang
User groups branch merged....
r2755 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
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
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-Philippe Lang
Removes RJS from GroupsController....
r9861 format.html { redirect_to :controller => 'groups', :action => 'edit', :id => @group, :tab => 'memberships' }
format.js
Jean-Baptiste Barth
Added a warning when a new user or group membership is invalid. #3834...
r3820 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
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' }
Jean-Philippe Lang
Removes RJS from GroupsController....
r9861 format.js
Jean-Philippe Lang
User groups branch merged....
r2755 end
end
Jean-Philippe Lang
Adds #find_group filter....
r9565
private
def find_group
@group = Group.find(params[:id])
rescue ActiveRecord::RecordNotFound
render_404
end
Jean-Philippe Lang
User groups branch merged....
r2755 end