annotate app/controllers/.svn/text-base/groups_controller.rb.svn-base @ 8:0c83d98252d9 yuya

* Add custom repo prefix and proper auth realm, remove auth cache (seems like an unwise feature), pass DB handle around, various other bits of tidying
author Chris Cannam
date Thu, 12 Aug 2010 15:31:37 +0100
parents 513646585e45
children 1d32c0a0efbf
rev   line source
Chris@0 1 # Redmine - project management software
Chris@0 2 # Copyright (C) 2006-2009 Jean-Philippe Lang
Chris@0 3 #
Chris@0 4 # This program is free software; you can redistribute it and/or
Chris@0 5 # modify it under the terms of the GNU General Public License
Chris@0 6 # as published by the Free Software Foundation; either version 2
Chris@0 7 # of the License, or (at your option) any later version.
Chris@0 8 #
Chris@0 9 # This program is distributed in the hope that it will be useful,
Chris@0 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@0 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@0 12 # GNU General Public License for more details.
Chris@0 13 #
Chris@0 14 # You should have received a copy of the GNU General Public License
Chris@0 15 # along with this program; if not, write to the Free Software
Chris@0 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@0 17
Chris@0 18 class GroupsController < ApplicationController
Chris@0 19 layout 'admin'
Chris@0 20
Chris@0 21 before_filter :require_admin
Chris@0 22
Chris@0 23 helper :custom_fields
Chris@0 24
Chris@0 25 # GET /groups
Chris@0 26 # GET /groups.xml
Chris@0 27 def index
Chris@0 28 @groups = Group.find(:all, :order => 'lastname')
Chris@0 29
Chris@0 30 respond_to do |format|
Chris@0 31 format.html # index.html.erb
Chris@0 32 format.xml { render :xml => @groups }
Chris@0 33 end
Chris@0 34 end
Chris@0 35
Chris@0 36 # GET /groups/1
Chris@0 37 # GET /groups/1.xml
Chris@0 38 def show
Chris@0 39 @group = Group.find(params[:id])
Chris@0 40
Chris@0 41 respond_to do |format|
Chris@0 42 format.html # show.html.erb
Chris@0 43 format.xml { render :xml => @group }
Chris@0 44 end
Chris@0 45 end
Chris@0 46
Chris@0 47 # GET /groups/new
Chris@0 48 # GET /groups/new.xml
Chris@0 49 def new
Chris@0 50 @group = Group.new
Chris@0 51
Chris@0 52 respond_to do |format|
Chris@0 53 format.html # new.html.erb
Chris@0 54 format.xml { render :xml => @group }
Chris@0 55 end
Chris@0 56 end
Chris@0 57
Chris@0 58 # GET /groups/1/edit
Chris@0 59 def edit
Chris@0 60 @group = Group.find(params[:id], :include => :projects)
Chris@0 61 end
Chris@0 62
Chris@0 63 # POST /groups
Chris@0 64 # POST /groups.xml
Chris@0 65 def create
Chris@0 66 @group = Group.new(params[:group])
Chris@0 67
Chris@0 68 respond_to do |format|
Chris@0 69 if @group.save
Chris@0 70 flash[:notice] = l(:notice_successful_create)
Chris@0 71 format.html { redirect_to(groups_path) }
Chris@0 72 format.xml { render :xml => @group, :status => :created, :location => @group }
Chris@0 73 else
Chris@0 74 format.html { render :action => "new" }
Chris@0 75 format.xml { render :xml => @group.errors, :status => :unprocessable_entity }
Chris@0 76 end
Chris@0 77 end
Chris@0 78 end
Chris@0 79
Chris@0 80 # PUT /groups/1
Chris@0 81 # PUT /groups/1.xml
Chris@0 82 def update
Chris@0 83 @group = Group.find(params[:id])
Chris@0 84
Chris@0 85 respond_to do |format|
Chris@0 86 if @group.update_attributes(params[:group])
Chris@0 87 flash[:notice] = l(:notice_successful_update)
Chris@0 88 format.html { redirect_to(groups_path) }
Chris@0 89 format.xml { head :ok }
Chris@0 90 else
Chris@0 91 format.html { render :action => "edit" }
Chris@0 92 format.xml { render :xml => @group.errors, :status => :unprocessable_entity }
Chris@0 93 end
Chris@0 94 end
Chris@0 95 end
Chris@0 96
Chris@0 97 # DELETE /groups/1
Chris@0 98 # DELETE /groups/1.xml
Chris@0 99 def destroy
Chris@0 100 @group = Group.find(params[:id])
Chris@0 101 @group.destroy
Chris@0 102
Chris@0 103 respond_to do |format|
Chris@0 104 format.html { redirect_to(groups_url) }
Chris@0 105 format.xml { head :ok }
Chris@0 106 end
Chris@0 107 end
Chris@0 108
Chris@0 109 def add_users
Chris@0 110 @group = Group.find(params[:id])
Chris@0 111 users = User.find_all_by_id(params[:user_ids])
Chris@0 112 @group.users << users if request.post?
Chris@0 113 respond_to do |format|
Chris@0 114 format.html { redirect_to :controller => 'groups', :action => 'edit', :id => @group, :tab => 'users' }
Chris@0 115 format.js {
Chris@0 116 render(:update) {|page|
Chris@0 117 page.replace_html "tab-content-users", :partial => 'groups/users'
Chris@0 118 users.each {|user| page.visual_effect(:highlight, "user-#{user.id}") }
Chris@0 119 }
Chris@0 120 }
Chris@0 121 end
Chris@0 122 end
Chris@0 123
Chris@0 124 def remove_user
Chris@0 125 @group = Group.find(params[:id])
Chris@0 126 @group.users.delete(User.find(params[:user_id])) if request.post?
Chris@0 127 respond_to do |format|
Chris@0 128 format.html { redirect_to :controller => 'groups', :action => 'edit', :id => @group, :tab => 'users' }
Chris@0 129 format.js { render(:update) {|page| page.replace_html "tab-content-users", :partial => 'groups/users'} }
Chris@0 130 end
Chris@0 131 end
Chris@0 132
Chris@0 133 def autocomplete_for_user
Chris@0 134 @group = Group.find(params[:id])
Chris@0 135 @users = User.active.like(params[:q]).find(:all, :limit => 100) - @group.users
Chris@0 136 render :layout => false
Chris@0 137 end
Chris@0 138
Chris@0 139 def edit_membership
Chris@0 140 @group = Group.find(params[:id])
Chris@0 141 @membership = Member.edit_membership(params[:membership_id], params[:membership], @group)
Chris@0 142 @membership.save if request.post?
Chris@0 143 respond_to do |format|
Chris@0 144 format.html { redirect_to :controller => 'groups', :action => 'edit', :id => @group, :tab => 'memberships' }
Chris@0 145 format.js {
Chris@0 146 render(:update) {|page|
Chris@0 147 page.replace_html "tab-content-memberships", :partial => 'groups/memberships'
Chris@0 148 page.visual_effect(:highlight, "member-#{@membership.id}")
Chris@0 149 }
Chris@0 150 }
Chris@0 151 end
Chris@0 152 end
Chris@0 153
Chris@0 154 def destroy_membership
Chris@0 155 @group = Group.find(params[:id])
Chris@0 156 Member.find(params[:membership_id]).destroy if request.post?
Chris@0 157 respond_to do |format|
Chris@0 158 format.html { redirect_to :controller => 'groups', :action => 'edit', :id => @group, :tab => 'memberships' }
Chris@0 159 format.js { render(:update) {|page| page.replace_html "tab-content-memberships", :partial => 'groups/memberships'} }
Chris@0 160 end
Chris@0 161 end
Chris@0 162 end