annotate .svn/pristine/b4/b4b121a602e6db678b41699ec2d4ceada140049b.svn-base @ 1298:4f746d8966dd redmine_2.3_integration

Merge from redmine-2.3 branch to create new branch redmine-2.3-integration
author Chris Cannam
date Fri, 14 Jun 2013 09:28:30 +0100
parents 622f24f53b42
children
rev   line source
Chris@1295 1 # Redmine - project management software
Chris@1295 2 # Copyright (C) 2006-2013 Jean-Philippe Lang
Chris@1295 3 #
Chris@1295 4 # This program is free software; you can redistribute it and/or
Chris@1295 5 # modify it under the terms of the GNU General Public License
Chris@1295 6 # as published by the Free Software Foundation; either version 2
Chris@1295 7 # of the License, or (at your option) any later version.
Chris@1295 8 #
Chris@1295 9 # This program is distributed in the hope that it will be useful,
Chris@1295 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@1295 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@1295 12 # GNU General Public License for more details.
Chris@1295 13 #
Chris@1295 14 # You should have received a copy of the GNU General Public License
Chris@1295 15 # along with this program; if not, write to the Free Software
Chris@1295 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@1295 17
Chris@1295 18 class GroupsController < ApplicationController
Chris@1295 19 layout 'admin'
Chris@1295 20
Chris@1295 21 before_filter :require_admin
Chris@1295 22 before_filter :find_group, :except => [:index, :new, :create]
Chris@1295 23 accept_api_auth :index, :show, :create, :update, :destroy, :add_users, :remove_user
Chris@1295 24
Chris@1295 25 helper :custom_fields
Chris@1295 26
Chris@1295 27 def index
Chris@1295 28 @groups = Group.sorted.all
Chris@1295 29
Chris@1295 30 respond_to do |format|
Chris@1295 31 format.html
Chris@1295 32 format.api
Chris@1295 33 end
Chris@1295 34 end
Chris@1295 35
Chris@1295 36 def show
Chris@1295 37 respond_to do |format|
Chris@1295 38 format.html
Chris@1295 39 format.api
Chris@1295 40 end
Chris@1295 41 end
Chris@1295 42
Chris@1295 43 def new
Chris@1295 44 @group = Group.new
Chris@1295 45 end
Chris@1295 46
Chris@1295 47 def create
Chris@1295 48 @group = Group.new
Chris@1295 49 @group.safe_attributes = params[:group]
Chris@1295 50
Chris@1295 51 respond_to do |format|
Chris@1295 52 if @group.save
Chris@1295 53 format.html {
Chris@1295 54 flash[:notice] = l(:notice_successful_create)
Chris@1295 55 redirect_to(params[:continue] ? new_group_path : groups_path)
Chris@1295 56 }
Chris@1295 57 format.api { render :action => 'show', :status => :created, :location => group_url(@group) }
Chris@1295 58 else
Chris@1295 59 format.html { render :action => "new" }
Chris@1295 60 format.api { render_validation_errors(@group) }
Chris@1295 61 end
Chris@1295 62 end
Chris@1295 63 end
Chris@1295 64
Chris@1295 65 def edit
Chris@1295 66 end
Chris@1295 67
Chris@1295 68 def update
Chris@1295 69 @group.safe_attributes = params[:group]
Chris@1295 70
Chris@1295 71 respond_to do |format|
Chris@1295 72 if @group.save
Chris@1295 73 flash[:notice] = l(:notice_successful_update)
Chris@1295 74 format.html { redirect_to(groups_path) }
Chris@1295 75 format.api { render_api_ok }
Chris@1295 76 else
Chris@1295 77 format.html { render :action => "edit" }
Chris@1295 78 format.api { render_validation_errors(@group) }
Chris@1295 79 end
Chris@1295 80 end
Chris@1295 81 end
Chris@1295 82
Chris@1295 83 def destroy
Chris@1295 84 @group.destroy
Chris@1295 85
Chris@1295 86 respond_to do |format|
Chris@1295 87 format.html { redirect_to(groups_path) }
Chris@1295 88 format.api { render_api_ok }
Chris@1295 89 end
Chris@1295 90 end
Chris@1295 91
Chris@1295 92 def add_users
Chris@1295 93 @users = User.find_all_by_id(params[:user_id] || params[:user_ids])
Chris@1295 94 @group.users << @users if request.post?
Chris@1295 95 respond_to do |format|
Chris@1295 96 format.html { redirect_to edit_group_path(@group, :tab => 'users') }
Chris@1295 97 format.js
Chris@1295 98 format.api { render_api_ok }
Chris@1295 99 end
Chris@1295 100 end
Chris@1295 101
Chris@1295 102 def remove_user
Chris@1295 103 @group.users.delete(User.find(params[:user_id])) if request.delete?
Chris@1295 104 respond_to do |format|
Chris@1295 105 format.html { redirect_to edit_group_path(@group, :tab => 'users') }
Chris@1295 106 format.js
Chris@1295 107 format.api { render_api_ok }
Chris@1295 108 end
Chris@1295 109 end
Chris@1295 110
Chris@1295 111 def autocomplete_for_user
Chris@1295 112 respond_to do |format|
Chris@1295 113 format.js
Chris@1295 114 end
Chris@1295 115 end
Chris@1295 116
Chris@1295 117 def edit_membership
Chris@1295 118 @membership = Member.edit_membership(params[:membership_id], params[:membership], @group)
Chris@1295 119 @membership.save if request.post?
Chris@1295 120 respond_to do |format|
Chris@1295 121 format.html { redirect_to edit_group_path(@group, :tab => 'memberships') }
Chris@1295 122 format.js
Chris@1295 123 end
Chris@1295 124 end
Chris@1295 125
Chris@1295 126 def destroy_membership
Chris@1295 127 Member.find(params[:membership_id]).destroy if request.post?
Chris@1295 128 respond_to do |format|
Chris@1295 129 format.html { redirect_to edit_group_path(@group, :tab => 'memberships') }
Chris@1295 130 format.js
Chris@1295 131 end
Chris@1295 132 end
Chris@1295 133
Chris@1295 134 private
Chris@1295 135
Chris@1295 136 def find_group
Chris@1295 137 @group = Group.find(params[:id])
Chris@1295 138 rescue ActiveRecord::RecordNotFound
Chris@1295 139 render_404
Chris@1295 140 end
Chris@1295 141 end