From dd1cb4a5bff698c05fd51ce049c5b74d1a412a80 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Fri, 1 Jun 2012 19:41:06 +0000 Subject: [PATCH] Adds #find_group filter. git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@9748 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/controllers/groups_controller.rb | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/app/controllers/groups_controller.rb b/app/controllers/groups_controller.rb index 8eb59d035..6053bcc0e 100644 --- a/app/controllers/groups_controller.rb +++ b/app/controllers/groups_controller.rb @@ -19,6 +19,7 @@ class GroupsController < ApplicationController layout 'admin' before_filter :require_admin + before_filter :find_group, :only => [:show, :edit, :update, :destroy, :add_users, :remove_user, :autocomplete_for_user, :edit_membership, :destroy_membership] helper :custom_fields @@ -32,8 +33,6 @@ class GroupsController < ApplicationController end def show - @group = Group.find(params[:id]) - respond_to do |format| format.html format.xml { render :xml => @group } @@ -68,11 +67,9 @@ class GroupsController < ApplicationController end def edit - @group = Group.find(params[:id], :include => :projects) end def update - @group = Group.find(params[:id]) @group.safe_attributes = params[:group] respond_to do |format| @@ -88,7 +85,6 @@ class GroupsController < ApplicationController end def destroy - @group = Group.find(params[:id]) @group.destroy respond_to do |format| @@ -98,7 +94,6 @@ class GroupsController < ApplicationController end 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| @@ -113,7 +108,6 @@ class GroupsController < ApplicationController end def remove_user - @group = Group.find(params[:id]) @group.users.delete(User.find(params[:user_id])) if request.delete? respond_to do |format| format.html { redirect_to :controller => 'groups', :action => 'edit', :id => @group, :tab => 'users' } @@ -122,13 +116,11 @@ class GroupsController < ApplicationController end def autocomplete_for_user - @group = Group.find(params[:id]) @users = User.active.not_in_group(@group).like(params[:q]).all(:limit => 100) render :layout => false end def edit_membership - @group = Group.find(params[:id]) @membership = Member.edit_membership(params[:membership_id], params[:membership], @group) @membership.save if request.post? respond_to do |format| @@ -151,11 +143,18 @@ class GroupsController < ApplicationController end 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 + + private + + def find_group + @group = Group.find(params[:id]) + rescue ActiveRecord::RecordNotFound + render_404 + end end -- 2.39.5