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