annotate app/controllers/groups_controller.rb @ 1327:287f201c2802 redmine-2.2-integration

Add italic
author Chris Cannam <chris.cannam@soundsoftware.ac.uk>
date Wed, 19 Jun 2013 20:56:22 +0100
parents 433d4f72a19b
children 622f24f53b42
rev   line source
Chris@0 1 # Redmine - project management software
Chris@1115 2 # Copyright (C) 2006-2012 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@909 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@909 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@909 20
Chris@0 21 before_filter :require_admin
Chris@1115 22 before_filter :find_group, :except => [:index, :new, :create]
Chris@1115 23 accept_api_auth :index, :show, :create, :update, :destroy, :add_users, :remove_user
Chris@909 24
Chris@0 25 helper :custom_fields
Chris@909 26
Chris@0 27 def index
Chris@1115 28 @groups = Group.sorted.all
Chris@0 29
Chris@0 30 respond_to do |format|
Chris@1115 31 format.html
Chris@1115 32 format.api
Chris@0 33 end
Chris@0 34 end
Chris@0 35
Chris@0 36 def show
Chris@0 37 respond_to do |format|
Chris@1115 38 format.html
Chris@1115 39 format.api
Chris@0 40 end
Chris@0 41 end
Chris@0 42
Chris@0 43 def new
Chris@0 44 @group = Group.new
Chris@0 45 end
Chris@0 46
Chris@0 47 def create
Chris@1115 48 @group = Group.new
Chris@1115 49 @group.safe_attributes = params[:group]
Chris@0 50
Chris@0 51 respond_to do |format|
Chris@0 52 if @group.save
Chris@909 53 format.html {
Chris@909 54 flash[:notice] = l(:notice_successful_create)
Chris@909 55 redirect_to(params[:continue] ? new_group_path : groups_path)
Chris@909 56 }
Chris@1115 57 format.api { render :action => 'show', :status => :created, :location => group_url(@group) }
Chris@0 58 else
Chris@0 59 format.html { render :action => "new" }
Chris@1115 60 format.api { render_validation_errors(@group) }
Chris@0 61 end
Chris@0 62 end
Chris@0 63 end
Chris@0 64
Chris@1115 65 def edit
Chris@1115 66 end
Chris@1115 67
Chris@0 68 def update
Chris@1115 69 @group.safe_attributes = params[:group]
Chris@0 70
Chris@0 71 respond_to do |format|
Chris@1115 72 if @group.save
Chris@0 73 flash[:notice] = l(:notice_successful_update)
Chris@0 74 format.html { redirect_to(groups_path) }
Chris@1115 75 format.api { render_api_ok }
Chris@0 76 else
Chris@0 77 format.html { render :action => "edit" }
Chris@1115 78 format.api { render_validation_errors(@group) }
Chris@0 79 end
Chris@0 80 end
Chris@0 81 end
Chris@0 82
Chris@0 83 def destroy
Chris@0 84 @group.destroy
Chris@0 85
Chris@0 86 respond_to do |format|
Chris@0 87 format.html { redirect_to(groups_url) }
Chris@1115 88 format.api { render_api_ok }
Chris@0 89 end
Chris@0 90 end
Chris@909 91
Chris@0 92 def add_users
Chris@1115 93 @users = User.find_all_by_id(params[:user_id] || params[:user_ids])
Chris@1115 94 @group.users << @users if request.post?
Chris@0 95 respond_to do |format|
Chris@0 96 format.html { redirect_to :controller => 'groups', :action => 'edit', :id => @group, :tab => 'users' }
Chris@1115 97 format.js
Chris@1115 98 format.api { render_api_ok }
Chris@0 99 end
Chris@0 100 end
Chris@909 101
Chris@0 102 def remove_user
Chris@909 103 @group.users.delete(User.find(params[:user_id])) if request.delete?
Chris@0 104 respond_to do |format|
Chris@0 105 format.html { redirect_to :controller => 'groups', :action => 'edit', :id => @group, :tab => 'users' }
Chris@1115 106 format.js
Chris@1115 107 format.api { render_api_ok }
Chris@0 108 end
Chris@0 109 end
Chris@909 110
Chris@0 111 def autocomplete_for_user
Chris@441 112 @users = User.active.not_in_group(@group).like(params[:q]).all(:limit => 100)
Chris@0 113 render :layout => false
Chris@0 114 end
Chris@909 115
Chris@0 116 def edit_membership
Chris@0 117 @membership = Member.edit_membership(params[:membership_id], params[:membership], @group)
Chris@0 118 @membership.save if request.post?
Chris@0 119 respond_to do |format|
Chris@1115 120 format.html { redirect_to :controller => 'groups', :action => 'edit', :id => @group, :tab => 'memberships' }
Chris@1115 121 format.js
Chris@14 122 end
Chris@0 123 end
Chris@909 124
Chris@0 125 def destroy_membership
Chris@0 126 Member.find(params[:membership_id]).destroy if request.post?
Chris@0 127 respond_to do |format|
Chris@0 128 format.html { redirect_to :controller => 'groups', :action => 'edit', :id => @group, :tab => 'memberships' }
Chris@1115 129 format.js
Chris@0 130 end
Chris@0 131 end
Chris@1115 132
Chris@1115 133 private
Chris@1115 134
Chris@1115 135 def find_group
Chris@1115 136 @group = Group.find(params[:id])
Chris@1115 137 rescue ActiveRecord::RecordNotFound
Chris@1115 138 render_404
Chris@1115 139 end
Chris@0 140 end